Update v1.0.6
This commit is contained in:
4
vendor/phpspec/phpspec/.gitattributes
vendored
4
vendor/phpspec/phpspec/.gitattributes
vendored
@@ -1,4 +0,0 @@
|
||||
* text=auto
|
||||
*.bat eol=crlf
|
||||
|
||||
docs export-ignore
|
||||
6
vendor/phpspec/phpspec/.gitignore
vendored
6
vendor/phpspec/phpspec/.gitignore
vendored
@@ -1,6 +0,0 @@
|
||||
*.tgz
|
||||
*.phar
|
||||
behat.yml
|
||||
vendor
|
||||
composer.lock
|
||||
phpspec.phar
|
||||
16
vendor/phpspec/phpspec/.phpspec/class.tpl
vendored
16
vendor/phpspec/phpspec/.phpspec/class.tpl
vendored
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of PhpSpec, A php toolset to drive emergent
|
||||
* design by specification.
|
||||
*
|
||||
* (c) Marcello Duarte <marcello.duarte@gmail.com>
|
||||
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/%namespace_block%
|
||||
|
||||
final class %name%
|
||||
{
|
||||
}
|
||||
16
vendor/phpspec/phpspec/.phpspec/interface.tpl
vendored
16
vendor/phpspec/phpspec/.phpspec/interface.tpl
vendored
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of PhpSpec, A php toolset to drive emergent
|
||||
* design by specification.
|
||||
*
|
||||
* (c) Marcello Duarte <marcello.duarte@gmail.com>
|
||||
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/%namespace_block%
|
||||
|
||||
interface %name%
|
||||
{
|
||||
}
|
||||
26
vendor/phpspec/phpspec/.scrutinizer.yml
vendored
26
vendor/phpspec/phpspec/.scrutinizer.yml
vendored
@@ -1,26 +0,0 @@
|
||||
imports:
|
||||
- javascript
|
||||
- php
|
||||
|
||||
tools:
|
||||
php_code_sniffer:
|
||||
filter:
|
||||
excluded-paths: [ spec/*, integration/*, features/*, src/PhpSpec/Loader/StreamWrapper.php ]
|
||||
config:
|
||||
standard: PSR2
|
||||
|
||||
php_analyzer:
|
||||
filter:
|
||||
excluded-paths: [ spec/*, integration/* ]
|
||||
|
||||
php_sim:
|
||||
filter:
|
||||
excluded-paths: [ spec/*, integration/* ]
|
||||
|
||||
build_failure_conditions:
|
||||
- 'issues.label("coding-style").exists'
|
||||
|
||||
filter:
|
||||
excluded_paths:
|
||||
- docs/*
|
||||
- vendor/*
|
||||
40
vendor/phpspec/phpspec/.travis.yml
vendored
40
vendor/phpspec/phpspec/.travis.yml
vendored
@@ -1,40 +0,0 @@
|
||||
language: php
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.3
|
||||
- php: 5.3.3
|
||||
env: DEPENDENCIES='low'
|
||||
- php: 5.4
|
||||
- php: 5.5
|
||||
- php: 5.6
|
||||
env: DEPENDENCIES='dev'
|
||||
- php: 5.6
|
||||
- php: hhvm
|
||||
- php: 7.0
|
||||
allow_failures:
|
||||
- env: DEPENDENCIES='dev'
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- composer selfupdate
|
||||
|
||||
install:
|
||||
- export COMPOSER_ROOT_VERSION=dev-master
|
||||
- if [ "$DEPENDENCIES" == "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
|
||||
- if [ "$DEPENDENCIES" != "low" ]; then composer update; fi;
|
||||
- if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi;
|
||||
|
||||
before_script:
|
||||
- echo "<?php if (defined('HHVM_VERSION')) { echo ',@hhvm'; } else { if (PHP_VERSION_ID >= 50400) echo ',@php5.4'; if (PHP_VERSION_ID >= 70000) echo ',@php7'; }" > php_version_tags.php
|
||||
|
||||
script:
|
||||
- bin/phpspec run --format=pretty
|
||||
- ./vendor/bin/phpunit --testdox
|
||||
- ./vendor/bin/behat --format=pretty --tags '~@php-version'`php php_version_tags.php`
|
||||
248
vendor/phpspec/phpspec/CHANGES.md
vendored
248
vendor/phpspec/phpspec/CHANGES.md
vendored
@@ -1,248 +0,0 @@
|
||||
2.4.1 / 2016/01/01
|
||||
==================
|
||||
|
||||
* Correctly handle nested class definitions
|
||||
* Correctly handle anonymous functions in code generation
|
||||
* Fixed rerunning on Windows platform
|
||||
* Fixed code generation on Windows platform
|
||||
* Fixed issue with fatal errors being suppressed
|
||||
* Handle underscores correctly when using PSR-4
|
||||
* Fixed HTML formatter
|
||||
|
||||
2.4.0 / 2015/11/28
|
||||
==================
|
||||
|
||||
* Improved docblock for beConstructedThrough()
|
||||
|
||||
2.4.0-rc1 / 2015/11/20
|
||||
======================
|
||||
|
||||
* No changes from RC1
|
||||
|
||||
2.4.0-beta / 2015-11-13
|
||||
=======================
|
||||
|
||||
* Handle and present fatal errors
|
||||
|
||||
2.4.0-alpha2 / 2015-11-03
|
||||
=========================
|
||||
|
||||
* Fixed edge case with partial use statements
|
||||
|
||||
2.4.0-alpha1 / 2015-11-01
|
||||
=========================
|
||||
|
||||
* Initial support for typehinted doubles in PHP7
|
||||
* Specs can now be run by specifying a fully qualified class name
|
||||
* New shouldContain matcher for strings
|
||||
* Warning added when trying to typehint scalars or callable in spec
|
||||
* No longer truncates strings when diffing arrays in verbose mode
|
||||
* New %resource_name% placeholder for generated specs
|
||||
* Fixed case error in class name that triggered strictness warnings on some platforms
|
||||
* Fixed undefined index error in some versions of Windows
|
||||
* Clarified in composer that ext-tokenizer is required
|
||||
* Supported installation with Symfony 3.0
|
||||
* Fixed error when spec and src paths are the same
|
||||
* New event is fired when phpspec creates a file
|
||||
* Internal refactoring of Presenter objects
|
||||
|
||||
2.3.0 / 2015-09-07
|
||||
==================
|
||||
|
||||
* No changes from rc1
|
||||
|
||||
2.3.0-rc1 / 2015-08-28
|
||||
======================
|
||||
|
||||
* No changes from beta3
|
||||
|
||||
2.3.0-beta3 / 2015-08-08
|
||||
========================
|
||||
|
||||
* Fixed broken dependency in beta2
|
||||
|
||||
2.3.0-beta2 / 2015-08-08
|
||||
========================
|
||||
|
||||
* Fixed bugs when generating methods in class with unusual whitespace
|
||||
|
||||
2.3.0-beta / 2015-07-04
|
||||
========================
|
||||
|
||||
* Adds `duringInstantiation()` to more easily test constructor exceptions
|
||||
* Adds `beConstructedThrough*()` and `beConstructed*()` shortcuts for named constructors
|
||||
* Generated constructors are now placed at the start of the class
|
||||
* Offers to make constructors private after generating a named constructor
|
||||
* Shows a warning when a class is generated in a location that is not autoloadable
|
||||
* Adds `%paths.config%` placeholder to allow config paths to be relative to config file
|
||||
* Fixed invalid JUnit output in some non-EN locales
|
||||
|
||||
2.2.1 / 2015-05-30
|
||||
==================
|
||||
|
||||
* Fix false positives in `shouldHaveKeyWithValue` matcher
|
||||
* Fix fatal error in edge case when method call parameters don't match expectations
|
||||
|
||||
2.2.0 / 2015-04-18
|
||||
==================
|
||||
|
||||
* No changes from rc1
|
||||
|
||||
2.2.0-rc1 / 2015-04-13
|
||||
======================
|
||||
|
||||
* No changes from beta2
|
||||
|
||||
2.2.0-beta2 / 2015-04-03
|
||||
========================
|
||||
|
||||
* Better diffs when presenting unexpected method arguments
|
||||
* Better handling of methods delclared inside Traits when faking
|
||||
|
||||
2.2.0-beta / 2015-03-28
|
||||
=======================
|
||||
|
||||
* Offer to generate interfaces for missing typehinted collaborators
|
||||
* Support for TAP format output
|
||||
* Remove deprecated usage of Symfony DialogHelper
|
||||
* New array `shouldHaveKeyWithValue` matcher
|
||||
* Clearer error message when specs have incorrect namespace prefix
|
||||
* Fix suite rerunning for HHVM
|
||||
|
||||
Backward Compatibility
|
||||
----------------------
|
||||
|
||||
* The unused `ask` and `askAndValidate` methods on `Console\IO` have been removed
|
||||
|
||||
2.1.1 / 2015-01-09
|
||||
==================
|
||||
|
||||
* Smoother rendering for progress bar
|
||||
* Fixed progress bar for case where no examples are found
|
||||
* Tidier output alignment + block width
|
||||
* Removed deprecated calls to Yaml::parse
|
||||
* More accurate lower bounds for composer installation
|
||||
|
||||
2.1.0 / 2014-12-14
|
||||
==================
|
||||
|
||||
* No changes from RC3
|
||||
|
||||
2.1.0-RC3 / 2014-12-04
|
||||
======================
|
||||
|
||||
* Removed minor BC break introduced in RC2
|
||||
|
||||
2.1.0-RC2 / 2014-11-14
|
||||
======================
|
||||
|
||||
* Specify bootstrap file via configuration
|
||||
* Correct error codes while using --stop-on-failure
|
||||
* Better detection of empty specs
|
||||
* Fixed issue where non-spec files in spec folder caused errors
|
||||
* Better PSR-4 support
|
||||
|
||||
2.1.0-RC1 / 2014-09-14
|
||||
======================
|
||||
|
||||
* Allow objects to be instantiated via static factory methods
|
||||
* Automatic generation of return statements using '--fake'
|
||||
* Test suite is automatically rerun when classes or methods have been generated
|
||||
* Allow examples to mark themselves as skipped
|
||||
* PSR-4 support
|
||||
* PSR-0 locator now supports underscores correctly
|
||||
* Ability to specify a custom bootstrap file using '--bootstrap' (for autoloader registration etc)
|
||||
* Ability to have a personal .phpspec.yml in home folder
|
||||
* Progress bar grows from left to right and flickers less
|
||||
* Improved diffs for object comparison
|
||||
* Throw an exception when construction method is redefined
|
||||
* Non-zero exit code when dependencies are missing
|
||||
* Respect exit code of commands other than 'run'
|
||||
* Higher CLI verbosity levels are handled properly
|
||||
* Code Generation and Stop on Failure are configurable through phpspec.yml
|
||||
* Fixes for object instantiation changes in newer versions of PHP
|
||||
* PHP 5.6 support
|
||||
* Fixes for progress bar sometimes rounding up to 100% when not all specs passed
|
||||
* Support for non-standard Composer autoloader location
|
||||
* Improved hhvm support
|
||||
* Extensions can now register new command
|
||||
* Resource locator de-duplicates resources (supports custom locators in extensions)
|
||||
|
||||
2.0.1 / 2014-07-01
|
||||
==================
|
||||
|
||||
* Fixed the loading of the autoloader for projects using a custom composer vendor folder
|
||||
|
||||
2.0.0 / 2014-03-19
|
||||
==================
|
||||
|
||||
* Improve support to windows
|
||||
* Improve support to hhvm
|
||||
* Improve acceptance tests coverage with Behat
|
||||
|
||||
2.0.0-RC4 / 2014-02-21
|
||||
======================
|
||||
|
||||
* Revamped junit formatter
|
||||
* Fixed #269 Problem with exception masking and generation for not found class
|
||||
* HHVM is officially supported
|
||||
* Add psr0 validator
|
||||
* Remove Nyan from core
|
||||
* Added an exception if the specified config file does not exist
|
||||
* Fixed a problem with generating a constructor when it is first time added
|
||||
* Improved help
|
||||
* Fixed the suite runner in fast machines
|
||||
|
||||
2.0.0-RC3 / 2014-01-01
|
||||
======================
|
||||
|
||||
* Fixed the Prophecy constraint as the new release is 1.1
|
||||
* Refactored formatters to be defined as services
|
||||
|
||||
2.0.0-RC2 / 2013-12-30
|
||||
======================
|
||||
|
||||
* Fixed the invocation of methods expecting an argument passed by reference
|
||||
* Fixed the instantiation of the wrapped object in shouldThrow
|
||||
|
||||
2.0.0-RC1 / 2013-12-26
|
||||
======================
|
||||
|
||||
* Bump the Prophecy requirement to ``~1.0.5@dev``
|
||||
* Added a JUnit formatter
|
||||
* Added the ``--stop-on-failure`` option
|
||||
* Fixed the support of the ``--no-interaction`` option
|
||||
* Added more events to add extension points
|
||||
* Added the number of specs in the console output
|
||||
* Fixed the handling of Windows line endings in the StringEngine and in reading doc comments
|
||||
* Added extension points in the template loading
|
||||
* Added a constructor generator
|
||||
* Added a HTML formatter
|
||||
* Added a nyan cat formatter
|
||||
|
||||
2.0.0beta4 / 2013-05-19
|
||||
=======================
|
||||
|
||||
* Add collaborator constructor setter
|
||||
* Fix couple of bugs in Prophecy integration layer
|
||||
* New (old) dot formatter
|
||||
|
||||
2.0.0beta3 / 2013-05-01
|
||||
=======================
|
||||
|
||||
* Prevent loading of unexisting PHP files
|
||||
* Fix typos in the error messages
|
||||
|
||||
2.0.0beta2 / 2013-04-30
|
||||
=======================
|
||||
|
||||
* Bump required Prophecy version to 1.0.1
|
||||
* Support non-string values with ArrayContain matcher
|
||||
* Create `src` folder if does not exist
|
||||
* Fix stack trace and matchers failure printing
|
||||
|
||||
2.0.0beta1 / 2013-04-29
|
||||
=======================
|
||||
|
||||
* Initial release
|
||||
|
||||
25
vendor/phpspec/phpspec/CONTRIBUTING.md
vendored
25
vendor/phpspec/phpspec/CONTRIBUTING.md
vendored
@@ -1,25 +0,0 @@
|
||||
Contributing
|
||||
============
|
||||
|
||||
PhpSpec is an open source, community-driven project. If you'd like to contribute,
|
||||
feel free to do this, but remember to follow this few simple rules:
|
||||
|
||||
Branching strategy
|
||||
-------------------
|
||||
|
||||
- __Always__ base your changes on the `master` branch (all new development happens here),
|
||||
- When you create Pull Request, always select `master` branch as target, otherwise it
|
||||
will be closed (this is selected by default).
|
||||
|
||||
Coverage
|
||||
--------
|
||||
|
||||
- All classes that interact solely with the core logic should be covered by Specs
|
||||
- Any infrastructure adaptors should be covered by integration tests using PHPUnit
|
||||
- All features should be covered with .feature descriptions automated with Behat
|
||||
|
||||
Code style / Formatting
|
||||
-----------------------
|
||||
|
||||
- All new classes must carry the standard copyright notice docblock
|
||||
- All code in the `src` folder must follow the PSR-2 standard
|
||||
23
vendor/phpspec/phpspec/LICENSE
vendored
23
vendor/phpspec/phpspec/LICENSE
vendored
@@ -1,23 +0,0 @@
|
||||
Copyright (c) 2013-2014 Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
Marcello Duarte <marcello.duarte@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
13
vendor/phpspec/phpspec/Makefile
vendored
13
vendor/phpspec/phpspec/Makefile
vendored
@@ -1,13 +0,0 @@
|
||||
all:
|
||||
@echo "Only build-phar target is currently supported."
|
||||
|
||||
build-phar:
|
||||
@echo "--> Checking for composer command line tool"
|
||||
command -v composer >/dev/null && continue || { echo "composer command not found."; exit 1; }
|
||||
@echo "--> Cleaning vendor directory"
|
||||
rm -Rfv vendor
|
||||
@echo "--> Installing dependencies without dev"
|
||||
composer install --no-dev
|
||||
@echo "--> Building Phar"
|
||||
box build
|
||||
@echo "--> Success"
|
||||
29
vendor/phpspec/phpspec/README.rst
vendored
29
vendor/phpspec/phpspec/README.rst
vendored
@@ -1,29 +0,0 @@
|
||||
phpspec
|
||||
=======
|
||||
|
||||
The main website with documentation is at `http://www.phpspec.net <http://www.phpspec.net>`_.
|
||||
|
||||
.. image:: https://travis-ci.org/phpspec/phpspec.svg?branch=master
|
||||
:target: http://travis-ci.org/phpspec/phpspec
|
||||
:alt: Master Travis Build Status
|
||||
|
||||
.. image:: https://scrutinizer-ci.com/g/phpspec/phpspec/badges/quality-score.png?b=master
|
||||
:target: https://scrutinizer-ci.com/g/phpspec/phpspec/build-status/master
|
||||
:alt: Master Scrutinizer Quality Score
|
||||
|
||||
Installing Dependencies
|
||||
-----------------------
|
||||
|
||||
Dependencies are handled via `composer <http://getcomposer.org>`_::
|
||||
|
||||
wget -nc http://getcomposer.org/composer.phar
|
||||
php composer.phar install
|
||||
|
||||
Developer's mailing list
|
||||
------------------------
|
||||
|
||||
For development discussion subscribe to `phpspec-dev@googlegroups.com <mailto:phpspec-dev@googlegroups.com>`_.
|
||||
|
||||
Community
|
||||
---------
|
||||
Check out #phpspec on irc.freenode.net.
|
||||
51
vendor/phpspec/phpspec/appveyor.yml
vendored
51
vendor/phpspec/phpspec/appveyor.yml
vendored
@@ -1,51 +0,0 @@
|
||||
build: false
|
||||
shallow_clone: true
|
||||
platform: x86
|
||||
clone_folder: c:\projects\phpspec
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- PHP_DOWNLOAD_FILE: php-5.6.14-nts-Win32-VC11-x86.zip
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- PHP_DOWNLOAD_FILE: php-5.6.14-nts-Win32-VC11-x86.zip
|
||||
|
||||
skip_commits:
|
||||
message: /\[ci skip\]/
|
||||
|
||||
cache:
|
||||
- c:\php -> appveyor.yml
|
||||
- '%LOCALAPPDATA%\Composer'
|
||||
- vendor
|
||||
|
||||
init:
|
||||
- SET PATH=c:\php;%PATH%
|
||||
- SET COMPOSER_NO_INTERACTION=1
|
||||
- SET PHP=1
|
||||
- SET ANSICON=121x90 (121x90)
|
||||
- git config --global core.autocrlf input
|
||||
|
||||
install:
|
||||
- IF EXIST c:\php (SET PHP=0) ELSE (mkdir c:\php)
|
||||
- cd c:\php
|
||||
- IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/archives/%PHP_DOWNLOAD_FILE%
|
||||
- IF %PHP%==1 7z x %PHP_DOWNLOAD_FILE% -y > 7z.log
|
||||
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
|
||||
- appveyor DownloadFile https://getcomposer.org/composer.phar
|
||||
- copy php.ini-production php.ini /Y
|
||||
- echo date.timezone="UTC" >> php.ini
|
||||
- echo extension_dir=ext >> php.ini
|
||||
- echo extension=php_openssl.dll >> php.ini
|
||||
- echo extension=php_curl.dll >> php.ini
|
||||
- echo extension=php_mbstring.dll >> php.ini
|
||||
- echo extension=php_fileinfo.dll >> php.ini
|
||||
- cd c:\projects\phpspec
|
||||
- SET COMPOSER_ROOT_VERSION=dev-master
|
||||
- composer update --no-progress --ansi
|
||||
|
||||
test_script:
|
||||
- cd c:\projects\phpspec
|
||||
- php bin\phpspec run --format=pretty
|
||||
- php vendor\phpunit\phpunit\phpunit --testdox
|
||||
- php vendor\behat\behat\bin\behat --format=pretty --tags="~@php-version,@php5.4"
|
||||
15
vendor/phpspec/phpspec/behat.yml.dist
vendored
15
vendor/phpspec/phpspec/behat.yml.dist
vendored
@@ -1,15 +0,0 @@
|
||||
default:
|
||||
suites:
|
||||
application:
|
||||
contexts: [ ApplicationContext, FilesystemContext ]
|
||||
filters: { tags: "~@isolated" }
|
||||
isolated:
|
||||
contexts: [ IsolatedProcessContext, FilesystemContext ]
|
||||
filters: { tags: "@isolated" }
|
||||
smoke:
|
||||
contexts: [ IsolatedProcessContext, FilesystemContext ]
|
||||
filters: { tags: "@smoke && ~@isolated" }
|
||||
|
||||
no-smoke:
|
||||
suites:
|
||||
smoke: ~
|
||||
26
vendor/phpspec/phpspec/bin/phpspec
vendored
26
vendor/phpspec/phpspec/bin/phpspec
vendored
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
define('PHPSPEC_VERSION', '2.4.1');
|
||||
|
||||
if (is_file($autoload = getcwd() . '/vendor/autoload.php')) {
|
||||
require $autoload;
|
||||
} elseif (is_file($autoload = getcwd() . '/../../autoload.php')) {
|
||||
require $autoload;
|
||||
}
|
||||
|
||||
if (is_file($autoload = __DIR__ . '/../vendor/autoload.php')) {
|
||||
require($autoload);
|
||||
} elseif (is_file($autoload = __DIR__ . '/../../../autoload.php')) {
|
||||
require($autoload);
|
||||
} else {
|
||||
fwrite(STDERR,
|
||||
'You must set up the project dependencies, run the following commands:' . PHP_EOL .
|
||||
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
|
||||
'php composer.phar install' . PHP_EOL
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$app = new PhpSpec\Console\Application(PHPSPEC_VERSION);
|
||||
$app->run();
|
||||
19
vendor/phpspec/phpspec/box.json
vendored
19
vendor/phpspec/phpspec/box.json
vendored
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"chmod": "0755",
|
||||
"directories": [
|
||||
"src"
|
||||
],
|
||||
"files": [
|
||||
"LICENSE"
|
||||
],
|
||||
"finder": [
|
||||
{
|
||||
"name": "*.php",
|
||||
"exclude": ["Tests"],
|
||||
"in": "vendor"
|
||||
}
|
||||
],
|
||||
"main": "bin/phpspec",
|
||||
"output": "phpspec.phar",
|
||||
"stub": true
|
||||
}
|
||||
64
vendor/phpspec/phpspec/composer.json
vendored
64
vendor/phpspec/phpspec/composer.json
vendored
@@ -1,64 +0,0 @@
|
||||
{
|
||||
"name": "phpspec/phpspec",
|
||||
"description": "Specification-oriented BDD framework for PHP 5.3+",
|
||||
"keywords": ["BDD", "SpecBDD", "TDD", "spec", "specification", "tests", "testing"],
|
||||
"homepage": "http://phpspec.net/",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Konstantin Kudryashov",
|
||||
"email": "ever.zet@gmail.com",
|
||||
"homepage": "http://everzet.com"
|
||||
},
|
||||
{
|
||||
"name": "Marcello Duarte",
|
||||
"homepage": "http://marcelloduarte.net/"
|
||||
}
|
||||
],
|
||||
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"phpspec/prophecy": "~1.4",
|
||||
"phpspec/php-diff": "~1.0.0",
|
||||
"sebastian/exporter": "~1.0",
|
||||
"symfony/console": "~2.3|~3.0",
|
||||
"symfony/event-dispatcher": "~2.1|~3.0",
|
||||
"symfony/process": "^2.6|~3.0",
|
||||
"symfony/finder": "~2.1|~3.0",
|
||||
"symfony/yaml": "~2.1|~3.0",
|
||||
"doctrine/instantiator": "^1.0.1",
|
||||
"ext-tokenizer": "*"
|
||||
},
|
||||
|
||||
"require-dev": {
|
||||
"behat/behat": "^3.0.11",
|
||||
"bossa/phpspec2-expect": "~1.0",
|
||||
"symfony/filesystem": "~2.1|~3.0",
|
||||
"phpunit/phpunit": "~4.4"
|
||||
},
|
||||
|
||||
"suggest": {
|
||||
"phpspec/nyan-formatters": "~1.0 – Adds Nyan formatters"
|
||||
},
|
||||
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"PhpSpec": "src/"
|
||||
}
|
||||
},
|
||||
|
||||
"autoload-dev": {
|
||||
"psr-0": {
|
||||
"spec\\PhpSpec": "."
|
||||
}
|
||||
},
|
||||
|
||||
"bin": ["bin/phpspec"],
|
||||
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.2.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,327 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Behat\Behat\Tester\Exception\PendingException;
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Gherkin\Node\PyStringNode;
|
||||
use Behat\Gherkin\Node\TableNode;
|
||||
use Fake\Prompter;
|
||||
use Fake\ReRunner;
|
||||
use Matcher\ApplicationOutputMatcher;
|
||||
use Matcher\ValidJUnitXmlMatcher;
|
||||
use PhpSpec\Console\Application;
|
||||
use PhpSpec\Loader\StreamWrapper;
|
||||
use PhpSpec\Matcher\MatchersProviderInterface;
|
||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||
|
||||
/**
|
||||
* Defines application features from the specific context.
|
||||
*/
|
||||
class ApplicationContext implements Context, MatchersProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
private $application;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $lastExitCode;
|
||||
|
||||
/**
|
||||
* @var ApplicationTester
|
||||
*/
|
||||
private $tester;
|
||||
|
||||
/**
|
||||
* @var Prompter
|
||||
*/
|
||||
private $prompter;
|
||||
|
||||
/**
|
||||
* @var ReRunner
|
||||
*/
|
||||
private $reRunner;
|
||||
|
||||
/**
|
||||
* @beforeScenario
|
||||
*/
|
||||
public function setupApplication()
|
||||
{
|
||||
StreamWrapper::register();
|
||||
|
||||
$this->application = new Application('2.1-dev');
|
||||
$this->application->setAutoExit(false);
|
||||
|
||||
$this->tester = new ApplicationTester($this->application);
|
||||
|
||||
$this->setupReRunner();
|
||||
$this->setupPrompter();
|
||||
}
|
||||
|
||||
private function setupPrompter()
|
||||
{
|
||||
$this->prompter = new Prompter();
|
||||
|
||||
$this->application->getContainer()->set('console.prompter', $this->prompter);
|
||||
}
|
||||
|
||||
private function setupReRunner()
|
||||
{
|
||||
$this->reRunner = new ReRunner;
|
||||
$this->application->getContainer()->set('process.rerunner.platformspecific', $this->reRunner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I have started describing the :class class
|
||||
* @Given I start describing the :class class
|
||||
*/
|
||||
public function iDescribeTheClass($class)
|
||||
{
|
||||
$arguments = array(
|
||||
'command' => 'describe',
|
||||
'class' => $class
|
||||
);
|
||||
|
||||
expect($this->tester->run($arguments, array('interactive' => false)))->toBe(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec (non interactively)
|
||||
* @When I run phpspec using the :formatter format
|
||||
* @When I run phpspec with the :option option
|
||||
* @When I run phpspec with :spec specs to run
|
||||
* @When /I run phpspec with option (?P<option>.*)/
|
||||
* @When /I run phpspec (?P<interactive>interactively)$/
|
||||
* @When /I run phpspec (?P<interactive>interactively) with the (?P<option>.*) option/
|
||||
*/
|
||||
public function iRunPhpspec($formatter = null, $option = null, $interactive = null, $spec = null)
|
||||
{
|
||||
$arguments = array (
|
||||
'command' => 'run',
|
||||
'spec' => $spec
|
||||
);
|
||||
|
||||
if ($formatter) {
|
||||
$arguments['--format'] = $formatter;
|
||||
}
|
||||
|
||||
$this->addOptionToArguments($option, $arguments);
|
||||
|
||||
$this->lastExitCode = $this->tester->run($arguments, array('interactive' => (bool)$interactive));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec and answer :answer when asked if I want to generate the code
|
||||
* @When I run phpspec with the option :option and (I) answer :answer when asked if I want to generate the code
|
||||
*/
|
||||
public function iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode($answer, $option=null)
|
||||
{
|
||||
$arguments = array (
|
||||
'command' => 'run'
|
||||
);
|
||||
|
||||
$this->addOptionToArguments($option, $arguments);
|
||||
|
||||
$this->prompter->setAnswer($answer=='y');
|
||||
|
||||
$this->lastExitCode = $this->tester->run($arguments, array('interactive' => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec and answer :answer to both questions
|
||||
*/
|
||||
public function iRunPhpspecAndAnswerToBothQuestions($answer)
|
||||
{
|
||||
$arguments = array (
|
||||
'command' => 'run'
|
||||
);
|
||||
|
||||
$this->prompter->setAnswer($answer=='y');
|
||||
$this->prompter->setAnswer($answer=='y');
|
||||
|
||||
$this->lastExitCode = $this->tester->run($arguments, array('interactive' => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $option
|
||||
* @param array $arguments
|
||||
*/
|
||||
private function addOptionToArguments($option, array &$arguments)
|
||||
{
|
||||
if ($option) {
|
||||
if (preg_match('/(?P<option>[a-z-]+)=(?P<value>[a-z.]+)/', $option, $matches)) {
|
||||
$arguments[$matches['option']] = $matches['value'];
|
||||
} else {
|
||||
$arguments['--' . trim($option, '"')] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see :output
|
||||
* @Then I should see:
|
||||
*/
|
||||
public function iShouldSee($output)
|
||||
{
|
||||
expect($this->tester)->toHaveOutput((string)$output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be prompted for code generation
|
||||
*/
|
||||
public function iShouldBePromptedForCodeGeneration()
|
||||
{
|
||||
expect($this->prompter)->toHaveBeenAsked();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should not be prompted for code generation
|
||||
*/
|
||||
public function iShouldNotBePromptedForCodeGeneration()
|
||||
{
|
||||
expect($this->prompter)->toNotHaveBeenAsked();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the suite should pass
|
||||
*/
|
||||
public function theSuiteShouldPass()
|
||||
{
|
||||
expect($this->lastExitCode)->toBeLike(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the suite should not pass
|
||||
*/
|
||||
public function theSuiteShouldNotPass()
|
||||
{
|
||||
expect($this->lastExitCode)->notToBeLike(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then :number example(s) should have been skipped
|
||||
*/
|
||||
public function exampleShouldHaveBeenSkipped($number)
|
||||
{
|
||||
expect($this->tester)->toHaveOutput("($number skipped)");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then :number example(s) should have been run
|
||||
*/
|
||||
public function examplesShouldHaveBeenRun($number)
|
||||
{
|
||||
expect($this->tester)->toHaveOutput("$number examples");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the exit code should be :code
|
||||
*/
|
||||
public function theExitCodeShouldBe($code)
|
||||
{
|
||||
expect($this->lastExitCode)->toBeLike($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see valid junit output
|
||||
*/
|
||||
public function iShouldSeeValidJunitOutput()
|
||||
{
|
||||
expect($this->tester)->toHaveOutputValidJunitXml();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the tests should be rerun
|
||||
*/
|
||||
public function theTestsShouldBeRerun()
|
||||
{
|
||||
expect($this->reRunner)->toHaveBeenRerun();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the tests should not be rerun
|
||||
*/
|
||||
public function theTestsShouldNotBeRerun()
|
||||
{
|
||||
expect($this->reRunner)->toNotHaveBeenRerun();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be prompted with:
|
||||
*/
|
||||
public function iShouldBePromptedWith(PyStringNode $question)
|
||||
{
|
||||
expect($this->prompter)->toHaveBeenAsked((string)$question);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I have started describing the :class class with the :config (custom) config
|
||||
* @Given I start describing the :class class with the :config (custom) config
|
||||
*/
|
||||
public function iDescribeTheClassWithTheConfig($class, $config)
|
||||
{
|
||||
$arguments = array(
|
||||
'command' => 'describe',
|
||||
'class' => $class,
|
||||
'--config' => $config
|
||||
);
|
||||
|
||||
expect($this->tester->run($arguments, array('interactive' => false)))->toBe(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec with the :config (custom) config and answer :answer when asked if I want to generate the code
|
||||
*/
|
||||
public function iRunPhpspecWithConfigAndAnswerIfIWantToGenerateTheCode($config, $answer)
|
||||
{
|
||||
$arguments = array (
|
||||
'command' => 'run',
|
||||
'--config' => $config
|
||||
);
|
||||
|
||||
$this->prompter->setAnswer($answer=='y');
|
||||
|
||||
$this->lastExitCode = $this->tester->run($arguments, array('interactive' => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom matchers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMatchers()
|
||||
{
|
||||
return array(
|
||||
new ApplicationOutputMatcher(),
|
||||
new ValidJUnitXmlMatcher()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec with the spec :spec
|
||||
*/
|
||||
public function iRunPhpspecWithTheSpec($spec)
|
||||
{
|
||||
$arguments = array (
|
||||
'command' => 'run',
|
||||
1 => $spec
|
||||
);
|
||||
|
||||
$this->lastExitCode = $this->tester->run($arguments, array('interactive' => false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec with the spec :spec and the config :config
|
||||
*/
|
||||
public function iRunPhpspecWithTheSpecAndTheConfig($spec, $config)
|
||||
{
|
||||
$arguments = array (
|
||||
'command' => 'run',
|
||||
1 => $spec,
|
||||
'--config' => $config
|
||||
);
|
||||
|
||||
$this->lastExitCode = $this->tester->run($arguments, array('interactive' => false));
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Fake;
|
||||
|
||||
use PhpSpec\Console\Prompter as PrompterInterface;
|
||||
|
||||
class Prompter implements PrompterInterface
|
||||
{
|
||||
private $answers = array();
|
||||
private $hasBeenAsked = false;
|
||||
private $question;
|
||||
|
||||
public function setAnswer($answer)
|
||||
{
|
||||
$this->answers[] = $answer;
|
||||
}
|
||||
|
||||
public function askConfirmation($question, $default = true)
|
||||
{
|
||||
$this->hasBeenAsked = true;
|
||||
$this->question = $question;
|
||||
return (bool)array_shift($this->answers);
|
||||
}
|
||||
|
||||
public function hasBeenAsked($question = null)
|
||||
{
|
||||
if (!$question) {
|
||||
return $this->hasBeenAsked;
|
||||
}
|
||||
|
||||
return $this->hasBeenAsked
|
||||
&& preg_replace('/\s+/', ' ', trim(strip_tags($this->question))) == preg_replace('/\s+/', ' ', $question) ;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Fake;
|
||||
|
||||
use PhpSpec\Process\ReRunner as BaseReRunner;
|
||||
|
||||
class ReRunner implements BaseReRunner
|
||||
{
|
||||
private $hasBeenReRun = false;
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSupported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function reRunSuite()
|
||||
{
|
||||
$this->hasBeenReRun = true;
|
||||
}
|
||||
|
||||
public function hasBeenReRun()
|
||||
{
|
||||
return $this->hasBeenReRun;
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Behat\Behat\Tester\Exception\PendingException;
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Gherkin\Node\PyStringNode;
|
||||
use Behat\Gherkin\Node\TableNode;
|
||||
use Matcher\FileExistsMatcher;
|
||||
use Matcher\FileHasContentsMatcher;
|
||||
use PhpSpec\Matcher\MatchersProviderInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
/**
|
||||
* Defines application features from the specific context.
|
||||
*/
|
||||
class FilesystemContext implements Context, MatchersProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $workingDirectory;
|
||||
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
private $filesystem;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->filesystem = new Filesystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* @beforeScenario
|
||||
*/
|
||||
public function prepWorkingDirectory()
|
||||
{
|
||||
$this->workingDirectory = tempnam(sys_get_temp_dir(), 'phpspec-behat');
|
||||
$this->filesystem->remove($this->workingDirectory);
|
||||
$this->filesystem->mkdir($this->workingDirectory);
|
||||
chdir($this->workingDirectory);
|
||||
|
||||
$this->filesystem->mkdir($this->workingDirectory . '/vendor');
|
||||
$this->filesystem->copy(
|
||||
__DIR__ . '/autoloader/autoload.php',
|
||||
$this->workingDirectory . '/vendor/autoload.php'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @afterScenario
|
||||
*/
|
||||
public function removeWorkingDirectory()
|
||||
{
|
||||
$this->filesystem->remove($this->workingDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given the bootstrap file :file contains:
|
||||
*/
|
||||
public function theFileContains($file, PyStringNode $contents)
|
||||
{
|
||||
$this->filesystem->dumpFile($file, (string)$contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given the class file :file contains:
|
||||
* @Given the trait file :file contains:
|
||||
*/
|
||||
public function theClassOrTraitFileContains($file, PyStringNode $contents)
|
||||
{
|
||||
$this->theFileContains($file, $contents);
|
||||
require_once($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given the spec file :file contains:
|
||||
*/
|
||||
public function theSpecFileContains($file, PyStringNode $contents)
|
||||
{
|
||||
$this->theFileContains($file, $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given the config file contains:
|
||||
*/
|
||||
public function theConfigFileContains(PyStringNode $contents)
|
||||
{
|
||||
$this->theFileContains('phpspec.yml', $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given there is no file :file
|
||||
*/
|
||||
public function thereIsNoFile($file)
|
||||
{
|
||||
expect($file)->toNotExist();
|
||||
expect(file_exists($file))->toBe(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the class in :file should contain:
|
||||
* @Then a new class/spec should be generated in the :file:
|
||||
*/
|
||||
public function theFileShouldContain($file, PyStringNode $contents)
|
||||
{
|
||||
expect($file)->toExist();
|
||||
expect($file)->toHaveContents($contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given the config file located in :folder contains:
|
||||
*/
|
||||
public function theConfigFileInFolderContains($folder, PyStringNode $contents)
|
||||
{
|
||||
$this->theFileContains($folder.DIRECTORY_SEPARATOR.'phpspec.yml', $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given I have not configured an autoloader
|
||||
*/
|
||||
public function iHaveNotConfiguredAnAutoloader()
|
||||
{
|
||||
$this->filesystem->remove($this->workingDirectory . '/vendor/autoload.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMatchers()
|
||||
{
|
||||
return array(
|
||||
new FileExistsMatcher(),
|
||||
new FileHasContentsMatcher()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Behat\Context\SnippetAcceptingContext;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Behat\Gherkin\Node\PyStringNode;
|
||||
|
||||
/**
|
||||
* Defines application features from the specific context.
|
||||
*/
|
||||
class IsolatedProcessContext implements Context, SnippetAcceptingContext
|
||||
{
|
||||
/**
|
||||
* @var Process
|
||||
*/
|
||||
private $process;
|
||||
|
||||
private $lastOutput;
|
||||
|
||||
/**
|
||||
* @Given I have started describing the :class class
|
||||
*/
|
||||
public function iHaveStartedDescribingTheClass($class)
|
||||
{
|
||||
$command = sprintf('%s %s %s', $this->buildPhpSpecCmd(), 'describe', escapeshellarg($class));
|
||||
|
||||
$process = new Process($command);
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec and answer :answer when asked if I want to generate the code
|
||||
*/
|
||||
public function iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode($answer)
|
||||
{
|
||||
$command = sprintf('%s %s', $this->buildPhpSpecCmd(), 'run');
|
||||
$env = array(
|
||||
'SHELL_INTERACTIVE' => true,
|
||||
'HOME' => $_SERVER['HOME'],
|
||||
'PATH' => $_SERVER['PATH']
|
||||
);
|
||||
|
||||
$this->process = $process = new Process($command);
|
||||
|
||||
$process->setEnv($env);
|
||||
$process->setInput($answer);
|
||||
$process->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function buildPhpSpecCmd()
|
||||
{
|
||||
return escapeshellcmd(__DIR__ . '/../../bin/phpspec');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the tests should be rerun
|
||||
*/
|
||||
public function theTestsShouldBeRerun()
|
||||
{
|
||||
expect(substr_count($this->process->getOutput(), 'specs'))->toBe(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see an error about the missing autoloader
|
||||
*/
|
||||
public function iShouldSeeAnErrorAboutTheMissingAutoloader()
|
||||
{
|
||||
expect($this->process->getErrorOutput())->toMatch('/autoload/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec
|
||||
*/
|
||||
public function iRunPhpspec()
|
||||
{
|
||||
$process = new Process(
|
||||
$this->buildPhpSpecCmd() . ' run'
|
||||
);
|
||||
$process->run();
|
||||
$this->lastOutput = $process->getOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec with the :formatter formatter
|
||||
*/
|
||||
public function iRunPhpspecWithThe($formatter)
|
||||
{
|
||||
$process = new Process(
|
||||
$this->buildPhpSpecCmd() . " --format=$formatter run"
|
||||
);
|
||||
$process->run();
|
||||
$this->lastOutput = $process->getErrorOutput();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I run phpspec on HHVM with the :formatter formatter
|
||||
*/
|
||||
public function iRunPhpspecOnHhvmWithThe($formatter)
|
||||
{
|
||||
$process = new Process(
|
||||
$this->buildPhpSpecCmd() . " --format=$formatter run"
|
||||
);
|
||||
$process->run();
|
||||
$this->lastOutput = $process->getOutput();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see :message
|
||||
*/
|
||||
public function iShouldSee($message)
|
||||
{
|
||||
expect(strpos($this->lastOutput, $message))->toNotBe(false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Matcher;
|
||||
|
||||
use PhpSpec\Exception\Example\FailureException;
|
||||
use PhpSpec\Matcher\MatcherInterface;
|
||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||
|
||||
class ApplicationOutputMatcher implements MatcherInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Checks if matcher supports provided subject and matcher name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function supports($name, $subject, array $arguments)
|
||||
{
|
||||
return ($name == 'haveOutput' && $subject instanceof ApplicationTester);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates positive match.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function positiveMatch($name, $subject, array $arguments)
|
||||
{
|
||||
$expected = $this->normalize($arguments[0]);
|
||||
$actual = $this->normalize($subject->getDisplay());
|
||||
if (strpos($actual, $expected) === false) {
|
||||
throw new FailureException(sprintf(
|
||||
"Application output did not contain expected '%s'. Actual output:\n'%s'" ,
|
||||
$expected,
|
||||
$subject->getDisplay()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private function normalize($string)
|
||||
{
|
||||
$string = preg_replace('/\([0-9]+ms\)/', '', $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates negative match.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function negativeMatch($name, $subject, array $arguments)
|
||||
{
|
||||
throw new FailureException('Negative application output matcher not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns matcher priority.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return 51;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Matcher;
|
||||
|
||||
use PhpSpec\Exception\Example\FailureException;
|
||||
use PhpSpec\Matcher\MatcherInterface;
|
||||
|
||||
class FileExistsMatcher implements MatcherInterface
|
||||
{
|
||||
/**
|
||||
* Checks if matcher supports provided subject and matcher name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function supports($name, $subject, array $arguments)
|
||||
{
|
||||
return ('exist' == $name && is_string($subject));
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates positive match.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function positiveMatch($name, $subject, array $arguments)
|
||||
{
|
||||
if (!file_exists($subject)) {
|
||||
throw new FailureException(sprintf(
|
||||
"File did not exist at path '%s'",
|
||||
$subject
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates negative match.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function negativeMatch($name, $subject, array $arguments)
|
||||
{
|
||||
if (file_exists($subject)) {
|
||||
throw new FailureException(sprintf(
|
||||
"File unexpectedly exists at path '%s'",
|
||||
$subject
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns matcher priority.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Matcher;
|
||||
|
||||
use PhpSpec\Exception\Example\FailureException;
|
||||
use PhpSpec\Matcher\MatcherInterface;
|
||||
|
||||
class FileHasContentsMatcher implements MatcherInterface
|
||||
{
|
||||
/**
|
||||
* Checks if matcher supports provided subject and matcher name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function supports($name, $subject, array $arguments)
|
||||
{
|
||||
return ('haveContents' == $name && is_string($subject));
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates positive match.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function positiveMatch($name, $subject, array $arguments)
|
||||
{
|
||||
$path = $subject;
|
||||
$expectedContents = $arguments[0];
|
||||
if ($expectedContents != file_get_contents($path)) {
|
||||
throw new FailureException(sprintf(
|
||||
"File at '%s' did not contain expected contents.\nExpected: '%s'\nActual: '%s'",
|
||||
$path,
|
||||
$expectedContents,
|
||||
file_get_contents($path)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates negative match.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function negativeMatch($name, $subject, array $arguments)
|
||||
{
|
||||
throw new FailureException('Negative file contents matcher not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns matcher priority.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return 51;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Matcher;
|
||||
|
||||
use PhpSpec\Exception\Example\FailureException;
|
||||
use PhpSpec\Matcher\MatcherInterface;
|
||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||
|
||||
const JUNIT_XSD_PATH = '/src/PhpSpec/Resources/schema/junit.xsd';
|
||||
|
||||
class ValidJUnitXmlMatcher implements MatcherInterface
|
||||
{
|
||||
/**
|
||||
* Checks if matcher supports provided subject and matcher name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function supports($name, $subject, array $arguments)
|
||||
{
|
||||
return ($name == 'haveOutputValidJunitXml' && $subject instanceof ApplicationTester);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates positive match.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function positiveMatch($name, $subject, array $arguments)
|
||||
{
|
||||
$dom = new \DOMDocument();
|
||||
$dom->loadXML($subject->getDisplay());
|
||||
if (!$dom->schemaValidate(__DIR__ . '/../../..' . JUNIT_XSD_PATH)) {
|
||||
throw new FailureException(sprintf(
|
||||
"Output was not valid JUnit XML"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates negative match.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function negativeMatch($name, $subject, array $arguments)
|
||||
{
|
||||
throw new FailureException('Negative JUnit matcher not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns matcher priority.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return 51;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
spl_autoload_register(function ($classname) {
|
||||
$classname = __DIR__ . '/../src/' . str_replace("\\", "/", trim($classname, "\\")) . ".php";
|
||||
if (file_exists($classname)) { include $classname; }
|
||||
});
|
||||
@@ -1,140 +0,0 @@
|
||||
Feature: Developer generates a class
|
||||
As a Developer
|
||||
I want to automate creating classes
|
||||
In order to avoid repetitive tasks and interruptions in development flow
|
||||
|
||||
@smoke @php-version @php5.4
|
||||
Scenario: Generating a class
|
||||
Given I have started describing the "CodeGeneration/ClassExample1/Markdown" class
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then a new class should be generated in the "src/CodeGeneration/ClassExample1/Markdown.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ClassExample1;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
@issue269
|
||||
Scenario: Generating a class with psr4 prefix
|
||||
Given the config file contains:
|
||||
"""
|
||||
suites:
|
||||
behat_suite:
|
||||
namespace: Behat\Tests\MyNamespace
|
||||
psr4_prefix: Behat\Tests
|
||||
"""
|
||||
And I have started describing the "Behat/Tests/MyNamespace/Markdown" class
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then a new class should be generated in the "src/MyNamespace/Markdown.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Behat\Tests\MyNamespace;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
@issue127
|
||||
Scenario: Generating a class with PSR0 must convert classname underscores to directory separator
|
||||
Given I have started describing the "CodeGeneration/ClassExample1/Text_Markdown" class
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then a new class should be generated in the "src/CodeGeneration/ClassExample1/Text/Markdown.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ClassExample1;
|
||||
|
||||
class Text_Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
@issue127
|
||||
Scenario: Generating a class with PSR0 must not convert namespace underscores to directory separator
|
||||
Given I have started describing the "CodeGeneration/Class_Example2/Text_Markdown" class
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then a new class should be generated in the "src/CodeGeneration/Class_Example2/Text/Markdown.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\Class_Example2;
|
||||
|
||||
class Text_Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a class when expectations on collaborator are defined
|
||||
Given the spec file "spec/CodeGeneration/MethodExample2/ForgotPasswordSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\MethodExample2;
|
||||
|
||||
use CodeGeneration\MethodExample2\UserRepository;
|
||||
use CodeGeneration\MethodExample2\User;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ForgotPasswordSpec extends ObjectBehavior
|
||||
{
|
||||
function it_changes_password_for_user(UserRepository $repository, User $user)
|
||||
{
|
||||
$repository->findOneByEmail('leszek.prabucki@gmail.com')->willReturn($user);
|
||||
$user->changePassword('123')->shouldBeCalled();
|
||||
|
||||
$this->changePassword('leszek.prabucki@gmail.com', '123');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/CodeGeneration/MethodExample2/User.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\MethodExample2;
|
||||
|
||||
interface User
|
||||
{
|
||||
public function changePassword($newPassword);
|
||||
}
|
||||
"""
|
||||
And the class file "src/CodeGeneration/MethodExample2/UserRepository.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\MethodExample2;
|
||||
|
||||
interface UserRepository
|
||||
{
|
||||
public function findOneByEmail($email);
|
||||
}
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/MethodExample2/ForgotPassword.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\MethodExample2;
|
||||
|
||||
class ForgotPassword
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
@isolated @php-version @php5.4
|
||||
Scenario: Generating a class outside of autoloadable paths gives a warning
|
||||
Given I have started describing the "CodeGeneration/ClassExample2/Markdown" class
|
||||
But I have not configured an autoloader
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then I should see an error about the missing autoloader
|
||||
@@ -1,121 +0,0 @@
|
||||
Feature: Developer generates a collaborator
|
||||
As a Developer
|
||||
I want to automate creating collaborators
|
||||
In order to avoid disrupting my workflow
|
||||
|
||||
Scenario: Being prompted but not generating a collaborator
|
||||
Given the spec file "spec/CodeGeneration/CollaboratorExample1/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\CollaboratorExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use CodeGeneration\CollaboratorExample1\Parser;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_interacts_with_a_collaborator(Parser $parser)
|
||||
{
|
||||
$parser->willReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorExample1/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorExample1;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "n" when asked if I want to generate the code
|
||||
Then I should be prompted with:
|
||||
"""
|
||||
Would you like me to generate an interface
|
||||
`CodeGeneration\CollaboratorExample1\Parser` for you?
|
||||
[Y/n]
|
||||
"""
|
||||
|
||||
Scenario: Asking for interface to be generated
|
||||
Given the spec file "spec/CodeGeneration/CollaboratorExample2/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\CollaboratorExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use CodeGeneration\CollaboratorExample2\Parser;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_interacts_with_a_collaborator(Parser $parser)
|
||||
{
|
||||
$parser->willReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorExample2/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorExample2;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/CollaboratorExample2/Parser.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorExample2;
|
||||
|
||||
interface Parser
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Not being prompted when typehint is in spec namespace
|
||||
Given the spec file "spec/CodeGeneration/CollaboratorExample3/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\CollaboratorExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_interacts_with_a_collaborator(Parser $parser)
|
||||
{
|
||||
$parser->willReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorExample3/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorExample3;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "n" when asked if I want to generate the code
|
||||
Then I should not be prompted for code generation
|
||||
|
||||
@@ -1,266 +0,0 @@
|
||||
Feature: Developer generates a collaborator's method
|
||||
As a Developer
|
||||
I want to automate creating collaborators' missing methods
|
||||
In order to avoid disrupting my workflow
|
||||
|
||||
Scenario: Being prompted to generate a collaborator method based on typehints
|
||||
Given the spec file "spec/CodeGeneration/CollaboratorMethodExample1/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\CollaboratorMethodExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use CodeGeneration\CollaboratorMethodExample1\Parser;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_interacts_with_a_collaborator(Parser $parser)
|
||||
{
|
||||
$parser->getSuccess()->willReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample1/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample1;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample1/Parser.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample1;
|
||||
|
||||
interface Parser
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "n" when asked if I want to generate the code
|
||||
Then I should be prompted with:
|
||||
"""
|
||||
Would you like me to generate a method signature
|
||||
`CodeGeneration\CollaboratorMethodExample1\Parser::getSuccess()` for you?
|
||||
[Y/n]
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Being prompted to generate a collaborator method based on docblocks
|
||||
Given the spec file "spec/CodeGeneration/CollaboratorMethodExample2/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\CollaboratorMethodExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
/**
|
||||
* @param \CodeGeneration\CollaboratorMethodExample2\Parser $parser
|
||||
*/
|
||||
function it_interacts_with_a_collaborator($parser)
|
||||
{
|
||||
$parser->getSuccess()->willReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample2/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample2;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample2/Parser.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample2;
|
||||
|
||||
interface Parser
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "n" when asked if I want to generate the code
|
||||
Then I should be prompted with:
|
||||
"""
|
||||
Would you like me to generate a method signature
|
||||
`CodeGeneration\CollaboratorMethodExample2\Parser::getSuccess()` for you?
|
||||
[Y/n]
|
||||
"""
|
||||
|
||||
Scenario: Asking for the method signature to be generated
|
||||
Given the spec file "spec/CodeGeneration/CollaboratorMethodExample3/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\CollaboratorMethodExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use CodeGeneration\CollaboratorMethodExample3\Parser;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_interacts_with_a_collaborator(Parser $parser)
|
||||
{
|
||||
$parser->getSuccess()->willReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample3/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample3;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample3/Parser.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample3;
|
||||
|
||||
interface Parser
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/CollaboratorMethodExample3/Parser.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample3;
|
||||
|
||||
interface Parser
|
||||
{
|
||||
|
||||
public function getSuccess();
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Asking for the method signature to be generated with multiple parameters
|
||||
Given the spec file "spec/CodeGeneration/CollaboratorMethodExample4/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\CollaboratorMethodExample4;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use CodeGeneration\CollaboratorMethodExample4\Parser;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_interacts_with_a_collaborator(Parser $parser)
|
||||
{
|
||||
$parser->parse('xyz', 2)->willReturn(1);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample4/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample4;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample4/Parser.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample4;
|
||||
|
||||
interface Parser
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/CollaboratorMethodExample4/Parser.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample4;
|
||||
|
||||
interface Parser
|
||||
{
|
||||
|
||||
public function parse($argument1, $argument2);
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Not being prompted when collaborator is a class
|
||||
Given the spec file "spec/CodeGeneration/CollaboratorMethodExample5/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\CollaboratorMethodExample5;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use CodeGeneration\CollaboratorMethodExample5\Parser;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_interacts_with_a_collaborator(Parser $parser)
|
||||
{
|
||||
$parser->getSuccess()->willReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample5/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample5;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/CollaboratorMethodExample5/Parser.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\CollaboratorMethodExample5;
|
||||
|
||||
class Parser
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "n" when asked if I want to generate the code
|
||||
Then I should not be prompted for code generation
|
||||
@@ -1,373 +0,0 @@
|
||||
Feature: Developer generates a method
|
||||
As a Developer
|
||||
I want to automate creating methods
|
||||
In order to avoid repetitive tasks and interruptions in development flow
|
||||
|
||||
Scenario: Generating a method
|
||||
Given the spec file "spec/CodeGeneration/MethodExample1/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\MethodExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/MethodExample1/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\MethodExample1;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/MethodExample1/Markdown.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\MethodExample1;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
// TODO: write logic here
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
Scenario: Generating a method in a class with psr4 prefix
|
||||
Given the spec file "spec/MyNamespace/PrefixSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Behat\Tests\MyNamespace;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class PrefixSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the config file contains:
|
||||
"""
|
||||
suites:
|
||||
behat_suite:
|
||||
namespace: Behat\Tests\MyNamespace
|
||||
psr4_prefix: Behat\Tests
|
||||
"""
|
||||
And the class file "src/MyNamespace/Prefix.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Behat\Tests\MyNamespace;
|
||||
|
||||
class Prefix
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/MyNamespace/Prefix.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Behat\Tests\MyNamespace;
|
||||
|
||||
class Prefix
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
// TODO: write logic here
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
Scenario: Generating a constructor in a file with existing methods places the constructor first
|
||||
Given the spec file "spec/MyNamespace/ConstructorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\MyNamespace;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ConstructorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_do_something_with_a_constructor()
|
||||
{
|
||||
$this->beConstructedWith('anArgument');
|
||||
$this->foo()->shouldReturn('bar');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/MyNamespace/Constructor.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class Constructor
|
||||
{
|
||||
public function foo()
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/MyNamespace/Constructor.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class Constructor
|
||||
{
|
||||
public function __construct($argument1)
|
||||
{
|
||||
// TODO: write logic here
|
||||
}
|
||||
|
||||
public function foo()
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a constructor in a file with no methods
|
||||
Given the spec file "spec/MyNamespace/ConstructorFirstSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\MyNamespace;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ConstructorFirstSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_do_something_with_a_constructor()
|
||||
{
|
||||
$this->beConstructedWith('anArgument');
|
||||
$this->foo()->shouldReturn('bar');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/MyNamespace/ConstructorFirst.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class ConstructorFirst
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/MyNamespace/ConstructorFirst.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class ConstructorFirst
|
||||
{
|
||||
public function __construct($argument1)
|
||||
{
|
||||
// TODO: write logic here
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a method in a class with existing methods and new lines
|
||||
Given the spec file "spec/MyNamespace/ExistingMethodSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\MyNamespace;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ExistingMethodSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_do_something()
|
||||
{
|
||||
$this->foo()->shouldReturn('bar');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/MyNamespace/ExistingMethod.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class ExistingMethod
|
||||
{
|
||||
public function existing()
|
||||
{
|
||||
return 'something';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/MyNamespace/ExistingMethod.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class ExistingMethod
|
||||
{
|
||||
public function existing()
|
||||
{
|
||||
return 'something';
|
||||
}
|
||||
|
||||
public function foo()
|
||||
{
|
||||
// TODO: write logic here
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a method in a class with existing methods containing anonymous functions
|
||||
Given the spec file "spec/MyNamespace/ExistingMethodAnonymousFunctionSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\MyNamespace;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ExistingMethodAnonymousFunctionSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_do_something()
|
||||
{
|
||||
$this->foo()->shouldReturn('bar');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/MyNamespace/ExistingMethodAnonymousFunction.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class ExistingMethodAnonymousFunction
|
||||
{
|
||||
public function existing()
|
||||
{
|
||||
return function () {
|
||||
return 'something';
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/MyNamespace/ExistingMethodAnonymousFunction.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class ExistingMethodAnonymousFunction
|
||||
{
|
||||
public function existing()
|
||||
{
|
||||
return function () {
|
||||
return 'something';
|
||||
};
|
||||
}
|
||||
|
||||
public function foo()
|
||||
{
|
||||
// TODO: write logic here
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a constructor in a file with no methods
|
||||
Given the spec file "spec/MyNamespace/CommentMethodSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\MyNamespace;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CommentMethodSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_do_something()
|
||||
{
|
||||
$this->foo()->shouldReturn('bar');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/MyNamespace/CommentMethod.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class CommentMethod
|
||||
{
|
||||
// this is a comment
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/MyNamespace/CommentMethod.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
class CommentMethod
|
||||
{
|
||||
// this is a comment
|
||||
|
||||
public function foo()
|
||||
{
|
||||
// TODO: write logic here
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -1,444 +0,0 @@
|
||||
Feature: Developer generates a named constructor
|
||||
As a Developer
|
||||
I want to automate creating named constructor
|
||||
In order to avoid repetitive tasks and interruptions in development flow
|
||||
|
||||
Scenario: Generating a named constructor in an empty class
|
||||
Given the spec file "spec/CodeGeneration/NamedConstructor/UserSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\NamedConstructor;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class UserSpec extends ObjectBehavior
|
||||
{
|
||||
function it_registers_a_user()
|
||||
{
|
||||
$this->beConstructedThrough('register', array('firstname', 'lastname'));
|
||||
$this->getFirstname()->shouldBe('firstname');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/NamedConstructor/User.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor;
|
||||
|
||||
class User
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/NamedConstructor/User.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor;
|
||||
|
||||
class User
|
||||
{
|
||||
public static function register($argument1, $argument2)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
// TODO: write logic here
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a named constructor with more arguments than an existing constructor accepts
|
||||
Given the spec file "spec/CodeGeneration/NamedConstructor/TooManyArguments/UserSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\NamedConstructor\TooManyArguments;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class UserSpec extends ObjectBehavior
|
||||
{
|
||||
function it_registers_a_user()
|
||||
{
|
||||
$this->beConstructedThrough('register', array('firstname', 'lastname'));
|
||||
$this->getFirstname()->shouldBe('firstname');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/NamedConstructor/TooManyArguments/User.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor\TooManyArguments;
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/NamedConstructor/TooManyArguments/User.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor\TooManyArguments;
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function register($argument1, $argument2)
|
||||
{
|
||||
throw new \BadMethodCallException("Mismatch between the number of arguments of the factory method and constructor");
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a named constructor with less arguments than an existing constructor accepts
|
||||
Given the spec file "spec/CodeGeneration/NamedConstructor/TooFewArguments/UserSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\NamedConstructor\TooFewArguments;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class UserSpec extends ObjectBehavior
|
||||
{
|
||||
function it_registers_a_user()
|
||||
{
|
||||
$this->beConstructedThrough('register', array('firstname', 'lastname'));
|
||||
$this->getFirstname()->shouldBe('firstname');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/NamedConstructor/TooFewArguments/User.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor\TooFewArguments;
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct($argument1, $argument2, $argument3)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/NamedConstructor/TooFewArguments/User.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor\TooFewArguments;
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct($argument1, $argument2, $argument3)
|
||||
{
|
||||
}
|
||||
|
||||
public static function register($argument1, $argument2)
|
||||
{
|
||||
throw new \BadMethodCallException("Mismatch between the number of arguments of the factory method and constructor");
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a named constructor with a matching number of constructor arguments
|
||||
Given the spec file "spec/CodeGeneration/NamedConstructor/EqualArguments/UserSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\NamedConstructor\EqualArguments;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class UserSpec extends ObjectBehavior
|
||||
{
|
||||
function it_registers_a_user()
|
||||
{
|
||||
$this->beConstructedThrough('register', array('firstname', 'lastname'));
|
||||
$this->getFirstname()->shouldBe('firstname');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/NamedConstructor/EqualArguments/User.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor\EqualArguments;
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct($argument1, $argument2)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/NamedConstructor/EqualArguments/User.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor\EqualArguments;
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct($argument1, $argument2)
|
||||
{
|
||||
}
|
||||
|
||||
public static function register($argument1, $argument2)
|
||||
{
|
||||
$user = new User($argument1, $argument2);
|
||||
|
||||
// TODO: write logic here
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a named constructor with the correct number of required constructor arguments
|
||||
Given the spec file "spec/CodeGeneration/NamedConstructor/OptionalArguments/UserSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\NamedConstructor\OptionalArguments;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class UserSpec extends ObjectBehavior
|
||||
{
|
||||
function it_registers_a_user()
|
||||
{
|
||||
$this->beConstructedThrough('register', array('firstname', 'lastname'));
|
||||
$this->getFirstname()->shouldBe('firstname');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/NamedConstructor/OptionalArguments/User.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor\OptionalArguments;
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct($argument1, $argument2, $argument3 = 'optional')
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/NamedConstructor/OptionalArguments/User.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\NamedConstructor\OptionalArguments;
|
||||
|
||||
class User
|
||||
{
|
||||
public function __construct($argument1, $argument2, $argument3 = 'optional')
|
||||
{
|
||||
}
|
||||
|
||||
public static function register($argument1, $argument2)
|
||||
{
|
||||
$user = new User($argument1, $argument2);
|
||||
|
||||
// TODO: write logic here
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a named constructor using beConstructedThrough*
|
||||
Given the spec file "spec/CodeGeneration/ShortSyntax/UserSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\ShortSyntax;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class UserSpec extends ObjectBehavior
|
||||
{
|
||||
function it_registers_a_user()
|
||||
{
|
||||
$this->beConstructedThroughRegister('firstname', 'lastname');
|
||||
$this->getFirstname()->shouldBe('firstname');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/ShortSyntax/User.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ShortSyntax;
|
||||
|
||||
class User
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/ShortSyntax/User.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ShortSyntax;
|
||||
|
||||
class User
|
||||
{
|
||||
public static function register($argument1, $argument2)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
// TODO: write logic here
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a named constructor using beConstructed*
|
||||
Given the spec file "spec/CodeGeneration/ShortSyntax2/UserSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\ShortSyntax2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class UserSpec extends ObjectBehavior
|
||||
{
|
||||
function it_registers_a_user()
|
||||
{
|
||||
$this->beConstructedFromString('firstname', 'lastname');
|
||||
$this->getFirstname()->shouldBe('firstname');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/ShortSyntax2/User.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ShortSyntax2;
|
||||
|
||||
class User
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/ShortSyntax2/User.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ShortSyntax2;
|
||||
|
||||
class User
|
||||
{
|
||||
public static function fromString($argument1, $argument2)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
// TODO: write logic here
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating the private constructor
|
||||
Given the spec file "spec/CodeGeneration/PrivateConstructor/UserSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\PrivateConstructor;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class UserSpec extends ObjectBehavior
|
||||
{
|
||||
function it_registers_a_user()
|
||||
{
|
||||
$this->beConstructedThrough('register', array('firstname', 'lastname'));
|
||||
$this->getFirstname()->shouldBe('firstname');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/PrivateConstructor/User.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\PrivateConstructor;
|
||||
|
||||
class User
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" to both questions
|
||||
Then the class in "src/CodeGeneration/PrivateConstructor/User.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\PrivateConstructor;
|
||||
|
||||
class User
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function register($argument1, $argument2)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
// TODO: write logic here
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -1,324 +0,0 @@
|
||||
Feature: Developer generates a method returning a constant
|
||||
As a Developer
|
||||
I want to automate creating methods that return constants
|
||||
In order to avoid having to manually write the code
|
||||
|
||||
Scenario: Generating a scalar return type when method exists
|
||||
Given the spec file "spec/CodeGeneration/ConstantExample1/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\ConstantExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/ConstantExample1/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample1;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the option "fake" and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/ConstantExample1/Markdown.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample1;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
return '<p>Hi, there</p>';
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a scalar return type when method contains comments
|
||||
Given the spec file "spec/CodeGeneration/ConstantExample2/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\ConstantExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/ConstantExample2/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample2;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
// TODO: Add Logic here
|
||||
/*
|
||||
This code is inactive
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the option "fake" and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/ConstantExample2/Markdown.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample2;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
return '<p>Hi, there</p>';
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: No prompt when method contains code
|
||||
Given the spec file "spec/CodeGeneration/ConstantExample3/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\ConstantExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/ConstantExample3/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample3;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
$foo = 'bar';
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec interactively with the "fake" option
|
||||
Then I should not be prompted for code generation
|
||||
|
||||
Scenario: No prompt when examples contradict code
|
||||
Given the spec file "spec/CodeGeneration/ConstantExample4/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\ConstantExample4;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
|
||||
function it_converts_more_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hello, there')->shouldReturn('<p>Hello, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/ConstantExample4/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample4;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec interactively with the "fake" option
|
||||
Then I should not be prompted for code generation
|
||||
|
||||
Scenario: No prompt when CLI option is not used
|
||||
Given the spec file "spec/CodeGeneration/ConstantExample5/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\ConstantExample5;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/ConstantExample5/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample5;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec interactively
|
||||
Then I should not be prompted for code generation
|
||||
|
||||
Scenario: Prompted when CLI option is not used but config flag is set
|
||||
Given the spec file "spec/CodeGeneration/ConstantExample6/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\ConstantExample6;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/ConstantExample6/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample6;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the config file contains:
|
||||
"""
|
||||
fake: true
|
||||
"""
|
||||
When I run phpspec interactively
|
||||
Then I should be prompted for code generation
|
||||
|
||||
@php-version @php5.4
|
||||
Scenario: Generating a scalar return type when method is in trait
|
||||
Given the spec file "spec/CodeGeneration/ConstantExample7/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\ConstantExample7;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the trait file "src/CodeGeneration/ConstantExample7/MarkdownTrait.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample7;
|
||||
|
||||
trait MarkdownTrait
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/ConstantExample7/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample7;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
use MarkdownTrait;
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the option "fake" and answer "y" when asked if I want to generate the code
|
||||
Then the class in "src/CodeGeneration/ConstantExample7/MarkdownTrait.php" should contain:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\ConstantExample7;
|
||||
|
||||
trait MarkdownTrait
|
||||
{
|
||||
public function toHtml($argument1)
|
||||
{
|
||||
return '<p>Hi, there</p>';
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -1,161 +0,0 @@
|
||||
Feature: Developer generates a spec
|
||||
As a Developer
|
||||
I want to automate creating specs
|
||||
In order to avoid repetitive tasks and interruptions in development flow
|
||||
|
||||
Scenario: Generating a spec
|
||||
When I start describing the "CodeGeneration/SpecExample1/Markdown" class
|
||||
Then a new spec should be generated in the "spec/CodeGeneration/SpecExample1/MarkdownSpec.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\SpecExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('CodeGeneration\SpecExample1\Markdown');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
|
||||
@issue687
|
||||
Scenario: Generating a spec with the same namespace as the source
|
||||
Given the config file contains:
|
||||
"""
|
||||
suites:
|
||||
code_generator_suite:
|
||||
namespace: CodeGeneration\SpecExample2
|
||||
spec_path: spec/
|
||||
spec_prefix: ''
|
||||
|
||||
"""
|
||||
When I start describing the "CodeGeneration/SpecExample2/Markdown" class
|
||||
Then a new spec should be generated in the "spec/CodeGeneration/SpecExample2/MarkdownSpec.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\SpecExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('CodeGeneration\SpecExample2\Markdown');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
@issue687
|
||||
Scenario: Generating a spec with the same namespace as the source even with psr4 prefix on src
|
||||
Given the config file contains:
|
||||
"""
|
||||
suites:
|
||||
code_generator_suite:
|
||||
namespace: CodeGeneration\SpecExample2
|
||||
psr4_prefix: CodeGeneration
|
||||
spec_path: spec/
|
||||
spec_prefix: ''
|
||||
|
||||
"""
|
||||
When I start describing the "CodeGeneration/SpecExample2/Markdown" class
|
||||
Then a new spec should be generated in the "spec/SpecExample2/MarkdownSpec.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\SpecExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('CodeGeneration\SpecExample2\Markdown');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
@issue127
|
||||
Scenario: Generating a spec with PSR0 must convert classname underscores to directory separator
|
||||
When I start describing the "CodeGeneration/SpecExample1/Text_Markdown" class
|
||||
Then a new spec should be generated in the "spec/CodeGeneration/SpecExample1/Text/MarkdownSpec.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\SpecExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class Text_MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('CodeGeneration\SpecExample1\Text_Markdown');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
@issue127
|
||||
Scenario: Generating a spec with PSR0 must not convert namespace underscores to directory separator
|
||||
When I start describing the "CodeGeneration/Spec_Example2/Text_Markdown" class
|
||||
Then a new spec should be generated in the "spec/CodeGeneration/Spec_Example2/Text/MarkdownSpec.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\Spec_Example2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class Text_MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('CodeGeneration\Spec_Example2\Text_Markdown');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Generating a spec for a class with psr4 prefix
|
||||
Given the config file contains:
|
||||
"""
|
||||
suites:
|
||||
behat_suite:
|
||||
namespace: Behat\CodeGeneration
|
||||
psr4_prefix: Behat\CodeGeneration
|
||||
"""
|
||||
When I start describing the "Behat/CodeGeneration/Markdown" class
|
||||
Then a new spec should be generated in the "spec/MarkdownSpec.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Behat\CodeGeneration;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Behat\CodeGeneration\Markdown');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -1,62 +0,0 @@
|
||||
Feature: Developer generates a class
|
||||
As a Developer
|
||||
I want the tests to automatically rerun after code generation events
|
||||
In order to avoid repetitive tasks and interruptions in development flow
|
||||
|
||||
@smoke @php-version @php5.4
|
||||
Scenario: Rerun after class generation
|
||||
Given I have started describing the "CodeGeneration/RerunExample1/Markdown" class
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the tests should be rerun
|
||||
|
||||
Scenario: Rerun after method generation
|
||||
Given the spec file "spec/CodeGeneration/RerunExample2/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\CodeGeneration\RerunExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/CodeGeneration/RerunExample2/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace CodeGeneration\RerunExample2;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the tests should be rerun
|
||||
|
||||
Scenario: No rerun if code generation is off
|
||||
Given I have started describing the "CodeGeneration/RerunExample3/Markdown" class
|
||||
When I run phpspec non interactively
|
||||
Then the tests should not be rerun
|
||||
|
||||
Scenario: No rerun if rerun flag is passed
|
||||
Given I have started describing the "CodeGeneration/RerunExample4/Markdown" class
|
||||
When I run phpspec with the option "no-rerun" and I answer "y" when asked if I want to generate the code
|
||||
Then the tests should not be rerun
|
||||
|
||||
Scenario: No rerun if rerun flag is passed
|
||||
Given I have started describing the "CodeGeneration/RerunExample5/Markdown" class
|
||||
And the config file contains:
|
||||
"""
|
||||
rerun: false
|
||||
"""
|
||||
When I run phpspec and answer "y" when asked if I want to generate the code
|
||||
Then the tests should not be rerun
|
||||
@@ -1,102 +0,0 @@
|
||||
Feature: Config directory can be used in spec and src paths
|
||||
As a Developer
|
||||
I need a path variable representing the config directory
|
||||
So I may use the directory of the config in spec and src paths and thus be able to run tests regardless of the current working directory
|
||||
|
||||
Scenario: Using %paths.config% variable in spec_path
|
||||
Given the config file located in "Awesome" contains:
|
||||
"""
|
||||
suites:
|
||||
behat_suite:
|
||||
namespace: MilkyWay\OrionCygnusArm
|
||||
spec_path: %paths.config%
|
||||
"""
|
||||
When I start describing the "MilkyWay/OrionCygnusArm/LocalBubble" class with the "Awesome/phpspec.yml" custom config
|
||||
Then a new spec should be generated in the "Awesome/spec/MilkyWay/OrionCygnusArm/LocalBubbleSpec.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\MilkyWay\OrionCygnusArm;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class LocalBubbleSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('MilkyWay\OrionCygnusArm\LocalBubble');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Not using %paths.config% variable in spec_path
|
||||
Given the config file located in "Awesome" contains:
|
||||
"""
|
||||
suites:
|
||||
behat_suite:
|
||||
namespace: MilkyWay\OrionCygnusArm
|
||||
"""
|
||||
When I start describing the "MilkyWay/OrionCygnusArm/ButterflyCluster" class with the "Awesome/phpspec.yml" custom config
|
||||
Then a new spec should be generated in the "spec/MilkyWay/OrionCygnusArm/ButterflyClusterSpec.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\MilkyWay\OrionCygnusArm;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ButterflyClusterSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('MilkyWay\OrionCygnusArm\ButterflyCluster');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Using %paths.config% variable in src_path
|
||||
Given the config file located in "Awesome" contains:
|
||||
"""
|
||||
suites:
|
||||
behat_suite:
|
||||
namespace: MilkyWay\OrionCygnusArm
|
||||
src_path: %paths.config%/src
|
||||
"""
|
||||
And I have started describing the "MilkyWay/OrionCygnusArm/Pleiades/Alcyone" class with the "Awesome/phpspec.yml" custom config
|
||||
When I run phpspec with the "Awesome/phpspec.yml" custom config and answer "y" when asked if I want to generate the code
|
||||
Then a new class should be generated in the "Awesome/src/MilkyWay/OrionCygnusArm/Pleiades/Alcyone.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MilkyWay\OrionCygnusArm\Pleiades;
|
||||
|
||||
class Alcyone
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Scenario: Not using %paths.config% variable in src_path
|
||||
Given the config file located in "Awesome" contains:
|
||||
"""
|
||||
suites:
|
||||
behat_suite:
|
||||
namespace: MilkyWay\OrionCygnusArm
|
||||
"""
|
||||
And I have started describing the "MilkyWay/OrionCygnusArm/BehiveCluster" class with the "Awesome/phpspec.yml" custom config
|
||||
When I run phpspec with the "Awesome/phpspec.yml" custom config and answer "y" when asked if I want to generate the code
|
||||
Then a new class should be generated in the "src/MilkyWay/OrionCygnusArm/BehiveCluster.php":
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace MilkyWay\OrionCygnusArm;
|
||||
|
||||
class BehiveCluster
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
@@ -1,436 +0,0 @@
|
||||
Feature: Developer specifies object construction
|
||||
As a Developer
|
||||
I want to describe how objects are constructed
|
||||
In order to be able to test objects with non-trivial construction
|
||||
|
||||
Scenario: Class is initialised using a constructor
|
||||
Given the spec file "spec/Runner/ConstructorExample1/ClassWithConstructorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ConstructorExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithConstructorSpec extends ObjectBehavior
|
||||
{
|
||||
function let(\DateTime $date)
|
||||
{
|
||||
$this->beConstructedWith($date);
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Runner\ConstructorExample1\ClassWithConstructor');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ConstructorExample1/ClassWithConstructor.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ConstructorExample1;
|
||||
|
||||
class ClassWithConstructor
|
||||
{
|
||||
private $date;
|
||||
|
||||
public function __construct(\DateTime $date)
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: Class is initialized using a static factory method and a collaborator as argument
|
||||
Given the spec file "spec/Runner/ConstructorExample2/ClassWithStaticFactoryMethodSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ConstructorExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithStaticFactoryMethodSpec extends ObjectBehavior
|
||||
{
|
||||
function let(\DateTime $date)
|
||||
{
|
||||
$this->beConstructedThrough('getInstance', array($date));
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Runner\ConstructorExample2\ClassWithStaticFactoryMethod');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ConstructorExample2/ClassWithStaticFactoryMethod.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ConstructorExample2;
|
||||
|
||||
class ClassWithStaticFactoryMethod
|
||||
{
|
||||
private $date;
|
||||
|
||||
public static function getInstance(\DateTime $date)
|
||||
{
|
||||
return new ClassWithStaticFactoryMethod($date);
|
||||
}
|
||||
|
||||
private function __construct(\DateTime $date)
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: Default static constructor parameter is overridden in example
|
||||
Given the spec file "spec/Runner/ConstructorExample3/ClassWithConstructorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ConstructorExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithConstructorSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('foo');
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->beConstructedWith('bar');
|
||||
$this->getType()->shouldReturn('bar');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ConstructorExample3/ClassWithConstructor.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ConstructorExample3;
|
||||
|
||||
class ClassWithConstructor
|
||||
{
|
||||
private $type;
|
||||
|
||||
public function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
|
||||
Scenario: Static constructor is overridden in example
|
||||
Given the spec file "spec/Runner/ConstructorExample4/ClassWithStaticFactoryMethodSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ConstructorExample4;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithStaticFactoryMethodSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedThrough('getInstanceOfType', array('foo'));
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->beConstructedThrough('getInstanceOfType', array('bar'));
|
||||
$this->getType()->shouldReturn('bar');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ConstructorExample4/ClassWithStaticFactoryMethod.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ConstructorExample4;
|
||||
|
||||
class ClassWithStaticFactoryMethod
|
||||
{
|
||||
private $type;
|
||||
|
||||
private function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public static function getInstanceOfType($type)
|
||||
{
|
||||
return new self($type);
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: Static constructor set in example used instead factory method set in let
|
||||
Given the spec file "spec/Runner/ConstructorExample7/ClassWithStaticFactoryMethodAndConstructorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ConstructorExample7;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithStaticFactoryMethodAndConstructorSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedThrough('getInstanceOfType', array('foo'));
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->beConstructedWith('bar');
|
||||
$this->getType()->shouldReturn('bar');
|
||||
$this->wasConstructedWith()->shouldReturn('__construct');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ConstructorExample7/ClassWithStaticFactoryMethodAndConstructor.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ConstructorExample7;
|
||||
|
||||
class ClassWithStaticFactoryMethodAndConstructor
|
||||
{
|
||||
private $type;
|
||||
private $wasConstructedWith;
|
||||
|
||||
public function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->wasConstructedWith = '__construct';
|
||||
}
|
||||
|
||||
public static function getInstanceOfType($type)
|
||||
{
|
||||
$created = new self($type);
|
||||
$created->wasConstructedWith = 'getInstanceOfType';
|
||||
return $created;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function wasConstructedWith()
|
||||
{
|
||||
return $this->wasConstructedWith;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: Factory method set in example used instead of constructor set in let
|
||||
Given the spec file "spec/Runner/ConstructorExample8/ClassWithStaticFactoryMethodAndConstructorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ConstructorExample8;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithStaticFactoryMethodAndConstructorSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('bar');
|
||||
$this->beConstructedThrough('getInstanceOfType', array('foo'));
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->beConstructedThrough('getInstanceOfType', array('foo'));
|
||||
$this->getType()->shouldReturn('foo');
|
||||
$this->wasConstructedWith()->shouldReturn('getInstanceOfType');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ConstructorExample8/ClassWithStaticFactoryMethodAndConstructor.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ConstructorExample8;
|
||||
|
||||
class ClassWithStaticFactoryMethodAndConstructor
|
||||
{
|
||||
private $type;
|
||||
private $wasConstructedWith;
|
||||
|
||||
public function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->wasConstructedWith = '__construct';
|
||||
}
|
||||
|
||||
public static function getInstanceOfType($type)
|
||||
{
|
||||
$created = new self($type);
|
||||
$created->wasConstructedWith = 'getInstanceOfType';
|
||||
return $created;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function wasConstructedWith()
|
||||
{
|
||||
return $this->wasConstructedWith;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: Developer cannot redefine constructor parameters if object is already instantiated
|
||||
Given the spec file "spec/Runner/ConstructorExample9/ClassConstructorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ConstructorExample9;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassConstructorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_behaves_differently_depending_on_type()
|
||||
{
|
||||
$this->beConstructedWith('foo');
|
||||
$this->getType()->shouldReturn('foo');
|
||||
|
||||
$this->beConstructedWith('bar');
|
||||
$this->getType()->shouldReturn('bar');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ConstructorExample9/ClassConstructor.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ConstructorExample9;
|
||||
|
||||
class ClassConstructor
|
||||
{
|
||||
public function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then I should see "you can not change object construction method when it is already instantiated"
|
||||
|
||||
Scenario: Developer cannot redefine factory method if object is already instantiated
|
||||
Given the spec file "spec/Runner/ConstructorExample10/ClassWithFactoryMethodSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ConstructorExample10;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithFactoryMethodSpec extends ObjectBehavior
|
||||
{
|
||||
function it_behaves_differently_depending_on_type()
|
||||
{
|
||||
$this->beConstructedThrough('createFoo');
|
||||
$this->getType()->shouldReturn('foo');
|
||||
|
||||
$this->beConstructedWith('createBar');
|
||||
$this->getType()->shouldReturn('bar');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ConstructorExample10/ClassWithFactoryMethod.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ConstructorExample10;
|
||||
|
||||
class ClassWithFactoryMethod
|
||||
{
|
||||
private function __construct($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public static function createFoo()
|
||||
{
|
||||
return new self('foo');
|
||||
}
|
||||
|
||||
public static function createBar()
|
||||
{
|
||||
return new self('bar');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then I should see "you can not change object construction method when it is already instantiated"
|
||||
@@ -1,126 +0,0 @@
|
||||
Feature: Developer is notified of which scenario caused a fatal error
|
||||
As a Developer
|
||||
I want to know in which scenario or example my script was running
|
||||
So that I can better trace where my changes caused a fatal error
|
||||
|
||||
@isolated
|
||||
Scenario: Spec attempts to call an undeclared function and outputs to stdout
|
||||
Given the spec file "spec/Message/Fatal/FatalSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Message\Fatal;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class FatalSpec extends ObjectBehavior
|
||||
{
|
||||
function it_fatals_when_calling_an_undeclared_function()
|
||||
{
|
||||
anything();
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Message/Fatal/Fatal.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Message\Fatal;
|
||||
|
||||
class Fatal
|
||||
{
|
||||
public function __construct($param)
|
||||
{
|
||||
if ($param == 'throw') {
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then I should see "Fatal error happened while executing the following"
|
||||
And I should see "it fatals when calling an undeclared function"
|
||||
|
||||
@isolated @php-version @php5.4 @php7
|
||||
Scenario: Fatal error writer message not shown, when formatter does not support it, outputs to stderr.
|
||||
Given the spec file "spec/Message/Fatal/Fatal2Spec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Message\Fatal;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class Fatal2Spec extends ObjectBehavior
|
||||
{
|
||||
function it_fatals_when_calling_an_undeclared_function()
|
||||
{
|
||||
anything();
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Message/Fatal/Fatal2.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Message\Fatal;
|
||||
|
||||
class Fatal2
|
||||
{
|
||||
public function __construct($param)
|
||||
{
|
||||
if ($param == 'throw') {
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the "junit" formatter
|
||||
Then I should see "Call to undefined function"
|
||||
|
||||
|
||||
@isolated @hhvm
|
||||
Scenario: Fatal error writer message not shown, when formatter does not support it, outputs to stdout.
|
||||
Given the spec file "spec/Message/Fatal/FatalHhvmSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Message\Fatal;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class FatalHhvmSpec extends ObjectBehavior
|
||||
{
|
||||
function it_fatals_when_calling_an_undeclared_function()
|
||||
{
|
||||
anything();
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Message/Fatal/FatalHhvm.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Message\Fatal;
|
||||
|
||||
class FatalHhvm
|
||||
{
|
||||
public function __construct($param)
|
||||
{
|
||||
if ($param == 'throw') {
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec on HHVM with the "junit" formatter
|
||||
Then I should see "Call to undefined function"
|
||||
@@ -1,82 +0,0 @@
|
||||
Feature: Developer is shown a parse error
|
||||
As a Developer
|
||||
I want to know if a parse error was thrown
|
||||
So that I can know that I can handle pass errors
|
||||
|
||||
@isolated @php-version @php5.4 @php7
|
||||
Scenario: Spec attempts to call an undeclared function and outputs to stderr
|
||||
Given the spec file "spec/Message/Fatal/ParseSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Message\Fatal;
|
||||
|
||||
use Parse;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ParseSpec extends ObjectBehavior
|
||||
{
|
||||
function it_thro ws_a_syntax_error()
|
||||
{
|
||||
$this->cool();
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the spec file "src/Message/Fatal/Parse.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Message\Parse;
|
||||
|
||||
class Parse
|
||||
{
|
||||
public function cool()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the "junit" formatter
|
||||
Then I should see "syntax error"
|
||||
|
||||
@isolated @hhvm
|
||||
Scenario: Spec attempts to call an undeclared function and outputs to stdout
|
||||
Given the spec file "spec/Message/Fatal/ParseHhvmSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Message\Fatal;
|
||||
|
||||
use Parse;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ParseHhvmSpec extends ObjectBehavior
|
||||
{
|
||||
function it_thro ws_a_syntax_error()
|
||||
{
|
||||
$this->cool();
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the spec file "src/Message/Fatal/ParseHhvm.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Message\Parse;
|
||||
|
||||
class ParseHhvm
|
||||
{
|
||||
public function cool()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec on HHVM with the "junit" formatter
|
||||
Then I should see "syntax error"
|
||||
@@ -1,48 +0,0 @@
|
||||
Feature: Developer specifies exception behaviour
|
||||
As a Developer
|
||||
I want to be able to specify the exceptions by SUS will throw
|
||||
In order to drive the design of my exception handling
|
||||
|
||||
Scenario: Throwing an exception during construction when beConstructedWith specifies valid parameters
|
||||
Given the spec file "spec/Runner/ExceptionExample3/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ExceptionExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('nothrow');
|
||||
}
|
||||
|
||||
function it_throws_an_exception_using_magic_syntax()
|
||||
{
|
||||
$this->shouldThrow('Exception')->during__construct('throw');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ExceptionExample3/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ExceptionExample3;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function __construct($param)
|
||||
{
|
||||
if ($param == 'throw') {
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,160 +0,0 @@
|
||||
Feature: Developer uses extension
|
||||
As a Developer
|
||||
I want to use my extension
|
||||
|
||||
Scenario: Extension can provide a new matcher
|
||||
Given the config file contains:
|
||||
"""
|
||||
extensions:
|
||||
- Example1\PhpSpec\MatcherExtension\Extension
|
||||
"""
|
||||
And the class file "src/Example1/PhpSpec/MatcherExtension/Extension.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Example1\PhpSpec\MatcherExtension;
|
||||
|
||||
use PhpSpec\Extension\ExtensionInterface;
|
||||
use PhpSpec\ServiceContainer;
|
||||
|
||||
class Extension implements ExtensionInterface
|
||||
{
|
||||
/**
|
||||
* @param ServiceContainer $container
|
||||
*/
|
||||
public function load(ServiceContainer $container)
|
||||
{
|
||||
$container->set('matchers.seven', function (ServiceContainer $c) {
|
||||
return new BeSevenMatcher($c->get('formatter.presenter'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Example1/PhpSpec/MatcherExtension/BeSevenMatcher.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Example1\PhpSpec\MatcherExtension;
|
||||
|
||||
use PhpSpec\Formatter\Presenter\PresenterInterface;
|
||||
use PhpSpec\Exception\Example\FailureException;
|
||||
use PhpSpec\Matcher\BasicMatcher;
|
||||
|
||||
class BeSevenMatcher extends BasicMatcher
|
||||
{
|
||||
/**
|
||||
* @var \PhpSpec\Formatter\Presenter\PresenterInterface
|
||||
*/
|
||||
private $presenter;
|
||||
|
||||
/**
|
||||
* @param PresenterInterface $presenter
|
||||
*/
|
||||
public function __construct(PresenterInterface $presenter)
|
||||
{
|
||||
$this->presenter = $presenter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports($name, $subject, array $arguments)
|
||||
{
|
||||
return 'beSeven' === $name
|
||||
&& is_int($subject)
|
||||
&& 0 == count($arguments)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function matches($subject, array $arguments)
|
||||
{
|
||||
return ($subject === 7);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return FailureException
|
||||
*/
|
||||
protected function getFailureException($name, $subject, array $arguments)
|
||||
{
|
||||
return new FailureException(sprintf(
|
||||
'Seven expected %s to be 7, but it is not.',
|
||||
$this->presenter->presentString($subject)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $subject
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return FailureException
|
||||
*/
|
||||
protected function getNegativeFailureException($name, $subject, array $arguments)
|
||||
{
|
||||
return new FailureException(sprintf(
|
||||
'Seven did not expect %s to 7, but it is.',
|
||||
$this->presenter->presentString($subject)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the spec file "spec/Example1/DummySpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Example1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class DummySpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Example1\Dummy');
|
||||
}
|
||||
function it_should_succeed_in_using_new_matcher()
|
||||
{
|
||||
$this->getSeven()->shouldBeSeven();
|
||||
$this->getFive()->shouldNotBeSeven();
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Example1/Dummy.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Example1;
|
||||
|
||||
class Dummy
|
||||
{
|
||||
public function getSeven()
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
public function getFive()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,566 +0,0 @@
|
||||
Feature: Developer is shown diffs
|
||||
In order to debug failing tests
|
||||
As a developer
|
||||
I should be shown a detailed diff when expected values do not match
|
||||
|
||||
Scenario: String diffing
|
||||
Given the spec file "spec/Diffs/DiffExample1/ClassWithStringsSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithStringsSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_equal()
|
||||
{
|
||||
$this->getString()->shouldReturn('foo');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample1/ClassWithStrings.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample1;
|
||||
|
||||
class ClassWithStrings
|
||||
{
|
||||
public function getString()
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
@@ -1,1 +1,1 @@
|
||||
-foo
|
||||
+bar
|
||||
"""
|
||||
|
||||
Scenario: Array diffing
|
||||
Given the spec file "spec/Diffs/DiffExample2/ClassWithArraysSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithArraysSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_equal()
|
||||
{
|
||||
$this->getArray()->shouldReturn(array(
|
||||
'int' => 1,
|
||||
'string' => 'foo'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample2/ClassWithArrays.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample2;
|
||||
|
||||
class ClassWithArrays
|
||||
{
|
||||
public function getArray()
|
||||
{
|
||||
return array(
|
||||
'int' => 3,
|
||||
'string' => 'bar'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
@@ -1,4 +1,4 @@
|
||||
[
|
||||
- int => 1,
|
||||
- string => "foo",
|
||||
+ int => 3,
|
||||
+ string => "bar",
|
||||
]
|
||||
"""
|
||||
|
||||
Scenario: Object diffing
|
||||
Given the spec file "spec/Diffs/DiffExample3/ClassWithObjectsSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithObjectsSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_equal()
|
||||
{
|
||||
$obj = new \StdClass;
|
||||
$obj->i = 1;
|
||||
$obj->s = 'foo';
|
||||
|
||||
$this->getObject()->shouldReturn($obj);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample3/ClassWithObjects.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample3;
|
||||
|
||||
class ClassWithObjects
|
||||
{
|
||||
public function getObject()
|
||||
{
|
||||
$obj = new \StdClass;
|
||||
$obj->i = 2;
|
||||
$obj->s = 'bar';
|
||||
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
- 'i' => 1
|
||||
- 's' => 'foo'
|
||||
"""
|
||||
And I should see:
|
||||
"""
|
||||
+ 'i' => 2
|
||||
+ 's' => 'bar'
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Unexpected method arguments call arguments string diffing
|
||||
Given the spec file "spec/Diffs/DiffExample4/ClassUnderSpecificationSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample4;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Diffs\DiffExample4\ClassBeingMocked;
|
||||
|
||||
class ClassUnderSpecificationSpec extends ObjectBehavior
|
||||
{
|
||||
function it_can_do_work(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->setValue('some really really long string, and even more, and more!')->shouldBeCalled();
|
||||
$this->doWork($objectBeingMocked);
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample4/ClassUnderSpecification.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample4;
|
||||
|
||||
class ClassUnderSpecification
|
||||
{
|
||||
public function doWork(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->setValue('some really really long string, and even more, and more');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample4/ClassBeingMocked.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample4;
|
||||
|
||||
class ClassBeingMocked
|
||||
{
|
||||
public function setValue($value)
|
||||
{
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
@@ -1,1 +1,1 @@
|
||||
-some really really long string, and even more, and more!
|
||||
+some really really long string, and even more, and more
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Unexpected method arguments call arguments array diffing
|
||||
Given the spec file "spec/Diffs/DiffExample5/ClassUnderSpecificationSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample5;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Diffs\DiffExample5\ClassBeingMocked;
|
||||
|
||||
class ClassUnderSpecificationSpec extends ObjectBehavior
|
||||
{
|
||||
function it_can_do_work(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->setValue(array(
|
||||
'key1' => 'val1',
|
||||
'key2' => 'val2',
|
||||
))->shouldBeCalled();
|
||||
$this->doWork($objectBeingMocked);
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample5/ClassUnderSpecification.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample5;
|
||||
|
||||
class ClassUnderSpecification
|
||||
{
|
||||
public function doWork(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->setValue(array(
|
||||
'key1' => 'val1',
|
||||
'key5' => 'val5',
|
||||
));
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample5/ClassBeingMocked.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample5;
|
||||
|
||||
class ClassBeingMocked
|
||||
{
|
||||
public function setValue($value)
|
||||
{
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
@@ -1,4 +1,4 @@
|
||||
[
|
||||
key1 => "val1",
|
||||
- key2 => "val2",
|
||||
+ key5 => "val5",
|
||||
]
|
||||
"""
|
||||
|
||||
Scenario: Unexpected method arguments call with multiple arguments including null diffing
|
||||
Given the spec file "spec/Diffs/DiffExample6/ClassUnderSpecificationSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample6;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Diffs\DiffExample6\ClassBeingMocked;
|
||||
|
||||
class ClassUnderSpecificationSpec extends ObjectBehavior
|
||||
{
|
||||
function it_can_do_work(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->setValue(array(
|
||||
'key' => 'value'
|
||||
), 'foo', null)->shouldBeCalled();
|
||||
$this->doWork($objectBeingMocked);
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample6/ClassUnderSpecification.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample6;
|
||||
|
||||
class ClassUnderSpecification
|
||||
{
|
||||
public function doWork(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->setValue(array(
|
||||
'key' => 'another value'
|
||||
), 'foo', 'bar');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample6/ClassBeingMocked.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample6;
|
||||
|
||||
class ClassBeingMocked
|
||||
{
|
||||
public function setValue($value)
|
||||
{
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
@@ -1,3 +1,3 @@
|
||||
[
|
||||
- key => "value",
|
||||
+ key => "another value",
|
||||
]
|
||||
"""
|
||||
And I should see:
|
||||
"""
|
||||
@@ -1,1 +1,1 @@
|
||||
-null
|
||||
+bar
|
||||
"""
|
||||
|
||||
Scenario: Unexpected method call
|
||||
Given the spec file "spec/Diffs/DiffExample7/ClassUnderSpecificationSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample7;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Diffs\DiffExample7\ClassBeingMocked;
|
||||
|
||||
class ClassUnderSpecificationSpec extends ObjectBehavior
|
||||
{
|
||||
function it_can_do_work(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->methodOne('value')->shouldBeCalled();
|
||||
$this->doWork($objectBeingMocked);
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample7/ClassUnderSpecification.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample7;
|
||||
|
||||
class ClassUnderSpecification
|
||||
{
|
||||
public function doWork(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->methodTwo('value');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample7/ClassBeingMocked.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample7;
|
||||
|
||||
class ClassBeingMocked
|
||||
{
|
||||
public function methodOne($value)
|
||||
{
|
||||
}
|
||||
|
||||
public function methodTwo($value)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
method call:
|
||||
- methodTwo("value")
|
||||
on Double\Diffs\DiffExample7\ClassBeingMocked\P13 was not expected, expected calls were:
|
||||
- methodOne(exact("value"))
|
||||
"""
|
||||
|
||||
Scenario: Unexpected method call when another prophecy for that call with not matching arguments exists
|
||||
Given the spec file "spec/Diffs/DiffExample8/ClassUnderSpecificationSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample8;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Diffs\DiffExample8\ClassBeingMocked;
|
||||
|
||||
class ClassUnderSpecificationSpec extends ObjectBehavior
|
||||
{
|
||||
function it_can_do_work(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->methodTwo('value')->shouldBeCalled();
|
||||
$objectBeingMocked->methodOne('another value')->shouldBeCalled();
|
||||
|
||||
$this->doWork($objectBeingMocked);
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample8/ClassUnderSpecification.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample8;
|
||||
|
||||
class ClassUnderSpecification
|
||||
{
|
||||
public function doWork(ClassBeingMocked $objectBeingMocked)
|
||||
{
|
||||
$objectBeingMocked->methodTwo('value');
|
||||
$objectBeingMocked->methodTwo('another value');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample8/ClassBeingMocked.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample8;
|
||||
|
||||
class ClassBeingMocked
|
||||
{
|
||||
public function methodOne($value)
|
||||
{
|
||||
}
|
||||
|
||||
public function methodTwo($value)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
method call:
|
||||
- methodTwo("another value")
|
||||
on Double\Diffs\DiffExample8\ClassBeingMocked\P14 was not expected, expected calls were:
|
||||
- methodTwo(exact("value"))
|
||||
- methodOne(exact("another value"))
|
||||
"""
|
||||
|
||||
Scenario: Array diffing with long strings
|
||||
Given the spec file "spec/Diffs/DiffExample9/ClassWithArraysSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample9;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithArraysSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_equal()
|
||||
{
|
||||
$this->getArray()->shouldReturn(array(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam nunc nulla, posuere et arcu ut.'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample9/ClassWithArrays.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample9;
|
||||
|
||||
class ClassWithArrays
|
||||
{
|
||||
public function getArray()
|
||||
{
|
||||
return array(
|
||||
'Vestibulum vehicula nisl at ex maximus, nec lobortis orci luctus. Integer euismod in nunc nec lobortis'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
@@ -1,3 +1,3 @@
|
||||
[
|
||||
- 0 => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam nunc nulla, posuere et arcu ut.",
|
||||
+ 0 => "Vestibulum vehicula nisl at ex maximus, nec lobortis orci luctus. Integer euismod in nunc nec lobortis",
|
||||
]
|
||||
"""
|
||||
|
||||
Scenario: Array diffing with multi line strings
|
||||
Given the spec file "spec/Diffs/DiffExample10/ClassWithArraysSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Diffs\DiffExample10;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ClassWithArraysSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_equal()
|
||||
{
|
||||
$this->getArray()->shouldReturn(array(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
Etiam nunc nulla, posuere et arcu ut.'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Diffs/DiffExample10/ClassWithArrays.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Diffs\DiffExample10;
|
||||
|
||||
class ClassWithArrays
|
||||
{
|
||||
public function getArray()
|
||||
{
|
||||
return array(
|
||||
'Vestibulum vehicula nisl at ex maximus, nec lobortis orci luctus.
|
||||
Integer euismod in nunc nec lobortis'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the "verbose" option
|
||||
Then I should see:
|
||||
"""
|
||||
@@ -1,4 +1,4 @@
|
||||
[
|
||||
- 0 => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
- Etiam nunc nulla, posuere et arcu ut.",
|
||||
+ 0 => "Vestibulum vehicula nisl at ex maximus, nec lobortis orci luctus.
|
||||
+ Integer euismod in nunc nec lobortis",
|
||||
]
|
||||
"""
|
||||
@@ -1,68 +0,0 @@
|
||||
Feature: Use the JUnit formatter
|
||||
In order to provide my CI tool with parsable phpspec results
|
||||
As a developer
|
||||
I need to be able to use a JUnit formatter
|
||||
|
||||
Scenario: Successfully export phpspec results in JUnit format
|
||||
Given the spec file "spec/Formatter/SpecExample/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Formatter\SpecExample;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
// passed
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
|
||||
// pending
|
||||
function it_converts_html_paragraph_to_plain_text()
|
||||
{
|
||||
}
|
||||
|
||||
// failed
|
||||
function it_formats_asterik_surrounding_text_in_italic()
|
||||
{
|
||||
$this->toHtml('*How are you?*')->shouldReturn('<i>How are you?</i>');
|
||||
}
|
||||
|
||||
// broken
|
||||
function it_formats_empty_text()
|
||||
{
|
||||
$this->toHtml('')->shouldReturn('<p></p>');
|
||||
}
|
||||
|
||||
// skipped
|
||||
function it_does_some_incompatible_things()
|
||||
{
|
||||
throw new \PhpSpec\Exception\Example\SkippingException();
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Formatter/SpecExample/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Formatter\SpecExample;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($text)
|
||||
{
|
||||
if (empty($text)) {
|
||||
throw new \InvalidArgumentException('Text cannot be empty: &$£€<>"');
|
||||
}
|
||||
return sprintf('<p>%s</p>', $text);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec using the "junit" format
|
||||
Then I should see valid junit output
|
||||
@@ -1,88 +0,0 @@
|
||||
Feature: Use the TAP formatter
|
||||
So that I can get non-XML parseable results
|
||||
As a Developer
|
||||
I need to be able to use a TAP formatter
|
||||
|
||||
Scenario: A spec which causes various result states
|
||||
Given the spec file "spec/Formatter/TapExample1/TapSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Formatter\TapExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use PhpSpec\Exception\Example\SkippingException;
|
||||
|
||||
class TapSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_most_definitely_pending()
|
||||
{
|
||||
}
|
||||
|
||||
function it_is_most_definitely_passing()
|
||||
{
|
||||
$this->fire('pass')->shouldReturn('pass');
|
||||
}
|
||||
|
||||
function it_is_most_definitely_failing()
|
||||
{
|
||||
$this->fire('fail')->shouldReturn('pass');
|
||||
}
|
||||
|
||||
function it_is_most_definitely_broken()
|
||||
{
|
||||
$this->fire('broken')->shouldReturn('pass');
|
||||
}
|
||||
|
||||
function it_is_most_definitely_skipping()
|
||||
{
|
||||
throw new SkippingException('php is not installed');
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the class file "src/Formatter/TapExample1/Tap.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Formatter\TapExample1;
|
||||
|
||||
use PhpSpec\Exception\Example\ErrorException;
|
||||
|
||||
class Tap
|
||||
{
|
||||
public function fire($stuff)
|
||||
{
|
||||
switch ($stuff) {
|
||||
case 'pass':
|
||||
return 'pass';
|
||||
case 'fail':
|
||||
return 'fail';
|
||||
case 'broken':
|
||||
throw new ErrorException('error','something terrible occurred','foo.php',99);
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run phpspec using the "tap" format
|
||||
Then I should see:
|
||||
"""
|
||||
TAP version 13
|
||||
not ok 1 - Formatter\TapExample1\Tap: is most definitely pending # TODO todo: write pending example
|
||||
---
|
||||
severity: todo
|
||||
...
|
||||
ok 2 - Formatter\TapExample1\Tap: is most definitely passing
|
||||
not ok 3 - Formatter\TapExample1\Tap: is most definitely failing
|
||||
---
|
||||
message: 'Expected "pass", but got "fail".'
|
||||
severity: fail
|
||||
...
|
||||
not ok 4 - Formatter\TapExample1\Tap: is most definitely broken
|
||||
---
|
||||
message: 'error: something terrible occurred in foo.php line 99'
|
||||
severity: fail
|
||||
...
|
||||
ok 5 - Formatter\TapExample1\Tap: is most definitely skipping # SKIP skipped: php is not installed
|
||||
1..5
|
||||
|
||||
"""
|
||||
@@ -1,129 +0,0 @@
|
||||
Feature: Developer uses unsupported collaborator type hinting
|
||||
As a developer
|
||||
I should be shown special exception when I declare collaborators with unsupported type hinting
|
||||
|
||||
Scenario: Array collaborator type hinting
|
||||
Given the spec file "spec/InvalidUsage/InvalidUsageExample1/StorageSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\InvalidUsage\InvalidUsageExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class StorageSpec extends ObjectBehavior
|
||||
{
|
||||
function it_can_store_data(array $data)
|
||||
{
|
||||
$this->store($data)->shouldReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/InvalidUsage/InvalidUsageExample1/Storage.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace InvalidUsage\InvalidUsageExample1;
|
||||
|
||||
class Storage
|
||||
{
|
||||
public function store(array $data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then I should see:
|
||||
"""
|
||||
collaborator must be an object: argument 0 defined in
|
||||
spec\InvalidUsage\InvalidUsageExample1\StorageSpec::it_can_store_data.
|
||||
"""
|
||||
|
||||
@php-version @php5.4
|
||||
Scenario: Callable collaborator type hinting
|
||||
Given the spec file "spec/InvalidUsage/InvalidUsageExample2/InvokerSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\InvalidUsage\InvalidUsageExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class InvokerSpec extends ObjectBehavior
|
||||
{
|
||||
function it_invokes_callable(callable $callback)
|
||||
{
|
||||
$this->invoke($callback)->shouldReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/InvalidUsage/InvalidUsageExample2/Invoker.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace InvalidUsage\InvalidUsageExample2;
|
||||
|
||||
class Invoker
|
||||
{
|
||||
public function invoke(callable $data, array $parameters = array())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then I should see:
|
||||
"""
|
||||
collaborator must be an object: argument 0 defined in
|
||||
spec\InvalidUsage\InvalidUsageExample2\InvokerSpec::it_invokes_callable.
|
||||
"""
|
||||
|
||||
|
||||
@php-version @php7
|
||||
Scenario: Integer collaborator type hinting
|
||||
Given the spec file "spec/InvalidUsage/InvalidUsageExample3/StorageSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\InvalidUsage\InvalidUsageExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class StorageSpec extends ObjectBehavior
|
||||
{
|
||||
function it_can_store_data(int $data)
|
||||
{
|
||||
$this->store($data)->shouldReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/InvalidUsage/InvalidUsageExample3/Storage.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace InvalidUsage\InvalidUsageExample3;
|
||||
|
||||
class Storage
|
||||
{
|
||||
public function store(int $data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then I should see:
|
||||
"""
|
||||
collaborator must be an object: argument 0 defined in
|
||||
spec\InvalidUsage\InvalidUsageExample3\StorageSpec::it_can_store_data.
|
||||
"""
|
||||
@@ -1,41 +0,0 @@
|
||||
Feature: Developer uses array-contain matcher
|
||||
As a Developer
|
||||
I want an array-contain matcher
|
||||
In order to confirm an array contains an expected value
|
||||
|
||||
Scenario: "Contain" alias matches using the array-contain matcher
|
||||
Given the spec file "spec/Matchers/ArrayContainExample1/MovieSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ArrayContainExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MovieSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_contain_jane_smith_in_the_cast()
|
||||
{
|
||||
$this->getCast()->shouldContain('Jane Smith');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ArrayContainExample1/Movie.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ArrayContainExample1;
|
||||
|
||||
class Movie
|
||||
{
|
||||
public function getCast()
|
||||
{
|
||||
return array('John Smith', 'Jane Smith');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,44 +0,0 @@
|
||||
Feature: Developer uses array-key matcher
|
||||
As a Developer
|
||||
I want an array-key matcher
|
||||
In order to confirm an array contains an expected key
|
||||
|
||||
Scenario: "HaveKey" alias matches using the array-key matcher
|
||||
Given the spec file "spec/Matchers/ArrayKeyExample1/MovieSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ArrayKeyExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MovieSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_have_a_release_date_for_france()
|
||||
{
|
||||
$this->getReleaseDates()->shouldHaveKey('France');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ArrayKeyExample1/Movie.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ArrayKeyExample1;
|
||||
|
||||
class Movie
|
||||
{
|
||||
public function getReleaseDates()
|
||||
{
|
||||
return array(
|
||||
'Australia' => '12 April 2013',
|
||||
'France' => '24 April 2013',
|
||||
);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,41 +0,0 @@
|
||||
Feature: Developer uses array-key-value matcher
|
||||
As a Developer
|
||||
I want an array-key-value matcher
|
||||
In order to confirm an array the expected value for a key
|
||||
|
||||
Scenario: "HaveKeyWithValue" alias matches using the array-key-value matcher
|
||||
Given the spec file "spec/Matchers/ArrayKeyValueExample1/MovieSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ArrayKeyValueExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MovieSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_contain_jane_smith_in_the_cast()
|
||||
{
|
||||
$this->getCast()->shouldHaveKeyWithValue('leadRole', 'John Smith');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ArrayKeyValueExample1/Movie.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ArrayKeyValueExample1;
|
||||
|
||||
class Movie
|
||||
{
|
||||
public function getCast()
|
||||
{
|
||||
return array('leadRole' => 'John Smith', 'supportingRole' => 'Jane Smith');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,41 +0,0 @@
|
||||
Feature: Developer uses comparison matcher
|
||||
As a Developer
|
||||
I want a comparison matcher
|
||||
In order to loosely compare a value against an expectation
|
||||
|
||||
Scenario: "BeLike" alias matches using comparison operator
|
||||
Given the spec file "spec/Matchers/ComparisonExample1/StringCalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ComparisonExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class StringCalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_returns_the_value_of_a_string()
|
||||
{
|
||||
$this->calc('5')->shouldBeLike('5');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ComparisonExample1/StringCalculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ComparisonExample1;
|
||||
|
||||
class StringCalculator
|
||||
{
|
||||
public function calc($string)
|
||||
{
|
||||
return (int) $string;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,41 +0,0 @@
|
||||
Feature: Developer uses array-count matcher
|
||||
As a Developer
|
||||
I want an array-count matcher
|
||||
In order to compare an array count against an expectation
|
||||
|
||||
Scenario: "HaveCount" alias matches using the array-count matcher
|
||||
Given the spec file "spec/Matchers/ArrayCountExample1/CarSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ArrayCountExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CarSpec extends ObjectBehavior
|
||||
{
|
||||
function it_returns_the_number_of_wheels()
|
||||
{
|
||||
$this->getWheels()->shouldHaveCount(4);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ArrayCountExample1/Car.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ArrayCountExample1;
|
||||
|
||||
class Car
|
||||
{
|
||||
public function getWheels()
|
||||
{
|
||||
return array('wheel', 'wheel', 'wheel', 'wheel');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,448 +0,0 @@
|
||||
Feature: Developer uses identity matcher
|
||||
As a Developer
|
||||
I want an identity matcher
|
||||
In order to match the identity of a value against an expectation
|
||||
|
||||
Scenario: "Return" alias matching using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample1/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldReturn(3);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample1/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample1;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Return" alias not matching using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample2/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldNotReturn(4);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample2/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample2;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Return" alias not matching type using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample3/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldNotReturn("3");
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample3/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample3;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Be" alias matching using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample4/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample4;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldBe(3);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample4/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample4;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Be" alias not matching using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample5/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample5;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldNotBe(4);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample5/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample5;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Be" alias not matching type using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample6/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample6;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldNotBe("3");
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample6/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample6;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Equal" alias matching using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample7/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample7;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldEqual(3);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample7/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample7;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Equal" alias not matching using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample8/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample8;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldNotEqual(4);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample8/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample8;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Equal" alias not matching type using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample9/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample9;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldNotEqual("3");
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample9/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample9;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "BeEqualTo" alias matching using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample10/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample10;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldEqual(3);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample10/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample10;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Equal" alias not matching using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample11/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample11;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldNotEqual(4);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample11/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample11;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Equal" alias not matching type using identity operator
|
||||
Given the spec file "spec/Matchers/IdentityExample12/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\IdentityExample12;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2)->shouldNotEqual("3");
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/IdentityExample12/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\IdentityExample12;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function sum($x, $y)
|
||||
{
|
||||
return $x + $y;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,161 +0,0 @@
|
||||
Feature: Developer uses identity matcher
|
||||
As a Developer
|
||||
I want an inline matcher
|
||||
So I can create expectations in a language closer to the domain I am describing
|
||||
|
||||
Scenario: Inline matcher with no argument
|
||||
Given the spec file "spec/Matchers/InlineExample1/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\InlineExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2);
|
||||
$this->shouldBePositive();
|
||||
}
|
||||
|
||||
function getMatchers()
|
||||
{
|
||||
return array ('bePositive' => function($subject) {
|
||||
return $subject->getTotal() > 0;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/InlineExample1/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\InlineExample1;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
private $total;
|
||||
|
||||
public function sum($x, $y)
|
||||
{
|
||||
$this->total = $x + $y;
|
||||
}
|
||||
|
||||
public function getTotal()
|
||||
{
|
||||
return $this->total;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: Inline matcher with an argument
|
||||
Given the spec file "spec/Matchers/InlineExample2/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\InlineExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_calculates_the_sum_of_two_addends()
|
||||
{
|
||||
$this->sum(1, 2);
|
||||
$this->shouldTotal(3);
|
||||
}
|
||||
|
||||
function getMatchers()
|
||||
{
|
||||
return array ('total' => function($subject, $total) {
|
||||
return $subject->getTotal() === $total;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/InlineExample2/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\InlineExample2;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
private $total;
|
||||
|
||||
public function sum($x, $y)
|
||||
{
|
||||
$this->total = $x + $y;
|
||||
}
|
||||
|
||||
public function getTotal()
|
||||
{
|
||||
return $this->total;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: Inline matcher throwing an exception
|
||||
Given the spec file "spec/Matchers/InlineExample3/CalculatorSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\InlineExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use PhpSpec\Exception\Example\FailureException;
|
||||
|
||||
class CalculatorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_uses_inline_matcher_that_throws_an_exception()
|
||||
{
|
||||
$this->shouldDoSomething('abc');
|
||||
}
|
||||
|
||||
function getMatchers()
|
||||
{
|
||||
return array ('doSomething' => function($subject, $param) {
|
||||
throw new FailureException(sprintf(
|
||||
'a very important message with subject "%s" and param "%s".',
|
||||
$subject, $param
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Matchers/InlineExample3/Calculator.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\InlineExample3;
|
||||
|
||||
class Calculator
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return 'Hi';
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should not pass
|
||||
Then I should see "a very important message"
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
Feature: Developer uses object-state matcher
|
||||
As a Developer
|
||||
I want an object-state matcher
|
||||
In order to validate objects against an expectation
|
||||
|
||||
Scenario: "Have" alias matches using the object-state matcher
|
||||
Given the spec file "spec/Matchers/ObjectStateExample1/CarSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ObjectStateExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CarSpec extends ObjectBehavior
|
||||
{
|
||||
function it_returns_true_if_it_has_an_wheels()
|
||||
{
|
||||
$this->shouldHaveWheels();
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ObjectStateExample1/Car.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ObjectStateExample1;
|
||||
|
||||
class Car
|
||||
{
|
||||
public function hasWheels()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Be" alias matches using the object-state matcher
|
||||
Given the spec file "spec/Matchers/ObjectStateExample2/CarSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ObjectStateExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CarSpec extends ObjectBehavior
|
||||
{
|
||||
function it_returns_true_if_it_is_available()
|
||||
{
|
||||
$this->shouldBeAvailable();
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ObjectStateExample2/Car.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ObjectStateExample2;
|
||||
|
||||
class Car
|
||||
{
|
||||
public function isAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,53 +0,0 @@
|
||||
Feature: Developer uses scalar matcher
|
||||
As a Developer
|
||||
I want an scalar matcher
|
||||
In order to match against various scalar values against their expectations
|
||||
|
||||
Scenario: Scalar matching aliases match using the scalar matcher
|
||||
Given the spec file "spec/Matchers/ScalarExample1/CarSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ScalarExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CarSpec extends ObjectBehavior
|
||||
{
|
||||
function it_returns_the_result()
|
||||
{
|
||||
$result = $this->getDetails();
|
||||
|
||||
$result['name']->shouldBeString();
|
||||
$result['age']->shouldBeInteger();
|
||||
$result['price']->shouldBeFloat();
|
||||
$result['sale']->shouldBeBool();
|
||||
$result['callback']->shouldBeCallable();
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ScalarExample1/Car.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ScalarExample1;
|
||||
|
||||
class Car
|
||||
{
|
||||
public function getDetails()
|
||||
{
|
||||
return array(
|
||||
'name' => 'astra',
|
||||
'age' => 34,
|
||||
'price' => 10.99,
|
||||
'sale' => true,
|
||||
'callback' => function() {}
|
||||
);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,41 +0,0 @@
|
||||
Feature: Developer uses string-contain matcher
|
||||
As a Developer
|
||||
I want a string-contain matcher
|
||||
In order to confirm a string contains an expected substring
|
||||
|
||||
Scenario: "Contain" alias matches using the string-contain matcher
|
||||
Given the spec file "spec/Matchers/StringContainExample1/MovieSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\StringContainExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MovieSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_have_a_title_that_contains_days()
|
||||
{
|
||||
$this->getTitle()->shouldContain('days');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/StringContainExample1/Movie.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\StringContainExample1;
|
||||
|
||||
class Movie
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return 'The future days of past';
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,41 +0,0 @@
|
||||
Feature: Developer uses string-end matcher
|
||||
As a Developer
|
||||
I want an string-end matcher
|
||||
In order to confirm a string ends with an expected substring
|
||||
|
||||
Scenario: "EndsWith" alias matches using the string-end matcher
|
||||
Given the spec file "spec/Matchers/StringEndExample1/MovieSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\StringEndExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MovieSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_have_a_title_that_ends_with_of_oz()
|
||||
{
|
||||
$this->getTitle()->shouldEndWith('of Oz');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/StringEndExample1/Movie.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\StringEndExample1;
|
||||
|
||||
class Movie
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return 'The Wizard of Oz';
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,41 +0,0 @@
|
||||
Feature: Developer uses string-regex matcher
|
||||
As a Developer
|
||||
I want an string-regex matcher
|
||||
In order to confirm a string matches against an expected regular expression
|
||||
|
||||
Scenario: "Matches" alias matches using the string-regex matcher
|
||||
Given the spec file "spec/Matchers/StringRegexExample1/MovieSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\StringRegexExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MovieSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_have_a_title_that_contains_wizard()
|
||||
{
|
||||
$this->getTitle()->shouldMatch('/wizard/i');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/StringRegexExample1/Movie.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\StringRegexExample1;
|
||||
|
||||
class Movie
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return 'The Wizard of Oz';
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,41 +0,0 @@
|
||||
Feature: Developer uses string-start matcher
|
||||
As a Developer
|
||||
I want an string-start matcher
|
||||
In order to confirm a string starts with an expected substring
|
||||
|
||||
Scenario: "StartWith" alias matches using the string-start matcher
|
||||
Given the spec file "spec/Matchers/StringStartExample1/MovieSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\StringStartExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MovieSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_have_a_title_that_starts_with_the_wizard()
|
||||
{
|
||||
$this->getTitle()->shouldStartWith('The Wizard');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/StringStartExample1/Movie.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\StringStartExample1;
|
||||
|
||||
class Movie
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return 'The Wizard of Oz';
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,215 +0,0 @@
|
||||
Feature: Developer uses throw matcher
|
||||
As a Developer
|
||||
I want a throw matcher
|
||||
In order to validate objects exceptions against my expectations
|
||||
|
||||
Scenario: "Throw" alias matches using the throw matcher with explicit method name
|
||||
Given the spec file "spec/Matchers/ThrowExample1/EmployeeSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ThrowExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class EmployeeSpec extends ObjectBehavior
|
||||
{
|
||||
function it_throws_an_exception_when_arguments_are_invalid()
|
||||
{
|
||||
$this->shouldThrow('\InvalidArgumentException')->during('setAge', array(0));
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ThrowExample1/Employee.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ThrowExample1;
|
||||
|
||||
class Employee
|
||||
{
|
||||
public function setAge($age)
|
||||
{
|
||||
if (0 === $age) {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Throw" alias matches using the throw matcher with implicit method name
|
||||
Given the spec file "spec/Matchers/ThrowExample2/EmployeeSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ThrowExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class EmployeeSpec extends ObjectBehavior
|
||||
{
|
||||
function it_throws_an_exception_when_arguments_are_invalid()
|
||||
{
|
||||
$this->shouldThrow('\InvalidArgumentException')->duringSetAge(0);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ThrowExample2/Employee.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ThrowExample2;
|
||||
|
||||
class Employee
|
||||
{
|
||||
public function setAge($age)
|
||||
{
|
||||
if (0 === $age) {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
|
||||
Scenario: "Throw" alias matches using the throw matcher with specific exception message
|
||||
Given the spec file "spec/Matchers/ThrowExample3/EmployeeSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\ThrowExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class EmployeeSpec extends ObjectBehavior
|
||||
{
|
||||
function it_throws_an_exception_when_arguments_are_invalid()
|
||||
{
|
||||
$this->shouldThrow(new \InvalidArgumentException('Invalid age'))->duringSetAge(0);
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/ThrowExample3/Employee.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\ThrowExample3;
|
||||
|
||||
class Employee
|
||||
{
|
||||
public function setAge($age)
|
||||
{
|
||||
if (0 === $age) {
|
||||
throw new \InvalidArgumentException('Invalid age');
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
@issue134
|
||||
Scenario: Throwing an exception during object construction
|
||||
Given the spec file "spec/Runner/ThrowExample4/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ThrowExample4;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_throws_an_exception_using_during_syntax()
|
||||
{
|
||||
$this->shouldThrow('Exception')->during('__construct', array(1,2));
|
||||
}
|
||||
|
||||
function it_throws_an_exception_using_magic_syntax()
|
||||
{
|
||||
$this->shouldThrow('Exception')->during__construct(1,2);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ThrowExample4/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ThrowExample4;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function __construct($num1, $num2)
|
||||
{
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
@issue610
|
||||
Scenario: Throwing an exception during object construction
|
||||
Given the spec file "spec/Runner/ThrowExample5/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\ThrowExample5;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_throws_an_exception_using_during_instantiation_syntax()
|
||||
{
|
||||
$this->beConstructedWith(1, 2);
|
||||
$this->shouldThrow('\InvalidArgumentException')->duringInstantiation();
|
||||
}
|
||||
|
||||
function it_throws_an_exception_using_during_named_instantiation_syntax()
|
||||
{
|
||||
$this->beConstructedThrough('defaultNumber2', array(1));
|
||||
$this->shouldThrow('\InvalidArgumentException')->duringInstantiation();
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/ThrowExample5/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\ThrowExample5;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function __construct($num1, $num2)
|
||||
{
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
public static function defaultNumber2($num1, $num2 = 2)
|
||||
{
|
||||
return new self($num1, $num2);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,145 +0,0 @@
|
||||
Feature: Developer uses type matcher
|
||||
As a Developer
|
||||
I want a type matcher
|
||||
In order to confirm that my object is of a given type
|
||||
|
||||
Scenario: "HaveType" alias matches using the type matcher
|
||||
Given the spec file "spec/Matchers/TypeExample1/CarSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\TypeExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CarSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_be_a_car()
|
||||
{
|
||||
$this->shouldHaveType('Matchers\TypeExample1\Car');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/TypeExample1/Car.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\TypeExample1;
|
||||
|
||||
class Car
|
||||
{
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
|
||||
Scenario: "ReturnAnInstanceOf" alias matches using the type matcher
|
||||
Given the spec file "spec/Matchers/TypeExample2/CarSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\TypeExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CarSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_be_a_car()
|
||||
{
|
||||
$this->get()->shouldReturnAnInstanceOf('Matchers\TypeExample2\Car');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/TypeExample2/Car.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\TypeExample2;
|
||||
|
||||
class Car
|
||||
{
|
||||
public function get()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "BeAnInstanceOf" alias matches using the type matcher
|
||||
Given the spec file "spec/Matchers/TypeExample3/CarSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\TypeExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CarSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_be_a_car()
|
||||
{
|
||||
$this->get()->shouldBeAnInstanceOf('Matchers\TypeExample3\Car');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/TypeExample3/Car.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\TypeExample3;
|
||||
|
||||
class Car
|
||||
{
|
||||
public function get()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: "Implement" alias matches using the type matcher
|
||||
Given the spec file "spec/Matchers/TypeExample4/CarSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Matchers\TypeExample4;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class CarSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_be_a_car()
|
||||
{
|
||||
$this->shouldImplement('Matchers\TypeExample4\Car');
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
And the class file "src/Matchers/TypeExample4/Car.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Matchers\TypeExample4;
|
||||
|
||||
class Car
|
||||
{
|
||||
}
|
||||
"""
|
||||
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
@@ -1,81 +0,0 @@
|
||||
Feature: Developer chooses no code generation
|
||||
As a Developer
|
||||
I want to set the no code generation setting option
|
||||
In order to specify how phpspec behaves when a class is not found
|
||||
|
||||
@issue352
|
||||
Scenario: code-generation defaults to off
|
||||
Given the spec file "spec/NoCodeGeneration/SpecExample1/NewClassSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\NoCodeGeneration\SpecExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class NewClassSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('NoCodeGeneration\NewClass');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec interactively
|
||||
Then I should be prompted for code generation
|
||||
|
||||
@issue352
|
||||
Scenario: code-generation is specified in the config
|
||||
Given the config file contains:
|
||||
"""
|
||||
code_generation: false
|
||||
"""
|
||||
And the spec file "spec/NoCodeGeneration/SpecExample2/NewClassSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\NoCodeGeneration\SpecExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class NewClassSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('NoCodeGeneration\NewClass');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec interactively
|
||||
Then I should not be prompted for code generation
|
||||
|
||||
@issue352
|
||||
Scenario: code-generation on the command line takes priority
|
||||
Given the config file contains:
|
||||
"""
|
||||
code_generation: true
|
||||
"""
|
||||
And the spec file "spec/NoCodeGeneration/SpecExample3/NewClassSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\NoCodeGeneration\SpecExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class NewClassSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('NoCodeGeneration\NewClass');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec interactively with the "no-code-generation" option
|
||||
Then I should not be prompted for code generation
|
||||
@@ -1,144 +0,0 @@
|
||||
Feature: Developer chooses stop on failure
|
||||
As a Developer
|
||||
I want to set the stop on failure setting option
|
||||
In order to specify how phpspec behaves on failure
|
||||
|
||||
@issue352
|
||||
Scenario: stop-on-failure defaults to off
|
||||
Given the spec file "spec/SkipOnFailure/SpecExample1/FirstFailSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\SkipOnFailure\SpecExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class FirstFailSpec extends ObjectBehavior
|
||||
{
|
||||
function it_fails()
|
||||
{
|
||||
$this->getValue()->shouldReturn(2);
|
||||
}
|
||||
|
||||
function it_should_never_get_called()
|
||||
{
|
||||
$this->getValue()->shouldReturn(1);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/SkipOnFailure/SpecExample1/FirstFail.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace SkipOnFailure\SpecExample1;
|
||||
|
||||
class FirstFail
|
||||
{
|
||||
public function getValue()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then 2 examples should have been run
|
||||
|
||||
@issue352
|
||||
Scenario: stop-on-failure is specified in the config
|
||||
Given the config file contains:
|
||||
"""
|
||||
stop_on_failure: true
|
||||
"""
|
||||
And the spec file "spec/SkipOnFailure/SpecExample2/FirstFailSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\SkipOnFailure\SpecExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class FirstFailSpec extends ObjectBehavior
|
||||
{
|
||||
function it_fails()
|
||||
{
|
||||
$this->getValue()->shouldReturn(2);
|
||||
}
|
||||
|
||||
function it_should_never_get_called()
|
||||
{
|
||||
$this->getValue()->shouldReturn(1);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/SkipOnFailure/SpecExample2/FirstFail.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace SkipOnFailure\SpecExample2;
|
||||
|
||||
class FirstFail
|
||||
{
|
||||
public function getValue()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then 1 example should have been run
|
||||
And the exit code should be 1
|
||||
|
||||
@issue352
|
||||
Scenario: stop-on-failure at command line overrides config
|
||||
Given the config file contains:
|
||||
"""
|
||||
stop_on_failure: false
|
||||
"""
|
||||
And the spec file "spec/SkipOnFailure/SpecExample3/FirstFailSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\SkipOnFailure\SpecExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class FirstFailSpec extends ObjectBehavior
|
||||
{
|
||||
function it_fails()
|
||||
{
|
||||
$this->getValue()->shouldReturn(2);
|
||||
}
|
||||
|
||||
function it_should_never_get_called()
|
||||
{
|
||||
$this->getValue()->shouldReturn(1);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/SkipOnFailure/SpecExample3/FirstFail.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace SkipOnFailure\SpecExample3;
|
||||
|
||||
class FirstFail
|
||||
{
|
||||
public function getValue()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the "stop-on-failure" option
|
||||
Then 1 example should have been run
|
||||
And the exit code should be 1
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
Feature: Developer is told about pending specs
|
||||
So that I remember to implement specs
|
||||
As a Developer
|
||||
I should be told about specs with missing bodies
|
||||
|
||||
Scenario: Empty spec causes pending result
|
||||
Given the spec file "spec/Runner/PendingExample1/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\PendingExample1;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run phpspec using the "pretty" format
|
||||
Then I should see:
|
||||
"""
|
||||
9 - converts plain text to html paragraphs
|
||||
todo: write pending example
|
||||
|
||||
|
||||
1 specs
|
||||
1 examples (1 pending)
|
||||
"""
|
||||
|
||||
Scenario: Spec with comments causes pending result
|
||||
Given the spec file "spec/Runner/PendingExample2/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\PendingExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
/**
|
||||
multi-line doc - comment
|
||||
*/
|
||||
/*
|
||||
multi-line comment
|
||||
*/
|
||||
// single-line comment
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run phpspec using the "pretty" format
|
||||
Then I should see:
|
||||
"""
|
||||
9 - converts plain text to html paragraphs
|
||||
todo: write pending example
|
||||
|
||||
|
||||
1 specs
|
||||
1 examples (1 pending)
|
||||
"""
|
||||
|
||||
@issue492
|
||||
Scenario: Comments with braces do not confuse the parser
|
||||
Given the spec file "spec/Runner/PendingExample3/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\PendingExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
pow(2,2);
|
||||
// {
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run phpspec using the "pretty" format
|
||||
Then I should see:
|
||||
"""
|
||||
1 examples (1 passed)
|
||||
"""
|
||||
|
||||
@php-version @php5.4
|
||||
Scenario: Spec defined in trait does not cause pending
|
||||
Given the trait file "spec/Runner/PendingExample4/PartialSpecTrait.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\PendingExample4;
|
||||
|
||||
trait PartialSpecTrait
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
pow(2,2);
|
||||
}
|
||||
}
|
||||
"""
|
||||
And the spec file "spec/Runner/PendingExample4/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\PendingExample4;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
use PartialSpecTrait;
|
||||
}
|
||||
"""
|
||||
When I run phpspec using the "pretty" format
|
||||
Then I should see:
|
||||
"""
|
||||
1 examples (1 passed)
|
||||
"""
|
||||
@@ -1,204 +0,0 @@
|
||||
Feature: Developer runs the specs
|
||||
As a Developer
|
||||
I want to run the specs
|
||||
In order to get feedback on a state of my application
|
||||
|
||||
Scenario: Running a spec with a class that doesn't exist
|
||||
Given I have started describing the "Runner/SpecExample1/Markdown" class
|
||||
When I run phpspec
|
||||
Then I should see "class Runner\SpecExample1\Markdown does not exist"
|
||||
|
||||
Scenario: Reporting success when running a spec with correctly implemented class
|
||||
Given the spec file "spec/Runner/SpecExample2/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\SpecExample2;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/SpecExample2/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\SpecExample2;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($text)
|
||||
{
|
||||
return sprintf('<p>%s</p>', $text);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then the suite should pass
|
||||
|
||||
@issue214
|
||||
Scenario: Letgo is executed after successful spec
|
||||
Given the spec file "spec/Runner/SpecExample3/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\SpecExample3;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function letgo()
|
||||
{
|
||||
throw new \Exception('Letgo is called');
|
||||
}
|
||||
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/SpecExample3/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\SpecExample3;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($text)
|
||||
{
|
||||
return sprintf('<p>%s</p>', $text);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then I should see "Letgo is called"
|
||||
|
||||
@issue214
|
||||
Scenario: Letgo is executed after exception is thrown
|
||||
Given the spec file "spec/Runner/SpecExample4/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\SpecExample4;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function letgo()
|
||||
{
|
||||
throw new \Exception('Letgo is called');
|
||||
}
|
||||
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/SpecExample4/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\SpecExample4;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($text)
|
||||
{
|
||||
throw new \Exception('Some exception');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec
|
||||
Then I should see "Letgo is called"
|
||||
|
||||
|
||||
Scenario: Fully qualified class name can run specs
|
||||
Given the spec file "spec/Runner/Namespace/Example1Spec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
namespace spec\Runner\TestNamespace;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class Example1Spec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Runner\TestNamespace\Example1');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/TestNamespace/Example1.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\TestNamespace;
|
||||
|
||||
class Example1
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with the spec "Runner\TestNamespace\Example1"
|
||||
Then the suite should pass
|
||||
|
||||
Scenario: Fully qualified PSR4 class name can run specs
|
||||
Given the spec file "spec/Runner/Namespace/Example2Spec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
namespace spec\Psr4\Runner\TestNamespace;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class Example2Spec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('Psr4\Runner\TestNamespace\Example2');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Psr4/Runner/TestNamespace/Example2.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Psr4\Runner\TestNamespace;
|
||||
|
||||
class Example2
|
||||
{
|
||||
}
|
||||
|
||||
"""
|
||||
And the config file located in "Psr4" contains:
|
||||
"""
|
||||
suites:
|
||||
behat_suite:
|
||||
namespace: Psr4
|
||||
psr4_prefix: Psr4
|
||||
"""
|
||||
When I run phpspec with the spec "Psr4\Runner\TestNamespace\Example2" and the config "Psr4/phpspec.yml"
|
||||
Then the suite should pass
|
||||
@@ -1,31 +0,0 @@
|
||||
Feature: Developer runs the specs with bootstrap option
|
||||
As a Developer
|
||||
I want to run the specs and specify bootstrap file
|
||||
In order to get feedback on a state of my application
|
||||
|
||||
Scenario: Running a spec with --bootstrap option
|
||||
Given the bootstrap file "bootstrap.php" contains:
|
||||
"""
|
||||
<?php
|
||||
throw new \Exception('bootstrap file is loaded');
|
||||
"""
|
||||
When I run phpspec with option --bootstrap=bootstrap.php
|
||||
Then I should see "bootstrap file is loaded"
|
||||
|
||||
Scenario: Running a spec with bootstrap option in config file
|
||||
Given the bootstrap file "bootstrap.php" contains:
|
||||
"""
|
||||
<?php
|
||||
throw new \Exception('bootstrap file is loaded');
|
||||
"""
|
||||
And the config file contains:
|
||||
"""
|
||||
bootstrap: bootstrap.php
|
||||
"""
|
||||
When I run phpspec
|
||||
Then I should see "bootstrap file is loaded"
|
||||
|
||||
Scenario: Running a spec with --bootstrap option and bootstrap file is missing.
|
||||
Given there is no file "missing.php"
|
||||
When I run phpspec with option --bootstrap=missing.php
|
||||
Then I should see "Bootstrap file 'missing.php' does not exist"
|
||||
@@ -1,52 +0,0 @@
|
||||
Feature: Developer runs specs with the given specs path configured to be the same as source path
|
||||
As a Developer
|
||||
I want to run the specs from given directory
|
||||
In order to get feedback on a state of requested part of my application
|
||||
|
||||
Scenario: Reporting success when running a spec with correctly implemented class, passing spec path as an argument
|
||||
Given the config file contains:
|
||||
"""
|
||||
suites:
|
||||
code_generator_suite:
|
||||
namespace: Runner\SpecPathExample
|
||||
psr4_prefix: Runner\SpecPathExample
|
||||
src_path: src/Runner/SpecPathExample
|
||||
spec_path: src/Runner/SpecPathExample
|
||||
|
||||
"""
|
||||
And the spec file "src/Runner/SpecPathExample/spec/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\SpecPathExample;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_to_html_paragraphs()
|
||||
{
|
||||
$this->toHtml('Hi, there')->shouldReturn('<p>Hi, there</p>');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/SpecPathExample/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\SpecPathExample;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($text)
|
||||
{
|
||||
return sprintf('<p>%s</p>', $text);
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec with "src/Runner/SpecPathExample/spec" specs to run
|
||||
Then 1 example should have been run
|
||||
And the suite should pass
|
||||
@@ -1,42 +0,0 @@
|
||||
Feature: Developer skips examples
|
||||
As a Developer
|
||||
I want to skip some examples I know won't pass
|
||||
In order to sanitize my result output
|
||||
|
||||
Scenario: Skip a spec with and run it using the dot formatter
|
||||
Given the spec file "spec/Runner/SpecExample/MarkdownSpec.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace spec\Runner\SpecExample;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use PhpSpec\Exception\Example\SkippingException;
|
||||
|
||||
class MarkdownSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_plain_text_table_to_html_table()
|
||||
{
|
||||
throw new SkippingException('subject to a php bug');
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
And the class file "src/Runner/SpecExample/Markdown.php" contains:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace Runner\SpecExample;
|
||||
|
||||
class Markdown
|
||||
{
|
||||
public function toHtml($text)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
When I run phpspec using the "dot" format
|
||||
Then 1 example should have been skipped
|
||||
But the suite should pass
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace integration\PhpSpec\Console\Prompter;
|
||||
|
||||
use PhpSpec\Console\Prompter\Dialog;
|
||||
|
||||
/**
|
||||
* @requires function \Symfony\Component\Console\Helper\DialogHelper::askConfirmation
|
||||
*/
|
||||
class DialogTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Console\Output\OutputInterface
|
||||
*/
|
||||
private $output;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Console\Helper\DialogHelper
|
||||
*/
|
||||
private $dialogHelper;
|
||||
|
||||
/**
|
||||
* @var \PhpSpec\Console\Prompter
|
||||
*/
|
||||
private $prompter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
|
||||
$this->dialogHelper = $this->getMockBuilder('Symfony\Component\Console\Helper\DialogHelper')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
|
||||
$this->prompter = new Dialog($this->output, $this->dialogHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
function it_is_a_prompter()
|
||||
{
|
||||
$this->assertInstanceOf('PhpSpec\Console\Prompter', $this->prompter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
function it_can_ask_a_question_and_return_the_result()
|
||||
{
|
||||
$this->dialogHelper->expects($this->once())
|
||||
->method('askConfirmation')
|
||||
->with($this->identicalTo($this->output), 'Are you sure?', true)
|
||||
->willReturn(true);
|
||||
|
||||
$result = $this->prompter->askConfirmation('Are you sure?');
|
||||
|
||||
$this->assertEquals(true, $result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace integration\PhpSpec\Console\Prompter;
|
||||
|
||||
use PhpSpec\Console\Prompter\Factory;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
|
||||
class FactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Console\Input\InputInterface
|
||||
*/
|
||||
private $input;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Console\Output\OutputInterface
|
||||
*/
|
||||
private $output;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $reportingLevel;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->reportingLevel = error_reporting();
|
||||
error_reporting($this->reportingLevel & ~E_USER_DEPRECATED);
|
||||
|
||||
$this->input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
|
||||
$this->output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
|
||||
}
|
||||
|
||||
/**
|
||||
* Symfony <2.5 case
|
||||
*
|
||||
* @requires function \Symfony\Component\Console\Helper\DialogHelper::askConfirmation
|
||||
* @test
|
||||
*/
|
||||
function it_provides_a_dialog_prompter_when_only_dialoghelper_is_registered()
|
||||
{
|
||||
$dialogHelper = $this->getMock('Symfony\Component\Console\Helper\DialogHelper');
|
||||
|
||||
$helperSet = new HelperSet(array(
|
||||
'dialog' => $dialogHelper
|
||||
));
|
||||
|
||||
$factory = new Factory($this->input, $this->output, $helperSet);
|
||||
$prompter = $factory->getPrompter();
|
||||
|
||||
$this->assertInstanceOf('PhpSpec\Console\Prompter\Dialog', $prompter);
|
||||
|
||||
$dialogHelper->expects($this->once())->method('askConfirmation');;
|
||||
$prompter->askConfirmation('Are you sure?');
|
||||
}
|
||||
|
||||
/**
|
||||
* Symfony >=3.0 case
|
||||
*
|
||||
* @requires function \Symfony\Component\Console\Helper\QuestionHelper::ask
|
||||
* @test
|
||||
*/
|
||||
function it_provides_a_question_prompter_when_only_questionhelper_is_registered()
|
||||
{
|
||||
$questionHelper = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper');
|
||||
|
||||
$helperSet = new HelperSet(array(
|
||||
'question' => $questionHelper
|
||||
));
|
||||
|
||||
$factory = new Factory($this->input, $this->output, $helperSet);
|
||||
$prompter = $factory->getPrompter();
|
||||
$this->assertInstanceOf('PhpSpec\Console\Prompter\Question', $prompter);
|
||||
|
||||
$questionHelper->expects($this->once())->method('ask');
|
||||
$prompter->askConfirmation('Are you sure?');
|
||||
}
|
||||
|
||||
/**
|
||||
* Symfony >=2.5 <3.0 case
|
||||
*
|
||||
* @requires function \Symfony\Component\Console\Helper\QuestionHelper::ask
|
||||
* @requires function \Symfony\Component\Console\Helper\DialogHelper::askConfirmation
|
||||
* @test
|
||||
*/
|
||||
function it_provides_a_question_prompter_when_both_prompters_are_registered()
|
||||
{
|
||||
$dialogHelper = $this->getMock('Symfony\Component\Console\Helper\DialogHelper');
|
||||
$questionHelper = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper');
|
||||
|
||||
$helperSet = new HelperSet(array(
|
||||
'dialog' => $dialogHelper,
|
||||
'question' => $questionHelper
|
||||
));
|
||||
|
||||
$factory = new Factory($this->input, $this->output, $helperSet);
|
||||
$prompter = $factory->getPrompter();
|
||||
$this->assertInstanceOf('PhpSpec\Console\Prompter\Question', $prompter);
|
||||
|
||||
$questionHelper->expects($this->once())->method('ask');
|
||||
$prompter->askConfirmation('Are you sure?');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
error_reporting($this->reportingLevel);
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace integration\PhpSpec\Console\Prompter;
|
||||
|
||||
use PhpSpec\Console\Prompter\Question;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
|
||||
/**
|
||||
* @requires function \Symfony\Component\Console\Helper\QuestionHelper::ask
|
||||
*/
|
||||
class QuestionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Console\Input\InputInterface
|
||||
*/
|
||||
private $input;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Console\Output\OutputInterface
|
||||
*/
|
||||
private $output;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Console\Helper\QuestionHelper
|
||||
*/
|
||||
private $questionHelper;
|
||||
|
||||
/**
|
||||
* @var \PhpSpec\Console\Prompter
|
||||
*/
|
||||
private $prompter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
|
||||
$this->output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
|
||||
$this->questionHelper = $this->getMock('Symfony\Component\Console\Helper\QuestionHelper');
|
||||
|
||||
$this->prompter = new Question($this->input, $this->output, $this->questionHelper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
function it_is_a_prompter()
|
||||
{
|
||||
$this->assertInstanceOf('PhpSpec\Console\Prompter', $this->prompter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
function it_can_ask_a_question_and_return_the_result()
|
||||
{
|
||||
$this->questionHelper->expects($this->once())
|
||||
->method('ask')
|
||||
->with(
|
||||
$this->identicalTo($this->input),
|
||||
$this->identicalTo($this->output),
|
||||
$this->equalTo(new ConfirmationQuestion('Are you sure?', true))
|
||||
)
|
||||
->willReturn(true);
|
||||
|
||||
$result = $this->prompter->askConfirmation('Are you sure?');
|
||||
|
||||
$this->assertEquals(true, $result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace integration\PhpSpec\Loader;
|
||||
|
||||
use PhpSpec\CodeAnalysis\TokenizedNamespaceResolver;
|
||||
use PhpSpec\CodeAnalysis\TokenizedTypeHintRewriter;
|
||||
use PhpSpec\Loader\StreamWrapper;
|
||||
use PhpSpec\Loader\Transformer\InMemoryTypeHintIndex;
|
||||
use PhpSpec\Loader\Transformer\TypeHintRewriter;
|
||||
|
||||
class StreamWrapperTest extends \PHPUnit_Framework_Testcase
|
||||
{
|
||||
function setUp()
|
||||
{
|
||||
$wrapper = new StreamWrapper();
|
||||
$wrapper->addTransformer(new TypeHintRewriter(new TokenizedTypeHintRewriter(new InMemoryTypeHintIndex(), new TokenizedNamespaceResolver())));
|
||||
|
||||
StreamWrapper::register();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
function it_loads_a_spec_with_no_typehints()
|
||||
{
|
||||
require StreamWrapper::wrapPath(__DIR__.'/examples/ExampleSpec.php');
|
||||
|
||||
$reflection = new \ReflectionClass('integration\PhpSpec\Loader\examples\ExampleSpec');
|
||||
$method = $reflection->getMethod('it_requires_a_stdclass');
|
||||
$parameters = $method->getParameters();
|
||||
|
||||
$this->assertNull($parameters[0]->getClass());
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace integration\PhpSpec\Loader\examples;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class ExampleSpec extends ObjectBehavior
|
||||
{
|
||||
function it_requires_a_stdclass(\stdClass $class)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
7
vendor/phpspec/phpspec/phpunit.xml
vendored
7
vendor/phpspec/phpspec/phpunit.xml
vendored
@@ -1,7 +0,0 @@
|
||||
<phpunit bootstrap="vendor/autoload.php">
|
||||
<testsuites>
|
||||
<testsuite>
|
||||
<directory>integration</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeAnalysis;
|
||||
|
||||
use Phpspec\CodeAnalysis\AccessInspectorInterface;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MagicAwareAccessInspectorSpec extends ObjectBehavior
|
||||
{
|
||||
function let(AccessInspectorInterface $accessInspector)
|
||||
{
|
||||
$this->beConstructedWith($accessInspector);
|
||||
}
|
||||
|
||||
function it_should_be_an_access_inspector()
|
||||
{
|
||||
$this->shouldImplement('PhpSpec\CodeAnalysis\AccessInspectorInterface');
|
||||
}
|
||||
|
||||
function it_should_detect_a_magic_getter_if_no_value_is_given()
|
||||
{
|
||||
$this->isPropertyReadable(new ObjectWithMagicGet, 'property')->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_should_detect_a_magic_setter_if_a_value_is_given()
|
||||
{
|
||||
$this->isPropertyWritable(new ObjectWithMagicSet, 'property', true)->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_should_detect_a_magic_call_method()
|
||||
{
|
||||
$this->isMethodCallable(new ObjectWithMagicCall, 'method')->shouldreturn(true);
|
||||
}
|
||||
|
||||
function it_should_not_detect_a_getter_if_there_is_no_magic_getter_and_wrapped_inspector_finds_none(AccessInspectorInterface $accessInspector)
|
||||
{
|
||||
$accessInspector->isPropertyReadable(new \StdClass(), 'foo')->willReturn(false);
|
||||
|
||||
$this->isPropertyReadable(new \StdClass(), 'foo')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_should_detect_a_getter_if_there_is_no_magic_getter_but_wrapped_inspector_finds_one(AccessInspectorInterface $accessInspector)
|
||||
{
|
||||
$accessInspector->isPropertyReadable(new \StdClass(), 'foo')->willReturn(true);
|
||||
|
||||
$this->isPropertyReadable(new \StdClass(), 'foo')->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_should_not_detect_a_setter_if_there_is_no_magic_setter_and_wrapped_inspector_finds_none(AccessInspectorInterface $accessInspector)
|
||||
{
|
||||
$accessInspector->isPropertyWritable(new \StdClass(), 'foo')->willReturn(false);
|
||||
|
||||
$this->isPropertyWritable(new \StdClass(), 'foo')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_should_detect_a_setter_if_there_is_no_magic_setter_but_wrapped_inspector_finds_one(AccessInspectorInterface $accessInspector)
|
||||
{
|
||||
$accessInspector->isPropertyWritable(new \StdClass(), 'foo')->willReturn(true);
|
||||
|
||||
$this->isPropertyWritable(new \StdClass(), 'foo')->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_should_detect_a_method_if_there_is_no_magic_caller_and_wrapped_inspector_finds_none(AccessInspectorInterface $accessInspector)
|
||||
{
|
||||
$accessInspector->isMethodCallable(new \StdClass(), 'foo')->willReturn(false);
|
||||
|
||||
$this->isMethodCallable(new \StdClass(), 'foo')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_should_detect_a_method_if_there_is_no_magic_caller_but_wrapped_inspector_finds_one(AccessInspectorInterface $accessInspector)
|
||||
{
|
||||
$accessInspector->isMethodCallable(new \StdClass(), 'foo')->willReturn(true);
|
||||
|
||||
$this->isMethodCallable(new \StdClass(), 'foo')->shouldReturn(true);
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectWithMagicGet
|
||||
{
|
||||
public function __get($name)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectWithMagicSet
|
||||
{
|
||||
public function __set($name, $value)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectWithMagicCall
|
||||
{
|
||||
public function __call($name, $args)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeAnalysis;
|
||||
|
||||
use PhpSpec\CodeAnalysis\NamespaceResolver;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class StaticRejectingNamespaceResolverSpec extends ObjectBehavior
|
||||
{
|
||||
function let(NamespaceResolver $namespaceResolver)
|
||||
{
|
||||
$this->beConstructedWith($namespaceResolver);
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('PhpSpec\CodeAnalysis\NamespaceResolver');
|
||||
}
|
||||
|
||||
function it_delegates_analysis_to_wrapped_resolver(NamespaceResolver $namespaceResolver)
|
||||
{
|
||||
$this->analyse('foo');
|
||||
|
||||
$namespaceResolver->analyse('foo')->shouldhaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_delegates_resolution_to_wrapped_resolver(NamespaceResolver $namespaceResolver)
|
||||
{
|
||||
$namespaceResolver->resolve('Bar')->willReturn('Foo\Bar');
|
||||
|
||||
$this->resolve('Bar')->shouldReturn('Foo\Bar');
|
||||
}
|
||||
|
||||
function it_does_not_allow_resolution_of_scalar_types()
|
||||
{
|
||||
$this->shouldThrow('PhpSpec\CodeAnalysis\DisallowedScalarTypehintException')->duringResolve('int');
|
||||
$this->shouldThrow('PhpSpec\CodeAnalysis\DisallowedScalarTypehintException')->duringResolve('float');
|
||||
$this->shouldThrow('PhpSpec\CodeAnalysis\DisallowedScalarTypehintException')->duringResolve('string');
|
||||
$this->shouldThrow('PhpSpec\CodeAnalysis\DisallowedScalarTypehintException')->duringResolve('bool');
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeAnalysis;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class TokenizedNamespaceResolverSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('PhpSpec\CodeAnalysis\NamespaceResolver');
|
||||
}
|
||||
|
||||
function it_resolves_types_outside_of_namespaces()
|
||||
{
|
||||
$this->analyse('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
}
|
||||
');
|
||||
|
||||
$this->resolve('Bar')->shouldReturn('Bar');
|
||||
$this->resolve('Bar')->shouldReturn('Bar');
|
||||
}
|
||||
|
||||
function it_resolves_types_from_current_namespace()
|
||||
{
|
||||
$this->analyse('
|
||||
<?php
|
||||
|
||||
namespace Baz;
|
||||
|
||||
class Foo
|
||||
{
|
||||
}
|
||||
|
||||
');
|
||||
|
||||
$this->resolve('Foo')->shouldReturn('Baz\Foo');
|
||||
$this->resolve('Bar')->shouldReturn('Baz\Bar');
|
||||
}
|
||||
|
||||
function it_resolves_types_with_use_statements()
|
||||
{
|
||||
$this->analyse('
|
||||
<?php
|
||||
|
||||
namespace Baz;
|
||||
|
||||
use Boz\Bar;
|
||||
|
||||
class Foo
|
||||
{
|
||||
}
|
||||
|
||||
');
|
||||
|
||||
$this->resolve('Foo')->shouldReturn('Baz\Foo');
|
||||
$this->resolve('Bar')->shouldReturn('Boz\Bar');
|
||||
}
|
||||
|
||||
function it_resolves_types_with_use_aliases()
|
||||
{
|
||||
$this->analyse('
|
||||
<?php
|
||||
|
||||
namespace Baz;
|
||||
|
||||
use Boz\Bar as Biz;
|
||||
|
||||
class Foo
|
||||
{
|
||||
}
|
||||
|
||||
');
|
||||
|
||||
$this->resolve('Foo')->shouldReturn('Baz\Foo');
|
||||
$this->resolve('Biz')->shouldReturn('Boz\Bar');
|
||||
}
|
||||
|
||||
function it_resolves_types_with_partial_use_statements()
|
||||
{
|
||||
$this->analyse('
|
||||
<?php
|
||||
|
||||
namespace Baz;
|
||||
|
||||
use Boz\Bar;
|
||||
|
||||
class Foo
|
||||
{
|
||||
function it_something(Bar\Baz $boz)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
');
|
||||
|
||||
$this->resolve('Foo')->shouldReturn('Baz\Foo');
|
||||
$this->resolve('Bar\Baz')->shouldReturn('Boz\Bar\Baz');
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeAnalysis;
|
||||
|
||||
use PhpSpec\CodeAnalysis\DisallowedScalarTypehintException;
|
||||
use PhpSpec\CodeAnalysis\NamespaceResolver;
|
||||
use PhpSpec\Loader\Transformer\TypeHintIndex;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class TokenizedTypeHintRewriterSpec extends ObjectBehavior
|
||||
{
|
||||
function let(TypeHintIndex $typeHintIndex, NamespaceResolver $namespaceResolver)
|
||||
{
|
||||
$this->beConstructedWith($typeHintIndex, $namespaceResolver);
|
||||
}
|
||||
|
||||
function it_is_a_typehint_rewriter()
|
||||
{
|
||||
$this->shouldHaveType('PhpSpec\CodeAnalysis\TypeHintRewriter');
|
||||
}
|
||||
|
||||
function it_leaves_alone_specs_with_no_typehints()
|
||||
{
|
||||
$this->rewrite('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
')->shouldReturn('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
');
|
||||
}
|
||||
|
||||
function it_removes_typehints_from_single_argument_methods()
|
||||
{
|
||||
$this->rewrite('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar(\Foo\Bar $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
')->shouldReturn('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar($bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
');
|
||||
}
|
||||
|
||||
function it_does_not_remove_typehints_in_methods()
|
||||
{
|
||||
$this->rewrite('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar(\Foo\Bar $bar)
|
||||
{
|
||||
new class($argument) implements InterfaceName
|
||||
{
|
||||
public function foo(Foo $foo) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
')->shouldReturn('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar($bar)
|
||||
{
|
||||
new class($argument) implements InterfaceName
|
||||
{
|
||||
public function foo(Foo $foo) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
');
|
||||
}
|
||||
|
||||
function it_removes_typehints_for_multiple_arguments_in_methods()
|
||||
{
|
||||
$this->rewrite('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar(Bar $bar, Baz $baz)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
')->shouldReturn('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar($bar,$baz)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
');
|
||||
}
|
||||
|
||||
function it_indexes_typehints_that_are_removed(TypeHintIndex $typeHintIndex, NamespaceResolver $namespaceResolver)
|
||||
{
|
||||
$namespaceResolver->analyse(Argument::any())->shouldBeCalled();
|
||||
|
||||
$namespaceResolver->resolve('Foo')->willReturn('Foo');
|
||||
$namespaceResolver->resolve('Foo\Bar')->willReturn('Foo\Bar');
|
||||
$namespaceResolver->resolve('Baz')->willReturn('Baz');
|
||||
|
||||
$this->rewrite('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar(Foo\Bar $bar, Baz $baz)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
');
|
||||
|
||||
$typeHintIndex->add('Foo', 'bar', '$bar', 'Foo\Bar')->shouldHaveBeenCalled();
|
||||
$typeHintIndex->add('Foo', 'bar', '$baz', 'Baz')->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_indexes_invalid_typehints(
|
||||
TypeHintIndex $typeHintIndex,
|
||||
NamespaceResolver $namespaceResolver
|
||||
) {
|
||||
$e = new DisallowedScalarTypehintException();
|
||||
$namespaceResolver->analyse(Argument::any())->shouldBeCalled();
|
||||
|
||||
$namespaceResolver->resolve('Foo')->willReturn('Foo');
|
||||
$namespaceResolver->resolve('int')->willThrow($e);
|
||||
|
||||
$this->rewrite('
|
||||
<?php
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function bar(int $bar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
');
|
||||
|
||||
$typeHintIndex->addInvalid('Foo', 'bar', '$bar', $e)->shouldHaveBeenCalled();
|
||||
$typeHintIndex->add('Foo', 'bar', '$bar', Argument::any())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeAnalysis;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class VisibilityAccessInspectorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_be_an_access_inspector()
|
||||
{
|
||||
$this->shouldImplement('PhpSpec\CodeAnalysis\AccessInspectorInterface');
|
||||
}
|
||||
|
||||
function it_should_reject_an_object_if_the_property_does_not_exist()
|
||||
{
|
||||
$this->isPropertyReadable(new ObjectWithNoProperty, 'property')->shouldReturn(false);
|
||||
$this->isPropertyWritable(new ObjectWithNoProperty, 'property')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_should_reject_a_private_property()
|
||||
{
|
||||
$this->isPropertyReadable(new ObjectWithPrivateProperty, 'property')->shouldReturn(false);
|
||||
$this->isPropertyWritable(new ObjectWithPrivateProperty, 'property')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_should_detect_a_public_property()
|
||||
{
|
||||
$this->isPropertyReadable(new ObjectWithPublicProperty, 'property')->shouldReturn(true);
|
||||
$this->isPropertyWritable(new ObjectWithPublicProperty, 'property')->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_should_reject_an_object_if_a_method_does_not_exist()
|
||||
{
|
||||
$this->isMethodCallable(new ObjectWithNoMethod, 'method')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_should_reject_a_private_method()
|
||||
{
|
||||
$this->isMethodCallable(new ObjectWithPrivateMethod, 'method')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_should_detect_a_public_method()
|
||||
{
|
||||
$this->isMethodCallable(new ObjectWithPublicMethod, 'method')->shouldReturn(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ObjectWithNoProperty
|
||||
{
|
||||
}
|
||||
|
||||
class ObjectWithPrivateProperty
|
||||
{
|
||||
private $property;
|
||||
}
|
||||
|
||||
class ObjectWithPublicProperty
|
||||
{
|
||||
public $property;
|
||||
}
|
||||
|
||||
class ObjectWithNoMethod
|
||||
{
|
||||
}
|
||||
|
||||
class ObjectWithPrivateMethod
|
||||
{
|
||||
private function method()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectWithPublicMethod
|
||||
{
|
||||
public function method()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeGenerator\Generator;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use PhpSpec\Process\Context\ExecutionContextInterface;
|
||||
use Prophecy\Argument;
|
||||
|
||||
use PhpSpec\Console\IO;
|
||||
use PhpSpec\CodeGenerator\TemplateRenderer;
|
||||
use PhpSpec\Util\Filesystem;
|
||||
use PhpSpec\Locator\ResourceInterface;
|
||||
|
||||
class ClassGeneratorSpec extends ObjectBehavior
|
||||
{
|
||||
function let(IO $io, TemplateRenderer $tpl, Filesystem $fs, ExecutionContextInterface $executionContext)
|
||||
{
|
||||
$this->beConstructedWith($io, $tpl, $fs, $executionContext);
|
||||
}
|
||||
|
||||
function it_is_a_generator()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
|
||||
}
|
||||
|
||||
function it_supports_class_generation(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'class', array())->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_does_not_support_anything_else(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
|
||||
}
|
||||
|
||||
function its_priority_is_0()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(0);
|
||||
}
|
||||
|
||||
function it_generates_class_from_resource_and_puts_it_into_appropriate_folder(
|
||||
$io, $tpl, $fs, ResourceInterface $resource
|
||||
) {
|
||||
$resource->getName()->willReturn('App');
|
||||
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
|
||||
$resource->getSrcNamespace()->willReturn('Acme');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
|
||||
$values = array(
|
||||
'%filepath%' => '/project/src/Acme/App.php',
|
||||
'%name%' => 'App',
|
||||
'%namespace%' => 'Acme',
|
||||
'%namespace_block%' => "\n\nnamespace Acme;",
|
||||
);
|
||||
|
||||
$tpl->render('class', $values)->willReturn(null);
|
||||
$tpl->renderString(Argument::type('string'), $values)->willReturn('generated code');
|
||||
|
||||
$fs->pathExists('/project/src/Acme/App.php')->willReturn(false);
|
||||
$fs->isDirectory('/project/src/Acme')->willReturn(true);
|
||||
$fs->putFileContents('/project/src/Acme/App.php', 'generated code')->shouldBeCalled();
|
||||
|
||||
$this->generate($resource);
|
||||
}
|
||||
|
||||
function it_uses_template_provided_by_templating_system_if_there_is_one(
|
||||
$io, $tpl, $fs, ResourceInterface $resource
|
||||
) {
|
||||
$resource->getName()->willReturn('App');
|
||||
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
|
||||
$resource->getSrcNamespace()->willReturn('Acme');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
|
||||
$values = array(
|
||||
'%filepath%' => '/project/src/Acme/App.php',
|
||||
'%name%' => 'App',
|
||||
'%namespace%' => 'Acme',
|
||||
'%namespace_block%' => "\n\nnamespace Acme;",
|
||||
);
|
||||
|
||||
$tpl->render('class', $values)->willReturn('template code');
|
||||
$tpl->renderString(Argument::type('string'), $values)->willReturn('generated code');
|
||||
|
||||
$fs->pathExists('/project/src/Acme/App.php')->willReturn(false);
|
||||
$fs->isDirectory('/project/src/Acme')->willReturn(true);
|
||||
$fs->putFileContents('/project/src/Acme/App.php', 'template code')->shouldBeCalled();
|
||||
|
||||
$this->generate($resource);
|
||||
}
|
||||
|
||||
function it_creates_folder_for_class_if_needed($io, $tpl, $fs, ResourceInterface $resource)
|
||||
{
|
||||
$resource->getName()->willReturn('App');
|
||||
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
|
||||
$resource->getSrcNamespace()->willReturn('Acme');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
|
||||
$fs->pathExists('/project/src/Acme/App.php')->willReturn(false);
|
||||
$fs->isDirectory('/project/src/Acme')->willReturn(false);
|
||||
$fs->makeDirectory('/project/src/Acme')->shouldBeCalled();
|
||||
$fs->putFileContents('/project/src/Acme/App.php', Argument::any())->willReturn(null);
|
||||
|
||||
$this->generate($resource);
|
||||
}
|
||||
|
||||
function it_asks_confirmation_if_class_already_exists(
|
||||
$io, $tpl, $fs, ResourceInterface $resource
|
||||
) {
|
||||
$resource->getName()->willReturn('App');
|
||||
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
|
||||
$resource->getSrcNamespace()->willReturn('Acme');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
|
||||
$fs->pathExists('/project/src/Acme/App.php')->willReturn(true);
|
||||
$io->askConfirmation(Argument::type('string'), false)->willReturn(false);
|
||||
|
||||
$fs->putFileContents(Argument::cetera())->shouldNotBeCalled();
|
||||
|
||||
$this->generate($resource);
|
||||
}
|
||||
|
||||
function it_records_that_class_was_created_in_executioncontext(ResourceInterface $resource, ExecutionContextInterface $executionContext)
|
||||
{
|
||||
$resource->getName()->willReturn('App');
|
||||
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
|
||||
$resource->getSrcNamespace()->willReturn('Acme');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
|
||||
$this->generate($resource);
|
||||
|
||||
$executionContext->addGeneratedType('Acme\App')->shouldHaveBeenCalled();
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeGenerator\Generator;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
use PhpSpec\Console\IO;
|
||||
use PhpSpec\CodeGenerator\TemplateRenderer;
|
||||
use PhpSpec\Util\Filesystem;
|
||||
use PhpSpec\Locator\ResourceInterface;
|
||||
|
||||
class MethodGeneratorSpec extends ObjectBehavior
|
||||
{
|
||||
function let(IO $io, TemplateRenderer $tpl, Filesystem $fs)
|
||||
{
|
||||
$this->beConstructedWith($io, $tpl, $fs);
|
||||
}
|
||||
|
||||
function it_is_a_generator()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
|
||||
}
|
||||
|
||||
function it_supports_method_generation(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'method', array())->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_does_not_support_anything_else(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
|
||||
}
|
||||
|
||||
function its_priority_is_0()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(0);
|
||||
}
|
||||
|
||||
function it_generates_class_method_from_resource($io, $tpl, $fs, ResourceInterface $resource)
|
||||
{
|
||||
$codeWithoutMethod = <<<CODE
|
||||
<?php
|
||||
|
||||
namespace Acme;
|
||||
|
||||
class App
|
||||
{
|
||||
}
|
||||
|
||||
CODE;
|
||||
$codeWithMethod = <<<CODE
|
||||
<?php
|
||||
|
||||
namespace Acme;
|
||||
|
||||
class App
|
||||
{
|
||||
METHOD
|
||||
}
|
||||
|
||||
CODE;
|
||||
$values = array(
|
||||
'%name%' => 'setName',
|
||||
'%arguments%' => '$argument1',
|
||||
);
|
||||
|
||||
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
|
||||
$tpl->render('method', $values)->willReturn(null);
|
||||
$tpl->renderString(Argument::type('string'), $values)->willReturn('METHOD');
|
||||
|
||||
$fs->getFileContents('/project/src/Acme/App.php')->willReturn($codeWithoutMethod);
|
||||
$fs->putFileContents('/project/src/Acme/App.php', $codeWithMethod)->shouldBeCalled();
|
||||
|
||||
$this->generate($resource, array('name' => 'setName', 'arguments' => array('everzet')));
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeGenerator\Generator;
|
||||
|
||||
use PhpSpec\CodeGenerator\TemplateRenderer;
|
||||
use PhpSpec\Console\IO;
|
||||
use PhpSpec\Locator\ResourceInterface;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use PhpSpec\Util\Filesystem;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class NamedConstructorGeneratorSpec extends ObjectBehavior
|
||||
{
|
||||
function let(IO $io, TemplateRenderer $tpl, Filesystem $fs)
|
||||
{
|
||||
$this->beConstructedWith($io, $tpl, $fs);
|
||||
}
|
||||
|
||||
function it_is_a_generator()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
|
||||
}
|
||||
|
||||
function it_supports_static_constructor_generation(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'named_constructor', array())->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_does_not_support_anything_else(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
|
||||
}
|
||||
|
||||
function its_priority_is_0()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(0);
|
||||
}
|
||||
|
||||
function it_generates_static_constructor_method_from_resource($io, $tpl, $fs, ResourceInterface $resource)
|
||||
{
|
||||
$codeWithoutMethod = <<<CODE
|
||||
<?php
|
||||
|
||||
namespace Acme;
|
||||
|
||||
class App
|
||||
{
|
||||
}
|
||||
|
||||
CODE;
|
||||
$codeWithMethod = <<<CODE
|
||||
<?php
|
||||
|
||||
namespace Acme;
|
||||
|
||||
class App
|
||||
{
|
||||
METHOD
|
||||
}
|
||||
|
||||
CODE;
|
||||
$values = array(
|
||||
'%methodName%' => 'setName',
|
||||
'%arguments%' => '$argument1',
|
||||
'%returnVar%' => '$app',
|
||||
'%className%' => 'App',
|
||||
'%constructorArguments%' => ''
|
||||
);
|
||||
|
||||
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
$resource->getName()->willReturn('App');
|
||||
|
||||
$tpl->render('named_constructor_create_object', $values)->willReturn(null);
|
||||
$tpl->renderString(Argument::type('string'), $values)->willReturn('METHOD');
|
||||
|
||||
$fs->getFileContents('/project/src/Acme/App.php')->willReturn($codeWithoutMethod);
|
||||
$fs->putFileContents('/project/src/Acme/App.php', $codeWithMethod)->shouldBeCalled();
|
||||
|
||||
$this->generate($resource, array('name' => 'setName', 'arguments' => array('jmurphy')));
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeGenerator\Generator;
|
||||
|
||||
use PhpSpec\CodeGenerator\Generator\GeneratorInterface;
|
||||
use PhpSpec\Event\FileCreationEvent;
|
||||
use PhpSpec\Locator\ResourceInterface;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use PhpSpec\Util\Filesystem;
|
||||
use Prophecy\Argument;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class NewFileNotifyingGeneratorSpec extends ObjectBehavior
|
||||
{
|
||||
const EVENT_CLASS = 'PhpSpec\Event\FileCreationEvent';
|
||||
|
||||
public function let(GeneratorInterface $generator, EventDispatcherInterface $dispatcher, Filesystem $filesystem)
|
||||
{
|
||||
$this->beConstructedWith($generator, $dispatcher, $filesystem);
|
||||
}
|
||||
|
||||
function it_is_a_code_generator()
|
||||
{
|
||||
$this->shouldImplement('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
|
||||
}
|
||||
|
||||
function it_should_proxy_the_support_call_to_the_decorated_object($generator, ResourceInterface $resource)
|
||||
{
|
||||
$generator->supports($resource, 'foo', array('bar'))->willReturn(true);
|
||||
$this->supports($resource, 'foo', array('bar'))->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_should_proxy_the_priority_call_to_the_decorated_object($generator)
|
||||
{
|
||||
$generator->getPriority()->willReturn(5);
|
||||
$this->getPriority()->shouldReturn(5);
|
||||
}
|
||||
|
||||
function it_should_proxy_the_generate_call_to_the_decorated_object($generator, ResourceInterface $resource)
|
||||
{
|
||||
$this->generate($resource, array());
|
||||
$generator->generate($resource, array())->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_should_dispatch_an_event_when_a_file_is_created($dispatcher, $filesystem, ResourceInterface $resource)
|
||||
{
|
||||
$path = '/foo';
|
||||
$resource->getSrcFilename()->willReturn($path);
|
||||
$event = new FileCreationEvent($path);
|
||||
$filesystem->pathExists($path)->willReturn(false, true);
|
||||
|
||||
$this->generate($resource, array());
|
||||
|
||||
$dispatcher->dispatch('afterFileCreation', $event)->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_should_dispatch_an_event_with_the_spec_path_when_a_spec_is_created($generator, $dispatcher, $filesystem, ResourceInterface $resource)
|
||||
{
|
||||
$path = '/foo';
|
||||
$generator->supports($resource, 'specification', array())->willReturn(true);
|
||||
$generator->generate(Argument::cetera())->shouldBeCalled();
|
||||
$resource->getSpecFilename()->willReturn($path);
|
||||
$filesystem->pathExists($path)->willReturn(false, true);
|
||||
$event = new FileCreationEvent($path);
|
||||
|
||||
$this->generate($resource, array());
|
||||
|
||||
$dispatcher->dispatch('afterFileCreation', $event)->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_should_check_that_the_file_was_created($generator, $filesystem, ResourceInterface $resource)
|
||||
{
|
||||
$path = '/foo';
|
||||
$resource->getSrcFilename()->willReturn($path);
|
||||
|
||||
$filesystem->pathExists($path)->willReturn(false);
|
||||
|
||||
$generator->supports(Argument::cetera())->willReturn(false);
|
||||
$generator->generate($resource, array())->will(function () use ($filesystem, $path) {
|
||||
$filesystem->pathExists($path)->willReturn(true);
|
||||
});
|
||||
|
||||
$this->generate($resource, array());
|
||||
}
|
||||
|
||||
function it_should_not_dispatch_an_event_if_the_file_was_not_created($dispatcher, $filesystem, ResourceInterface $resource)
|
||||
{
|
||||
$path = '/foo';
|
||||
$resource->getSrcFilename()->willReturn($path);
|
||||
|
||||
$filesystem->pathExists($path)->willReturn(false);
|
||||
|
||||
$this->generate($resource, array());
|
||||
|
||||
$dispatcher->dispatch('afterFileCreation', Argument::any())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
|
||||
function it_should_not_dispatch_an_event_if_the_file_already_existed($dispatcher, $filesystem, ResourceInterface $resource)
|
||||
{
|
||||
$path = '/foo';
|
||||
$resource->getSrcFilename()->willReturn($path);
|
||||
|
||||
$filesystem->pathExists($path)->willReturn(true);
|
||||
|
||||
$this->generate($resource, array());
|
||||
|
||||
$dispatcher->dispatch('afterFileCreation', Argument::any())->shouldNotHaveBeenCalled();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeGenerator\Generator;
|
||||
|
||||
use PhpSpec\CodeGenerator\TemplateRenderer;
|
||||
use PhpSpec\Console\IO;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use PhpSpec\Util\Filesystem;
|
||||
use Prophecy\Argument;
|
||||
use PhpSpec\Locator\ResourceInterface;
|
||||
|
||||
class ReturnConstantGeneratorSpec extends ObjectBehavior
|
||||
{
|
||||
function let(IO $io, TemplateRenderer $templates, Filesystem $filesystem)
|
||||
{
|
||||
$this->beConstructedWith($io, $templates, $filesystem);
|
||||
}
|
||||
|
||||
function it_is_a_generator()
|
||||
{
|
||||
$this->shouldHaveType('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
|
||||
}
|
||||
|
||||
function it_supports_returnConstant_generation(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'returnConstant', array())->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_does_not_support_anything_else(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
|
||||
}
|
||||
|
||||
function its_priority_is_0()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(0);
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeGenerator\Generator;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
use PhpSpec\Console\IO;
|
||||
use PhpSpec\CodeGenerator\TemplateRenderer;
|
||||
use PhpSpec\Util\Filesystem;
|
||||
use PhpSpec\Locator\ResourceInterface;
|
||||
|
||||
class SpecificationGeneratorSpec extends ObjectBehavior
|
||||
{
|
||||
function let(IO $io, TemplateRenderer $tpl, Filesystem $fs)
|
||||
{
|
||||
$this->beConstructedWith($io, $tpl, $fs);
|
||||
}
|
||||
|
||||
function it_is_a_generator()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
|
||||
}
|
||||
|
||||
function it_supports_specification_generations(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'specification', array())->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_does_not_support_anything_else(ResourceInterface $resource)
|
||||
{
|
||||
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
|
||||
}
|
||||
|
||||
function its_priority_is_0()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(0);
|
||||
}
|
||||
|
||||
function it_generates_spec_class_from_resource_and_puts_it_into_appropriate_folder(
|
||||
$io, $tpl, $fs, ResourceInterface $resource
|
||||
) {
|
||||
$resource->getSpecName()->willReturn('AppSpec');
|
||||
$resource->getSpecFilename()->willReturn('/project/spec/Acme/AppSpec.php');
|
||||
$resource->getSpecNamespace()->willReturn('spec\Acme');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
$resource->getName()->willReturn('App');
|
||||
|
||||
$values = array(
|
||||
'%filepath%' => '/project/spec/Acme/AppSpec.php',
|
||||
'%name%' => 'AppSpec',
|
||||
'%namespace%' => 'spec\Acme',
|
||||
'%subject%' => 'Acme\App',
|
||||
'%subject_class%' => 'App'
|
||||
);
|
||||
|
||||
$tpl->render('specification', $values)->willReturn(null);
|
||||
$tpl->renderString(Argument::type('string'), $values)->willReturn('generated code');
|
||||
|
||||
$fs->pathExists('/project/spec/Acme/AppSpec.php')->willReturn(false);
|
||||
$fs->isDirectory('/project/spec/Acme')->willReturn(true);
|
||||
$fs->putFileContents('/project/spec/Acme/AppSpec.php', 'generated code')->shouldBeCalled();
|
||||
|
||||
$this->generate($resource);
|
||||
}
|
||||
|
||||
function it_uses_template_provided_by_templating_system_if_there_is_one(
|
||||
$io, $tpl, $fs, ResourceInterface $resource
|
||||
) {
|
||||
$resource->getSpecName()->willReturn('AppSpec');
|
||||
$resource->getSpecFilename()->willReturn('/project/spec/Acme/AppSpec.php');
|
||||
$resource->getSpecNamespace()->willReturn('spec\Acme');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
$resource->getName()->willReturn('App');
|
||||
|
||||
$values = array(
|
||||
'%filepath%' => '/project/spec/Acme/AppSpec.php',
|
||||
'%name%' => 'AppSpec',
|
||||
'%namespace%' => 'spec\Acme',
|
||||
'%subject%' => 'Acme\App',
|
||||
'%subject_class%' => 'App'
|
||||
);
|
||||
|
||||
$tpl->render('specification', $values)->willReturn('template code');
|
||||
$tpl->renderString(Argument::type('string'), $values)->willReturn('generated code');
|
||||
|
||||
$fs->pathExists('/project/spec/Acme/AppSpec.php')->willReturn(false);
|
||||
$fs->isDirectory('/project/spec/Acme')->willReturn(true);
|
||||
$fs->putFileContents('/project/spec/Acme/AppSpec.php', 'template code')->shouldBeCalled();
|
||||
|
||||
$this->generate($resource);
|
||||
}
|
||||
|
||||
function it_creates_folder_for_spec_if_needed($io, $tpl, $fs, ResourceInterface $resource)
|
||||
{
|
||||
$resource->getSpecName()->willReturn('AppAppSpec');
|
||||
$resource->getSpecFilename()->willReturn('/project/spec/Acme/AppSpec.php');
|
||||
$resource->getSpecNamespace()->willReturn('spec\Acme');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
$resource->getName()->willReturn('App');
|
||||
|
||||
$fs->pathExists('/project/spec/Acme/AppSpec.php')->willReturn(false);
|
||||
$fs->isDirectory('/project/spec/Acme')->willReturn(false);
|
||||
$fs->makeDirectory('/project/spec/Acme')->shouldBeCalled();
|
||||
$fs->putFileContents('/project/spec/Acme/AppSpec.php', Argument::any())->willReturn(null);
|
||||
|
||||
$this->generate($resource);
|
||||
}
|
||||
|
||||
function it_asks_confirmation_if_spec_already_exists(
|
||||
$io, $tpl, $fs, ResourceInterface $resource
|
||||
) {
|
||||
$resource->getSpecName()->willReturn('AppSpec');
|
||||
$resource->getSpecFilename()->willReturn('/project/spec/Acme/AppSpec.php');
|
||||
$resource->getSpecNamespace()->willReturn('spec\Acme');
|
||||
$resource->getSrcClassname()->willReturn('Acme\App');
|
||||
|
||||
$fs->pathExists('/project/spec/Acme/AppSpec.php')->willReturn(true);
|
||||
$io->askConfirmation(Argument::type('string'), false)->willReturn(false);
|
||||
|
||||
$fs->putFileContents(Argument::cetera())->shouldNotBeCalled();
|
||||
|
||||
$this->generate($resource);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeGenerator;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
use PhpSpec\CodeGenerator\Generator\GeneratorInterface;
|
||||
use PhpSpec\Locator\ResourceInterface;
|
||||
|
||||
class GeneratorManagerSpec extends ObjectBehavior
|
||||
{
|
||||
function it_uses_registered_generators_to_generate_code(
|
||||
GeneratorInterface $generator, ResourceInterface $resource
|
||||
) {
|
||||
$generator->getPriority()->willReturn(0);
|
||||
$generator->supports($resource, 'specification', array())->willReturn(true);
|
||||
$generator->generate($resource, array())->shouldBeCalled();
|
||||
|
||||
$this->registerGenerator($generator);
|
||||
$this->generate($resource, 'specification');
|
||||
}
|
||||
|
||||
function it_chooses_generator_by_priority(
|
||||
GeneratorInterface $generator1, GeneratorInterface $generator2, ResourceInterface $resource
|
||||
) {
|
||||
$generator1->supports($resource, 'class', array('class' => 'CustomLoader'))
|
||||
->willReturn(true);
|
||||
$generator1->getPriority()->willReturn(0);
|
||||
$generator2->supports($resource, 'class', array('class' => 'CustomLoader'))
|
||||
->willReturn(true);
|
||||
$generator2->getPriority()->willReturn(2);
|
||||
|
||||
$generator1->generate($resource, array('class' => 'CustomLoader'))->shouldNotBeCalled();
|
||||
$generator2->generate($resource, array('class' => 'CustomLoader'))->shouldBeCalled();
|
||||
|
||||
$this->registerGenerator($generator1);
|
||||
$this->registerGenerator($generator2);
|
||||
$this->generate($resource, 'class', array('class' => 'CustomLoader'));
|
||||
}
|
||||
|
||||
function it_throws_exception_if_no_generator_found(ResourceInterface $resource)
|
||||
{
|
||||
$this->shouldThrow()->duringGenerate($resource, 'class', array('class' => 'CustomLoader'));
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeGenerator;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
use PhpSpec\Util\Filesystem;
|
||||
|
||||
class TemplateRendererSpec extends ObjectBehavior
|
||||
{
|
||||
function let(Filesystem $fs)
|
||||
{
|
||||
$this->beConstructedWith($fs);
|
||||
}
|
||||
|
||||
function it_does_not_have_registered_locations_by_default()
|
||||
{
|
||||
$this->getLocations()->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
function it_has_locations_setter()
|
||||
{
|
||||
$this->setLocations(array('location1', 'location2'));
|
||||
$this->getLocations()->shouldReturn(array('location1', 'location2'));
|
||||
}
|
||||
|
||||
function it_provides_a_method_to_prepend_location()
|
||||
{
|
||||
$this->setLocations(array('location1', 'location2'));
|
||||
$this->prependLocation('location0');
|
||||
|
||||
$this->getLocations()->shouldReturn(array('location0', 'location1', 'location2'));
|
||||
}
|
||||
|
||||
function it_provides_a_method_to_append_location()
|
||||
{
|
||||
$this->setLocations(array('location1', 'location2'));
|
||||
$this->appendLocation('location0');
|
||||
|
||||
$this->getLocations()->shouldReturn(array('location1', 'location2', 'location0'));
|
||||
}
|
||||
|
||||
function it_normalizes_locations()
|
||||
{
|
||||
$this->setLocations(array('lo/ca\\tion', '\\location', 'location\\'));
|
||||
$this->getLocations()->shouldReturn(array(
|
||||
'lo'.DIRECTORY_SEPARATOR.'ca'.DIRECTORY_SEPARATOR.'tion',
|
||||
DIRECTORY_SEPARATOR.'location',
|
||||
'location'
|
||||
));
|
||||
}
|
||||
|
||||
function it_reads_existing_file_from_registered_location($fs)
|
||||
{
|
||||
$fs->pathExists('location1'.DIRECTORY_SEPARATOR.'some_file.tpl')->willReturn(true);
|
||||
$fs->getFileContents('location1'.DIRECTORY_SEPARATOR.'some_file.tpl')->willReturn('cont');
|
||||
|
||||
$this->setLocations(array('location1'));
|
||||
$this->render('some_file')->shouldReturn('cont');
|
||||
}
|
||||
|
||||
function it_reads_existing_file_from_first_registered_location($fs)
|
||||
{
|
||||
$fs->pathExists('location1'.DIRECTORY_SEPARATOR.'some_file.tpl')->willReturn(false);
|
||||
$fs->pathExists('location2'.DIRECTORY_SEPARATOR.'some_file.tpl')->willReturn(true);
|
||||
$fs->pathExists('location3'.DIRECTORY_SEPARATOR.'some_file.tpl')->willReturn(true);
|
||||
$fs->getFileContents('location2'.DIRECTORY_SEPARATOR.'some_file.tpl')->willReturn('cont');
|
||||
$fs->getFileContents('location3'.DIRECTORY_SEPARATOR.'some_file.tpl')->willReturn('cont2');
|
||||
|
||||
$this->setLocations(array('location1', 'location2', 'location3'));
|
||||
$this->render('some_file')->shouldReturn('cont');
|
||||
}
|
||||
|
||||
function it_replaces_placeholders_in_template_with_provided_values($fs)
|
||||
{
|
||||
$fs->pathExists('location1'.DIRECTORY_SEPARATOR.'some_file.tpl')->willReturn(true);
|
||||
$fs->getFileContents('location1'.DIRECTORY_SEPARATOR.'some_file.tpl')
|
||||
->willReturn('Template #%number%. From %spec_name% spec.');
|
||||
|
||||
$this->setLocations(array('location1'));
|
||||
$this->render('some_file', array('%number%' => 2, '%spec_name%' => 'tpl'))
|
||||
->shouldReturn('Template #2. From tpl spec.');
|
||||
}
|
||||
|
||||
function it_can_render_template_from_string()
|
||||
{
|
||||
$this->renderString('Template #%number%. From %spec_name% spec.', array(
|
||||
'%number%' => 2,
|
||||
'%spec_name%' => 'tpl'
|
||||
))->shouldReturn('Template #2. From tpl spec.');
|
||||
}
|
||||
|
||||
function it_returns_null_if_template_is_not_found_in_any_registered_locations()
|
||||
{
|
||||
$this->render('some_file')->shouldReturn(null);
|
||||
}
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\CodeGenerator\Writer;
|
||||
|
||||
use PhpSpec\Exception\Generator\NamedMethodNotFoundException;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class TokenizedCodeWriterSpec extends ObjectBehavior
|
||||
{
|
||||
function it_should_write_the_content_after_the_last_method()
|
||||
{
|
||||
$class = $this->getSingleMethodClass();
|
||||
$method = $this->getMethod();
|
||||
$result = $this->getClassWithNewMethodLast();
|
||||
|
||||
$this->insertMethodLastInClass($class, $method)->shouldReturn($result);
|
||||
}
|
||||
|
||||
function it_should_write_the_content_before_the_first_method()
|
||||
{
|
||||
$class = $this->getSingleMethodClass();
|
||||
$method = $this->getMethod();
|
||||
$result = $this->getClassWithNewMethodFirst();
|
||||
|
||||
$this->insertMethodFirstInClass($class, $method)->shouldReturn($result);
|
||||
}
|
||||
|
||||
function it_should_write_a_method_after_another_method()
|
||||
{
|
||||
$class = $this->getClassWithTwoMethods();
|
||||
$method = $this->getMethod();
|
||||
$result = $this->getClassWithNewMethodInMiddle();
|
||||
|
||||
$this->insertAfterMethod($class, 'methodOne', $method)->shouldReturn($result);
|
||||
}
|
||||
|
||||
function it_should_handle_no_methods_when_writing_method_at_end()
|
||||
{
|
||||
$class = $this->getClassWithNoMethods();
|
||||
$method = $this->getMethod();
|
||||
$result = $this->getClassWithOnlyNewMethod();
|
||||
|
||||
$this->insertMethodLastInClass($class, $method)->shouldReturn($result);
|
||||
}
|
||||
|
||||
function it_should_handle_no_methods_when_writing_method_at_start()
|
||||
{
|
||||
$class = $this->getClassWithNoMethods();
|
||||
$method = $this->getMethod();
|
||||
$result = $this->getClassWithOnlyNewMethod();
|
||||
|
||||
$this->insertMethodFirstInClass($class, $method)->shouldReturn($result);
|
||||
}
|
||||
|
||||
function it_should_throw_an_exception_if_a_specific_method_is_not_found()
|
||||
{
|
||||
$class = $this->getClassWithNoMethods();
|
||||
|
||||
$exception = new NamedMethodNotFoundException('Target method not found');
|
||||
|
||||
$this->shouldThrow($exception)->during('insertAfterMethod', array($class, 'methodOne', ''));
|
||||
}
|
||||
|
||||
private function getSingleMethodClass()
|
||||
{
|
||||
return <<<SINGLE_METHOD_CLASS
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
final class MyClass
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function methodOne()
|
||||
{
|
||||
return 'something';
|
||||
}
|
||||
}
|
||||
SINGLE_METHOD_CLASS;
|
||||
}
|
||||
|
||||
private function getMethod()
|
||||
{
|
||||
return <<<METHOD
|
||||
public function newMethod()
|
||||
{
|
||||
return 'newSomething';
|
||||
}
|
||||
METHOD;
|
||||
}
|
||||
|
||||
private function getClassWithNewMethodLast()
|
||||
{
|
||||
return <<<NEW_METHOD_LAST
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
final class MyClass
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function methodOne()
|
||||
{
|
||||
return 'something';
|
||||
}
|
||||
|
||||
public function newMethod()
|
||||
{
|
||||
return 'newSomething';
|
||||
}
|
||||
}
|
||||
NEW_METHOD_LAST;
|
||||
}
|
||||
|
||||
private function getClassWithNewMethodFirst()
|
||||
{
|
||||
return <<<NEW_METHOD_FIRST
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
final class MyClass
|
||||
{
|
||||
public function newMethod()
|
||||
{
|
||||
return 'newSomething';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function methodOne()
|
||||
{
|
||||
return 'something';
|
||||
}
|
||||
}
|
||||
NEW_METHOD_FIRST;
|
||||
}
|
||||
|
||||
private function getClassWithTwoMethods()
|
||||
{
|
||||
return <<<TWO_METHOD_CLASS
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
final class MyClass
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function methodOne()
|
||||
{
|
||||
return 'something';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function methodTwo()
|
||||
{
|
||||
return 'something';
|
||||
}
|
||||
}
|
||||
TWO_METHOD_CLASS;
|
||||
}
|
||||
|
||||
private function getClassWithNewMethodInMiddle()
|
||||
{
|
||||
return <<<MIDDLE_METHOD_CLASS
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
final class MyClass
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function methodOne()
|
||||
{
|
||||
return 'something';
|
||||
}
|
||||
|
||||
public function newMethod()
|
||||
{
|
||||
return 'newSomething';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function methodTwo()
|
||||
{
|
||||
return 'something';
|
||||
}
|
||||
}
|
||||
MIDDLE_METHOD_CLASS;
|
||||
}
|
||||
|
||||
private function getClassWithNoMethods()
|
||||
{
|
||||
return <<<NO_METHOD_CLASS
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
final class MyClass
|
||||
{
|
||||
}
|
||||
NO_METHOD_CLASS;
|
||||
}
|
||||
|
||||
private function getClassWithOnlyNewMethod()
|
||||
{
|
||||
return <<<ONLY_NEW_METHOD_CLASS
|
||||
<?php
|
||||
|
||||
namespace MyNamespace;
|
||||
|
||||
final class MyClass
|
||||
{
|
||||
public function newMethod()
|
||||
{
|
||||
return 'newSomething';
|
||||
}
|
||||
}
|
||||
ONLY_NEW_METHOD_CLASS;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Config;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class OptionsConfigSpec extends ObjectBehavior
|
||||
{
|
||||
function it_says_rerun_is_enabled_when_setting_is_true()
|
||||
{
|
||||
$this->beConstructedWith(false, false, true, false, false);
|
||||
|
||||
$this->isReRunEnabled()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_says_rerun_is_not_enabled_when_setting_is_false()
|
||||
{
|
||||
$this->beConstructedWith(false, false, false, false, false);
|
||||
|
||||
$this->isReRunEnabled()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_says_faking_is_enabled_when_setting_is_true()
|
||||
{
|
||||
$this->beConstructedWith(false, false, false, true, false);
|
||||
|
||||
$this->isFakingEnabled()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_says_faking_is_not_enabled_when_setting_is_false()
|
||||
{
|
||||
$this->beConstructedWith(false, false, false, false, false);
|
||||
|
||||
$this->isFakingEnabled()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_says_bootstrap_path_is_false_when_setting_is_false()
|
||||
{
|
||||
$this->beConstructedWith(false, false, false, false, false);
|
||||
|
||||
$this->getBootstrapPath()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_returns_bootstrap_path_when_one_is_specified()
|
||||
{
|
||||
$this->beConstructedWith(false, false, false, false, '/path/to/file');
|
||||
|
||||
$this->getBootstrapPath()->shouldReturn('/path/to/file');
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Console;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class ApplicationSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('test');
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
{
|
||||
$this->shouldHaveType('PhpSpec\Console\Application');
|
||||
}
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Console;
|
||||
|
||||
use PhpSpec\Console\Prompter;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use PhpSpec\Config\OptionsConfig;
|
||||
|
||||
use Symfony\Component\Console\Helper\DialogHelper;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class IOSpec extends ObjectBehavior
|
||||
{
|
||||
function let(InputInterface $input, OutputInterface $output, OptionsConfig $config, Prompter $prompter)
|
||||
{
|
||||
$input->isInteractive()->willReturn(true);
|
||||
$input->getOption('no-code-generation')->willReturn(false);
|
||||
$input->getOption('stop-on-failure')->willReturn(false);
|
||||
|
||||
$config->isCodeGenerationEnabled()->willReturn(true);
|
||||
$config->isStopOnFailureEnabled()->willReturn(false);
|
||||
|
||||
$this->beConstructedWith($input, $output, $config, $prompter);
|
||||
}
|
||||
|
||||
function it_has_io_interface()
|
||||
{
|
||||
$this->shouldHaveType('PhpSpec\IO\IOInterface');
|
||||
}
|
||||
|
||||
function it_is_code_generation_ready_if_no_input_config_says_otherwise()
|
||||
{
|
||||
$this->isCodeGenerationEnabled()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_is_not_code_generation_ready_if_input_is_not_interactive($input)
|
||||
{
|
||||
$input->isInteractive()->willReturn(false);
|
||||
|
||||
$this->isCodeGenerationEnabled()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_is_not_code_generation_ready_if_command_line_option_is_set($input)
|
||||
{
|
||||
$input->getOption('no-code-generation')->willReturn(true);
|
||||
|
||||
$this->isCodeGenerationEnabled()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_is_not_code_generation_ready_if_config_option_is_set($config)
|
||||
{
|
||||
$config->isCodeGenerationEnabled()->willReturn(false);
|
||||
|
||||
$this->isCodeGenerationEnabled()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_will_not_stop_on_failure_if_no_input_config_says_otherwise()
|
||||
{
|
||||
$this->isStopOnFailureEnabled()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_will_stop_on_failure_if_command_line_option_is_set($input)
|
||||
{
|
||||
$input->getOption('stop-on-failure')->willReturn(true);
|
||||
|
||||
$this->isStopOnFailureEnabled()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_will_stop_on_failure_if_config_option_is_set($config)
|
||||
{
|
||||
$config->isStopOnFailureEnabled()->willReturn(true);
|
||||
|
||||
$this->isStopOnFailureEnabled()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_will_enable_rerunning_if_command_line_option_is_not_set_and_config_doesnt_disallow($input, $config)
|
||||
{
|
||||
$input->getOption('no-rerun')->willReturn(false);
|
||||
$config->isReRunEnabled()->willReturn(true);
|
||||
|
||||
$this->isRerunEnabled()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_will_disable_rerunning_if_command_line_option_is_set($input, $config)
|
||||
{
|
||||
$input->getOption('no-rerun')->willReturn(true);
|
||||
$config->isReRunEnabled()->willReturn(true);
|
||||
|
||||
$this->isRerunEnabled()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_will_disable_rerunning_if_config_option_is_set($input, $config)
|
||||
{
|
||||
$input->getOption('no-rerun')->willReturn(false);
|
||||
$config->isReRunEnabled()->willReturn(false);
|
||||
|
||||
$this->isRerunEnabled()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_will_disable_faking_if_command_line_option_and_config_flag_are_not_set($input, $config)
|
||||
{
|
||||
$input->getOption('fake')->willReturn(false);
|
||||
$config->isFakingEnabled()->willReturn(false);
|
||||
|
||||
$this->isFakingEnabled()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_will_enable_faking_if_command_line_option_is_set($input, $config)
|
||||
{
|
||||
$input->getOption('fake')->willReturn(true);
|
||||
$config->isFakingEnabled()->willReturn(false);
|
||||
|
||||
$this->isFakingEnabled()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_will_enable_faking_if_config_flag_is_set($input, $config)
|
||||
{
|
||||
$input->getOption('fake')->willReturn(false);
|
||||
$config->isFakingEnabled()->willReturn(true);
|
||||
|
||||
$this->isFakingEnabled()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_will_report_no_bootstrap_when_there_is_none($input, $config)
|
||||
{
|
||||
$input->getOption('bootstrap')->willReturn(null);
|
||||
$config->getBootstrapPath()->willReturn(false);
|
||||
|
||||
$this->getBootstrapPath()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_will_report_bootstrap_path_when_one_is_in_the_config_file($input, $config)
|
||||
{
|
||||
$input->getOption('bootstrap')->willReturn(null);
|
||||
$config->getBootstrapPath()->willReturn('/path/to/bootstrap.php');
|
||||
|
||||
$this->getBootstrapPath()->shouldReturn('/path/to/bootstrap.php');
|
||||
}
|
||||
|
||||
function it_will_report_bootstrap_path_when_one_is_specified_at_the_command_line($input, $config)
|
||||
{
|
||||
$input->getOption('bootstrap')->willReturn('/path/to/bootstrap.php');
|
||||
$config->getBootstrapPath()->willReturn(false);
|
||||
|
||||
$this->getBootstrapPath()->shouldReturn('/path/to/bootstrap.php');
|
||||
}
|
||||
|
||||
function it_will_report_bootstrap_path_from_cli_when_different_paths_are_specified_in_config_and_cli($input, $config)
|
||||
{
|
||||
$input->getOption('bootstrap')->willReturn('/path/to/bootstrap.php');
|
||||
$config->getBootstrapPath()->willReturn('/path/to/different.php');
|
||||
|
||||
$this->getBootstrapPath()->shouldReturn('/path/to/bootstrap.php');
|
||||
}
|
||||
|
||||
function it_defaults_the_block_width()
|
||||
{
|
||||
$this->getBlockWidth()->shouldReturn(60);
|
||||
}
|
||||
|
||||
function it_sets_the_block_width_to_the_minimum_when_terminal_is_narrow()
|
||||
{
|
||||
$this->setConsoleWidth(10);
|
||||
|
||||
$this->getBlockWidth()->shouldReturn(60);
|
||||
}
|
||||
|
||||
function it_sets_the_block_width_to_the_maximum_when_terminal_is_very_wide()
|
||||
{
|
||||
$this->setConsoleWidth(1000);
|
||||
|
||||
$this->getBlockWidth()->shouldReturn(80);
|
||||
}
|
||||
|
||||
function it_sets_the_block_width_to_narrower_than_the_terminal_width_when_terminal_is_in_range()
|
||||
{
|
||||
$this->setConsoleWidth(75);
|
||||
|
||||
$this->getBlockWidth()->shouldReturn(65);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Console;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use PhpSpec\Event\ExampleEvent;
|
||||
|
||||
class ResultConverterSpec extends ObjectBehavior
|
||||
{
|
||||
function it_converts_passed_result_code_into_0()
|
||||
{
|
||||
$this->convert(ExampleEvent::PASSED)->shouldReturn(0);
|
||||
}
|
||||
|
||||
function it_converts_skipped_result_code_into_0()
|
||||
{
|
||||
$this->convert(ExampleEvent::SKIPPED)->shouldReturn(0);
|
||||
}
|
||||
|
||||
function it_converts_pending_result_code_into_1()
|
||||
{
|
||||
$this->convert(ExampleEvent::PENDING)->shouldReturn(1);
|
||||
}
|
||||
|
||||
function it_converts_failed_result_code_into_1()
|
||||
{
|
||||
$this->convert(ExampleEvent::FAILED)->shouldReturn(1);
|
||||
}
|
||||
|
||||
function it_converts_broken_result_code_into_1()
|
||||
{
|
||||
$this->convert(ExampleEvent::BROKEN)->shouldReturn(1);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Event;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
use PhpSpec\Loader\Node\ExampleNode;
|
||||
use PhpSpec\Loader\Node\SpecificationNode;
|
||||
use PhpSpec\Loader\Suite;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ExampleEventSpec extends ObjectBehavior
|
||||
{
|
||||
function let(Suite $suite, SpecificationNode $specification, ExampleNode $example, Exception $exception)
|
||||
{
|
||||
$this->beConstructedWith($example, 10, $this->FAILED, $exception);
|
||||
|
||||
$example->getSpecification()->willReturn($specification);
|
||||
$specification->getSuite()->willReturn($suite);
|
||||
}
|
||||
|
||||
function it_is_an_event()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_example($example)
|
||||
{
|
||||
$this->getExample()->shouldReturn($example);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_specification($specification)
|
||||
{
|
||||
$this->getSpecification()->shouldReturn($specification);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_suite($suite)
|
||||
{
|
||||
$this->getSuite()->shouldReturn($suite);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_time()
|
||||
{
|
||||
$this->getTime()->shouldReturn(10);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_result()
|
||||
{
|
||||
$this->getResult()->shouldReturn($this->FAILED);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_exception($exception)
|
||||
{
|
||||
$this->getException()->shouldReturn($exception);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Event;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use PhpSpec\Loader\Suite;
|
||||
use PhpSpec\Loader\Node\SpecificationNode;
|
||||
use PhpSpec\Loader\Node\ExampleNode;
|
||||
use PhpSpec\Matcher\MatcherInterface;
|
||||
use Prophecy\Argument;
|
||||
use Exception;
|
||||
|
||||
class ExpectationEventSpec extends ObjectBehavior
|
||||
{
|
||||
function let(Suite $suite, SpecificationNode $specification, ExampleNode $example,
|
||||
MatcherInterface $matcher, $subject, Exception $exception)
|
||||
{
|
||||
$method = 'calledMethod';
|
||||
$arguments = array('methodArguments');
|
||||
|
||||
$this->beConstructedWith($example, $matcher, $subject, $method, $arguments, $this->FAILED, $exception);
|
||||
|
||||
$example->getSpecification()->willReturn($specification);
|
||||
$specification->getSuite()->willReturn($suite);
|
||||
}
|
||||
|
||||
function it_is_an_event()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_matcher($matcher)
|
||||
{
|
||||
$this->getMatcher()->shouldReturn($matcher);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_example($example)
|
||||
{
|
||||
$this->getExample()->shouldReturn($example);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_specification($specification)
|
||||
{
|
||||
$this->getSpecification()->shouldReturn($specification);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_suite($suite)
|
||||
{
|
||||
$this->getSuite()->shouldReturn($suite);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_subject($subject)
|
||||
{
|
||||
$this->getSubject()->shouldReturn($subject);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_method()
|
||||
{
|
||||
$this->getMethod()->shouldReturn('calledMethod');
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_arguments()
|
||||
{
|
||||
$this->getArguments()->shouldReturn(array('methodArguments'));
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_result()
|
||||
{
|
||||
$this->getResult()->shouldReturn($this->FAILED);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_exception($exception)
|
||||
{
|
||||
$this->getException()->shouldReturn($exception);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Event;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class FileCreationEventSpec extends ObjectBehavior
|
||||
{
|
||||
private $filepath = 'foo/bar.php';
|
||||
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith($this->filepath);
|
||||
}
|
||||
|
||||
function it_should_be_a_symfony_event()
|
||||
{
|
||||
$this->shouldHaveType('Symfony\Component\EventDispatcher\Event');
|
||||
}
|
||||
|
||||
function it_should_be_a_phpspec_event()
|
||||
{
|
||||
$this->shouldImplement('PhpSpec\Event\EventInterface');
|
||||
}
|
||||
|
||||
function it_should_return_the_created_file_path()
|
||||
{
|
||||
$this->getFilePath()->shouldReturn($this->filepath);
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Event;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use PhpSpec\Wrapper\Subject;
|
||||
use PhpSpec\Loader\Suite;
|
||||
use PhpSpec\Loader\Node\SpecificationNode;
|
||||
use PhpSpec\Loader\Node\ExampleNode;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class MethodCallEventSpec extends ObjectBehavior
|
||||
{
|
||||
function let(Suite $suite, SpecificationNode $specification, ExampleNode $example, $subject)
|
||||
{
|
||||
$method = 'calledMethod';
|
||||
$arguments = array('methodArguments');
|
||||
$returnValue = 'returned value';
|
||||
|
||||
$this->beConstructedWith($example, $subject, $method, $arguments, $returnValue);
|
||||
|
||||
$example->getSpecification()->willReturn($specification);
|
||||
$specification->getSuite()->willReturn($suite);
|
||||
}
|
||||
|
||||
function it_is_an_event()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_example($example)
|
||||
{
|
||||
$this->getExample()->shouldReturn($example);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_specification($specification)
|
||||
{
|
||||
$this->getSpecification()->shouldReturn($specification);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_suite($suite)
|
||||
{
|
||||
$this->getSuite()->shouldReturn($suite);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_subject($subject)
|
||||
{
|
||||
$this->getSubject()->shouldReturn($subject);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_method()
|
||||
{
|
||||
$this->getMethod()->shouldReturn('calledMethod');
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_arguments()
|
||||
{
|
||||
$this->getArguments()->shouldReturn(array('methodArguments'));
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_return_value()
|
||||
{
|
||||
$this->getReturnValue()->shouldReturn('returned value');
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Event;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
use PhpSpec\Event\ExampleEvent as Example;
|
||||
use PhpSpec\Loader\Node\SpecificationNode;
|
||||
use PhpSpec\Loader\Suite;
|
||||
|
||||
class SpecificationEventSpec extends ObjectBehavior
|
||||
{
|
||||
function let(Suite $suite, SpecificationNode $specification)
|
||||
{
|
||||
$this->beConstructedWith($specification, 10, Example::FAILED);
|
||||
|
||||
$specification->getSuite()->willReturn($suite);
|
||||
}
|
||||
|
||||
function it_is_an_event()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_suite($suite)
|
||||
{
|
||||
$this->getSuite()->shouldReturn($suite);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_specification($specification)
|
||||
{
|
||||
$this->getSpecification()->shouldReturn($specification);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_time()
|
||||
{
|
||||
$this->getTime()->shouldReturn(10);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_result()
|
||||
{
|
||||
$this->getResult()->shouldReturn(Example::FAILED);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Event;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
use PhpSpec\Event\ExampleEvent as Example;
|
||||
use PhpSpec\Loader\Suite;
|
||||
|
||||
class SuiteEventSpec extends ObjectBehavior
|
||||
{
|
||||
function let(Suite $suite)
|
||||
{
|
||||
$this->beConstructedWith($suite, 10, Example::FAILED);
|
||||
}
|
||||
|
||||
function it_is_an_event()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_suite($suite)
|
||||
{
|
||||
$this->getSuite()->shouldReturn($suite);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_time()
|
||||
{
|
||||
$this->getTime()->shouldReturn(10);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_result()
|
||||
{
|
||||
$this->getResult()->shouldReturn(Example::FAILED);
|
||||
}
|
||||
|
||||
function it_defaults_to_saying_suite_is_not_worth_rerunning()
|
||||
{
|
||||
$this->isWorthRerunning()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_can_be_told_that_the_suite_is_worth_rerunning()
|
||||
{
|
||||
$this->markAsWorthRerunning();
|
||||
$this->isWorthRerunning()->shouldReturn(true);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Exception\Example;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class NotEqualExceptionSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('Not equal', 2, 5);
|
||||
}
|
||||
|
||||
function it_is_failure()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\Exception\Example\FailureException');
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_expected()
|
||||
{
|
||||
$this->getExpected()->shouldReturn(2);
|
||||
}
|
||||
|
||||
function it_provides_a_link_to_actual()
|
||||
{
|
||||
$this->getActual()->shouldReturn(5);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Exception\Example;
|
||||
|
||||
use PhpSpec\Event\ExampleEvent;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
class StopOnFailureExceptionSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('Message', 0, null, 1);
|
||||
}
|
||||
|
||||
function it_is_an_example_exception()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('PhpSpec\Exception\Example\ExampleException');
|
||||
}
|
||||
|
||||
function it_has_a_the_result_of_the_last_spec()
|
||||
{
|
||||
$this->getResult()->shouldReturn(1);
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Exception;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
|
||||
use PhpSpec\Formatter\Presenter\PresenterInterface;
|
||||
|
||||
class ExceptionFactorySpec extends ObjectBehavior
|
||||
{
|
||||
private $fixture;
|
||||
private $createdException;
|
||||
|
||||
function let(PresenterInterface $presenter)
|
||||
{
|
||||
$this->beConstructedWith($presenter);
|
||||
$this->fixture = new \stdClass();
|
||||
$this->fixture->subject = new \stdClass();
|
||||
$this->fixture->method = 'foo';
|
||||
$this->fixture->arguments = array('bar');
|
||||
$this->fixture->classname = '\stdClass';
|
||||
$this->fixture->property = 'zoo';
|
||||
}
|
||||
|
||||
function it_creates_a_named_constructor_not_found_exception(PresenterInterface $presenter)
|
||||
{
|
||||
$presenter->presentString("{$this->fixture->classname}::{$this->fixture->method}")
|
||||
->shouldBeCalled()
|
||||
->willReturn("\"{$this->fixture->classname}::{$this->fixture->method}\"");
|
||||
$this->fixture->message = 'Named constructor "\stdClass::foo" not found.';
|
||||
$this->createdException = $this->namedConstructorNotFound(
|
||||
$this->fixture->classname,
|
||||
$this->fixture->method,
|
||||
$this->fixture->arguments
|
||||
);
|
||||
|
||||
$this->shouldCreateNamedConstructorNotFoundException();
|
||||
}
|
||||
|
||||
function it_creates_a_method_not_found_exception(PresenterInterface $presenter)
|
||||
{
|
||||
$presenter->presentString("{$this->fixture->classname}::{$this->fixture->method}")
|
||||
->shouldBeCalled()
|
||||
->willReturn("\"{$this->fixture->classname}::{$this->fixture->method}\"");
|
||||
$this->fixture->message = 'Method "\stdClass::foo" not found.';
|
||||
$this->createdException = $this->methodNotFound(
|
||||
$this->fixture->classname,
|
||||
$this->fixture->method,
|
||||
$this->fixture->arguments
|
||||
);
|
||||
|
||||
$this->shouldCreateMethodNotFoundException();
|
||||
}
|
||||
|
||||
function it_creates_a_method_not_visible_exception(PresenterInterface $presenter)
|
||||
{
|
||||
$presenter->presentString("{$this->fixture->classname}::{$this->fixture->method}")
|
||||
->shouldBeCalled()
|
||||
->willReturn("\"{$this->fixture->classname}::{$this->fixture->method}\"");
|
||||
$this->fixture->message = 'Method "\stdClass::foo" not visible.';
|
||||
|
||||
$this->createdException = $this->methodNotVisible(
|
||||
$this->fixture->classname,
|
||||
$this->fixture->method,
|
||||
$this->fixture->arguments
|
||||
);
|
||||
|
||||
$this->shouldCreateMethodNotVisibleException();
|
||||
}
|
||||
|
||||
function it_creates_a_class_not_found_exception(PresenterInterface $presenter)
|
||||
{
|
||||
$presenter->presentString("{$this->fixture->classname}")
|
||||
->shouldBeCalled()
|
||||
->willReturn("\"{$this->fixture->classname}\"");
|
||||
$this->fixture->message = 'Class "\stdClass" does not exist.';
|
||||
$this->createdException = $this->classNotFound(
|
||||
$this->fixture->classname
|
||||
);
|
||||
|
||||
$this->shouldCreateClassNotFoundException();
|
||||
}
|
||||
|
||||
function it_creates_a_property_not_found_exception(PresenterInterface $presenter)
|
||||
{
|
||||
$presenter->presentString("{$this->fixture->property}")
|
||||
->shouldBeCalled()
|
||||
->willReturn("\"{$this->fixture->property}\"");
|
||||
$this->fixture->message = 'Property "zoo" not found.';
|
||||
$this->createdException = $this->propertyNotFound(
|
||||
$this->fixture->subject,
|
||||
$this->fixture->property
|
||||
);
|
||||
|
||||
$this->shouldCreatePropertyNotFoundException();
|
||||
}
|
||||
|
||||
function it_creates_a_calling_method_on_non_object_exception(PresenterInterface $presenter)
|
||||
{
|
||||
$presenter->presentString("{$this->fixture->method}()")
|
||||
->shouldBeCalled()
|
||||
->willReturn("\"{$this->fixture->method}()\"");
|
||||
$fixtureMessage = "Call to a member function \"{$this->fixture->method}()\" on a non-object.";
|
||||
$exception = $this->callingMethodOnNonObject($this->fixture->method);
|
||||
$exception->shouldHaveType('PhpSpec\Exception\Wrapper\SubjectException');
|
||||
$exception->getMessage()->shouldBe($fixtureMessage);
|
||||
}
|
||||
|
||||
function it_creates_a_setting_property_on_non_object_exception(PresenterInterface $presenter)
|
||||
{
|
||||
$presenter->presentString("{$this->fixture->property}")
|
||||
->shouldBeCalled()
|
||||
->willReturn("\"{$this->fixture->property}\"");
|
||||
$fixtureMessage = "Setting property \"{$this->fixture->property}\" on a non-object.";
|
||||
$exception = $this->settingPropertyOnNonObject($this->fixture->property);
|
||||
$exception->shouldHaveType('PhpSpec\Exception\Wrapper\SubjectException');
|
||||
$exception->getMessage()->shouldBe($fixtureMessage);
|
||||
}
|
||||
|
||||
function it_creates_an_accessing_property_on_non_object_exception(PresenterInterface $presenter)
|
||||
{
|
||||
$presenter->presentString("{$this->fixture->property}")
|
||||
->shouldBeCalled()
|
||||
->willReturn("\"{$this->fixture->property}\"");
|
||||
$fixtureMessage = "Getting property \"{$this->fixture->property}\" on a non-object.";
|
||||
$exception = $this->gettingPropertyOnNonObject($this->fixture->property);
|
||||
$exception->shouldHaveType('PhpSpec\Exception\Wrapper\SubjectException');
|
||||
$exception->getMessage()->shouldBe($fixtureMessage);
|
||||
}
|
||||
|
||||
function shouldCreateNamedConstructorNotFoundException()
|
||||
{
|
||||
$this->createdException->shouldHaveType('PhpSpec\Exception\Fracture\NamedConstructorNotFoundException');
|
||||
$this->createdException->getMessage()->shouldReturn($this->fixture->message);
|
||||
$this->createdException->getSubject()->shouldBeLike($this->fixture->subject);
|
||||
$this->createdException->getMethodName()->shouldReturn($this->fixture->method);
|
||||
$this->createdException->getArguments()->shouldReturn($this->fixture->arguments);
|
||||
}
|
||||
|
||||
function shouldCreateMethodNotFoundException()
|
||||
{
|
||||
$this->createdException->shouldHaveType('PhpSpec\Exception\Fracture\MethodNotFoundException');
|
||||
$this->createdException->getMessage()->shouldReturn($this->fixture->message);
|
||||
$this->createdException->getSubject()->shouldBeLike($this->fixture->subject);
|
||||
$this->createdException->getMethodName()->shouldReturn($this->fixture->method);
|
||||
$this->createdException->getArguments()->shouldReturn($this->fixture->arguments);
|
||||
}
|
||||
|
||||
function shouldCreateMethodNotVisibleException()
|
||||
{
|
||||
$this->createdException->shouldHaveType('PhpSpec\Exception\Fracture\MethodNotVisibleException');
|
||||
$this->createdException->getMessage()->shouldReturn($this->fixture->message);
|
||||
$this->createdException->getSubject()->shouldBeLike($this->fixture->subject);
|
||||
$this->createdException->getMethodName()->shouldReturn($this->fixture->method);
|
||||
$this->createdException->getArguments()->shouldReturn($this->fixture->arguments);
|
||||
}
|
||||
|
||||
function shouldCreateClassNotFoundException()
|
||||
{
|
||||
$this->createdException->shouldHaveType('PhpSpec\Exception\Fracture\ClassNotFoundException');
|
||||
$this->createdException->getMessage()->shouldReturn($this->fixture->message);
|
||||
$this->createdException->getClassname()->shouldReturn($this->fixture->classname);
|
||||
}
|
||||
|
||||
function shouldCreatePropertyNotFoundException()
|
||||
{
|
||||
$this->createdException->shouldHaveType('PhpSpec\Exception\Fracture\PropertyNotFoundException');
|
||||
$this->createdException->getMessage()->shouldReturn($this->fixture->message);
|
||||
$this->createdException->getSubject()->shouldReturn($this->fixture->subject);
|
||||
$this->createdException->getProperty()->shouldReturn($this->fixture->property);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace spec\PhpSpec\Exception;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
use ReflectionMethod;
|
||||
|
||||
class ExceptionSpec extends ObjectBehavior
|
||||
{
|
||||
function it_extends_basic_exception()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Exception');
|
||||
}
|
||||
|
||||
function it_could_have_a_cause(ReflectionMethod $cause)
|
||||
{
|
||||
$this->setCause($cause);
|
||||
$this->getCause()->shouldReturn($cause);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user