Laravel 5.6 updates

Travis config update

Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
Manish Verma
2018-08-06 20:08:55 +05:30
parent 126fbb0255
commit 1ac0f42a58
2464 changed files with 65239 additions and 46734 deletions

View File

@@ -2,25 +2,25 @@ language: php
sudo: false
dist: trusty
cache:
directories:
- $HOME/.composer/cache
matrix:
include:
- php: 5.3
- php: 5.3
env: DEPENDENCIES='low'
- php: 5.4
- php: 5.5
- php: 5.6
env: DEPENDENCIES='dev'
- php: 5.6
- php: hhvm
dist: trusty
- php: 7.0
env: COMPOSER_FLAGS='--prefer-lowest'
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.2
env: DEPENDENCIES='dev'
- php: nightly
env: COMPOSER_FLAGS='--ignore-platform-reqs'
allow_failures:
- env: DEPENDENCIES='dev'
- php: nightly
fast_finish: true
before_install:
@@ -28,9 +28,8 @@ before_install:
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;
- if [ "$DEPENDENCIES" == "dev" ]; then composer config minimum-stability dev; fi;
- composer update $COMPOSER_FLAGS
script:
- bin/phpspec run --format=dot
@@ -52,5 +51,5 @@ deploy:
skip_cleanup: true
on:
tags: true
php: 5.6
condition: $DEPENDENCIES != "low"
php: 7.0
condition: COMPOSER_FLAGS != "--prefer-lowest"

211
vendor/phpspec/phpspec/CHANGES-v2.md vendored Normal file
View File

@@ -0,0 +1,211 @@
2.5.8 / 2017-07-29
==================
* [fixed] parameters after extensions ignored in config file (@borNfreee)
2.5.7 / 2017-05-12
==================
* [fixed] constructor no longer generated multuple tiles (@CarlosV2)
* [fixed] warning when src_path is empty (@vitorf7)
2.5.6 / 2017-04-27
==================
* Support sebastian/exporter 2.0 and 3.0 (@mattsches and @remicollet)
2.5.5 / 2016-12-04
==================
* [fixed] PHP 5.3 support was broken (@unfunco)
2.5.4 / 2016-12-02
==================
* [fixed] Prevent deprecation warning in Symfony 3.2.0 (@veewee)
* [performance] Reduced size of Phar (@unfunco)
2.5.3 / 2016-09-26
==================
* [fixed] Accidental linebreaks in spec name are not allowed (@randompixel)
* [fixed] Throwable can be passed as instance to shouldThrow (@jameshalsall)
* [performance] Phar version now has an optimised autoloader
2.5.2 / 2016-09-04
==================
* [fixed] Exceptions are properly highlighted in error messages (@ciaranmcnulty)
2.5.1 / 2016-07-16
==================
* [fixed] Describing a class providing a namespace with leading backslash (@mheki)
* [fixed] Bug where rerun test suite was uncoloured (@ciaranmcnulty)
* [fixed] Bug in DotFormatter when number of rows is multiple of column width (@bendavies)
2.5.0 / 2016-03-20
==================
* Fixed bug with typehints in classes defined in spec file
* Supports grouped Use statements
* Now shows path in error message when spec file doesn't contain a class
* Supports catching PHP 7 Errors in shouldThrow
* No longer attempts to generate methods with reserved names
* Fixed bug where bootstrapped classes could not be loaded after class generation
* Fixed bug where line numbers were incorrectly reported on PHP 7
* Fixed new methods being inserted incorrectly when strings included closing brace
* Dot formatter now shows spec count on last line
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()
* Handle and present fatal errors
* Fixed edge case with partial use statements
* 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
==================
* Fixed bugs when generating methods in class with unusual whitespace
* 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
==================
* Better diffs when presenting unexpected method arguments
* Better handling of methods delclared inside Traits when faking
* 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
* [BC break] 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
==================
* 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
* 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
* 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
* Fixed the Prophecy constraint as the new release is 1.1
* Refactored formatters to be defined as services
* Fixed the invocation of methods expecting an argument passed by reference
* Fixed the instantiation of the wrapped object in shouldThrow
* 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
* Add collaborator constructor setter
* Fix couple of bugs in Prophecy integration layer
* New (old) dot formatter
* Prevent loading of unexisting PHP files
* Fix typos in the error messages
* 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

85
vendor/phpspec/phpspec/CHANGES-v3.md vendored Normal file
View File

@@ -0,0 +1,85 @@
3.4.3 / 2017-12-06
==================
* [fixed] Undefined exception when giving wrong args to Trigger matcher (@greg0ire)
3.4.2 / 2017-08-05
==================
* [fixed] Illegible text when using a white terminal background (@MarcelloDuarte)
3.4.1 / 2017-07-29
==================
* [fixed] parameters after extensions ignored in config file (@borNfreee)
3.4.0 / 2017-05-12
==================
* [fixed] constructor no longer generated multuple tiles (@CarlosV2)
* [fixed] warning when src_path is empty (@vitorf7)
* Support methods with reserved names on PHP 7 (@avant1)
3.3.0 / 2017-04-27
==================
* Support sebastian/exporter 3.0 (@remicollet)
* Support `.phpspec.yml` as a filename (@shrikeh)
3.2.3 / 2016-01-29
==================
* IDE support for shouldYield/shouldStartYielding (@pamil)
3.2.2 / 2016-12-04
==================
* Support sebastian/exporter 2.0 providing PHPUnit 5.7 compatibility (@mattsches)
3.2.1 / 2016-12-02
==================
* [fixed] Prevent deprecation warning in Symfony 3.2.0 (@veewee)
3.2.0 / 2016-11-27
==================
* New `shouldTrigger` matcher for specifying a warning is triggered (@Taluu)
* New `shouldIterateAs` matcher for specifying how a class is iterated (@pamil)
* New `shouldBeApproximately` matcher for comparing floats (@brainrepo)
* [fixed] No longer suggests an outdated version of Nyan formatters (@unfunco)
* [performance] Reduced size of Phar (@unfunco)
3.1.1 / 2016-09-26
==================
* [fixed] Accidental linebreaks in spec name are not allowed (@randompixel)
* [fixed] Throwable can be passed as instance to shouldThrow (@jameshalsall)
* [performance] Phar version now has an optimised autoloader
3.1.0 / 2017-09-17
======================
* Many errors are now caught and handled without ending suite execution (@ciaranmcnulty)
* Validates that matchers specified in config are valid matchers (@avant1)
* Shows Error message even when Exception was expected (@harrisonbro)
* Disallows doubling of PHP 7.1's `iterable` type (@avant1)
* [fixed] Exceptions are properly highlighted in error messages (@ciaranmcnulty)
3.0.0 / 2016-07-16
==================
* Default template now uses `::class` (@ciaranmcnulty)
* No longer declare variables/constants in global scope (@ciaranmcnulty)
* Ability to register matchers quickly via the config file (@gquemener)
* [fixed] Describing a class providing a namespace with leading backslash (@mheki)
* [fixed] Bug where rerun test suite was uncoloured (@ciaranmcnulty)
* [fixed] Bug in DotFormatter when number of rows is multiple of column width (@bendavies)
* [BC break] Removed support for @param for creating doubles (@Sam-Burns)
* [BC break] Bumped dependency versions (see migration guide) (@ciaranmcnulty)
* [BC break] Removed various code branches for support of older dependencies (@ciaranmcnulty)
* [BC break] Made classes final or abstract in simple cases (@ciaranmcnulty)
* [BC break] Removed `*Interface` from all interfaces (@shanethehat)
* [BC break] Removed deprecated code / optional interfaces (@mheki)
* [BC break] Changed extension config format so parameters are scoped to extensions (@docteurklein)
* [BC break] New Extension and ServiceContainer interfaces (@ciaranmcnulty)

79
vendor/phpspec/phpspec/CHANGES-v4.md vendored Normal file
View File

@@ -0,0 +1,79 @@
4.3.1 / 2018-07-02
==================
* Typehint iteration matchers for IDEs (@l3l0)
* Extension point to help annotation extension (@drupol)
4.3.0 / 2017-12-22
==================
* Add support for .yaml file extension in config file (@unfunco)
* [fixed] src folder is created when does not exist and using PSR-4 (@unfunco)
4.2.5 / 2017-12-06
==================
* [fixed] Undefined exception when giving wrong args to Trigger matcher (@greg0ire)
4.2.4 / 2017-11-24
==================
* [fixed] Errors from incorrect type hint when collaborator method not found (@greg0ire)
4.2.3 / 2017-11-24
==================
* [fixed] Allow installation with Symfony 4 (@sroze, @gnugat)
4.2.2 / 2017-11-17
==================
* [fixed] Missing autocomplete for shouldIterateLike matchers (@pamil)
* [fixed] Regression where config files called .dist or . prefix were not picked up (@jakzal)
4.2.1 / 2017-11-10
==================
* [fixed] Properly handle empty config file (@ciaranmcnulty)
* [fixed] Non-existent folders broke composer detection (@greg0ire)
4.2.0 / 2017-10-28
==================
* Detect autoloader from composer to automatically define spec locations, reducing need for suites with PSR-4 (@greg0ire)
* Describe command without class now shows prompt with autocompleting input (@fullpipe)
4.1.0 / 2017-10-18
==================
* New `shouldIterateLike`/`shouldYieldLike` matcher (@sroze)
* Checks class name is not a reserved word when creating spec (@avant1)
4.0.4 / 2017-09-13
==================
* Allow installation on PHP 7.2 (@ciaranmcnulty)
* [performance] Improved speed when invoking native functions (@bendavies)
4.0.3 / 2017-08-26
==================
* [fixed] TypeError thrown when calling `ExampleEvent::getTime()` on event constructed w/ nullable `$time` (@oxkhar)
* [fixed] TypeError thrown when presenting diff in verbose mode (@avant1)
4.0.2 / 2017-08-05
==================
* [fixed] Illegible text when using a white terminal background (@MarcelloDuarte)
4.0.1 / 2017-07-04
==================
* [fixed] type error when handling errors (@nightlinus)
4.0.0 / 2017-07-29
==================
* Dropped support for PHP versions less than 7.0 (@ciaranmcnulty)
* Added scalar types and return types (@Sam-Burns, @ciaranmcnulty)
* [fixed] parameters after extensions ignored in config file (@borNfreee)

View File

@@ -1,211 +1 @@
2.5.8 / 2017-07-29
==================
* [fixed] parameters after extensions ignored in config file (@borNfreee)
2.5.7 / 2017-05-12
==================
* [fixed] constructor no longer generated multuple tiles (@CarlosV2)
* [fixed] warning when src_path is empty (@vitorf7)
2.5.6 / 2017-04-27
==================
* Support sebastian/exporter 2.0 and 3.0 (@mattsches and @remicollet)
2.5.5 / 2016-12-04
==================
* [fixed] PHP 5.3 support was broken (@unfunco)
2.5.4 / 2016-12-02
==================
* [fixed] Prevent deprecation warning in Symfony 3.2.0 (@veewee)
* [performance] Reduced size of Phar (@unfunco)
2.5.3 / 2016-09-26
==================
* [fixed] Accidental linebreaks in spec name are not allowed (@randompixel)
* [fixed] Throwable can be passed as instance to shouldThrow (@jameshalsall)
* [performance] Phar version now has an optimised autoloader
2.5.2 / 2016-09-04
==================
* [fixed] Exceptions are properly highlighted in error messages (@ciaranmcnulty)
2.5.1 / 2016-07-16
==================
* [fixed] Describing a class providing a namespace with leading backslash (@mheki)
* [fixed] bug where rerun test suite was uncoloured (@ciaranmcnulty)
* [fixed] Bug in DotFormatter when number of rows is multiple of column width (@bendavies)
2.5.0 / 2016-03-20
==================
* Fixed bug with typehints in classes defined in spec file
* Supports grouped Use statements
* Now shows path in error message when spec file doesn't contain a class
* Supports catching PHP 7 Errors in shouldThrow
* No longer attempts to generate methods with reserved names
* Fixed bug where bootstrapped classes could not be loaded after class generation
* Fixed bug where line numbers were incorrectly reported on PHP 7
* Fixed new methods being inserted incorrectly when strings included closing brace
* Dot formatter now shows spec count on last line
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()
* Handle and present fatal errors
* Fixed edge case with partial use statements
* 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
==================
* Fixed bugs when generating methods in class with unusual whitespace
* 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
==================
* Better diffs when presenting unexpected method arguments
* Better handling of methods delclared inside Traits when faking
* 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
* [BC break] 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
==================
* 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
* 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
* 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
* Fixed the Prophecy constraint as the new release is 1.1
* Refactored formatters to be defined as services
* Fixed the invocation of methods expecting an argument passed by reference
* Fixed the instantiation of the wrapped object in shouldThrow
* 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
* Add collaborator constructor setter
* Fix couple of bugs in Prophecy integration layer
* New (old) dot formatter
* Prevent loading of unexisting PHP files
* Fix typos in the error messages
* 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
CHANGES-v4.md

View File

@@ -7,9 +7,9 @@ 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).
- For new features, or bugs that only affect the 5.x versions, base your changes on the `master` branch and open PRs against `master`
- For bugs that affect 4.3.x versions, base your changes on the `4.3` branch and open PRs agains `4.3`
- Bugs in previous versions are not going to be fixed, upgrade to `4.3` minimum.
Coverage
--------

View File

@@ -1,4 +1,4 @@
Copyright (c) 2013-2014 Konstantin Kudryashov <ever.zet@gmail.com>
Copyright (c) 2013-2016 Konstantin Kudryashov <ever.zet@gmail.com>
Marcello Duarte <marcello.duarte@gmail.com>
Permission is hereby granted, free of charge, to any person

View File

@@ -4,25 +4,39 @@ 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
:target: https://travis-ci.org/phpspec/phpspec
:alt: Master Travis Build Status
.. image:: https://scrutinizer-ci.com/g/phpspec/phpspec/badges/quality-score.png?b=master
.. image:: https://img.shields.io/scrutinizer/g/phpspec/phpspec.svg
:target: https://scrutinizer-ci.com/g/phpspec/phpspec/build-status/master
:alt: Master Scrutinizer Quality Score
.. image:: https://ci.appveyor.com/api/projects/status/wce4nun9re76ocp6/branch/master?svg=true
.. image:: https://img.shields.io/appveyor/ci/ciaranmcnulty/phpspec/master.svg
:target: https://ci.appveyor.com/project/ciaranmcnulty/phpspec/branch/master
:alt: AppVeyor build status
.. image:: https://poser.pugx.org/phpspec/phpspec/downloads.png
:target: https://poser.pugx.org/phpspec/phpspec/downloads
:alt: Total downloads
.. image:: https://poser.pugx.org/phpspec/phpspec/v/stable.png
:target: https://poser.pugx.org/phpspec/phpspec/v/stable
:alt: Latest stable version
.. image:: https://poser.pugx.org/phpspec/phpspec/v/unstable.png
:target: https://poser.pugx.org/phpspec/phpspec/v/unstable
:alt: Latest unstable version
.. image:: https://poser.pugx.org/phpspec/phpspec/license.png
:target: https://poser.pugx.org/phpspec/phpspec/license
:alt: Software license
Installing Dependencies
-----------------------
Dependencies are handled via `composer <http://getcomposer.org>`_::
Dependencies are handled via `composer <https://getcomposer.org>`_::
wget -nc http://getcomposer.org/composer.phar
wget -nc https://getcomposer.org/composer.phar
php composer.phar install
Developer's mailing list

View File

@@ -1,3 +1,4 @@
version: '{build}'
build: false
shallow_clone: true
platform: x86
@@ -5,39 +6,55 @@ clone_folder: c:\projects\phpspec
environment:
matrix:
- PHP_DOWNLOAD_FILE: php-5.6.14-nts-Win32-VC11-x86.zip
- php: 7.2
skip_commits:
message: /\[ci skip\]/
cache:
- c:\php -> appveyor.yml
- '%LOCALAPPDATA%\Composer'
- C:\ProgramData\chocolatey\bin -> appveyor.yml
- C:\ProgramData\chocolatey\lib -> appveyor.yml
- C:\tools\php -> appveyor.yml
- C:\tools\composer -> appveyor.yml
- '%LOCALAPPDATA%\Composer\files'
init:
- SET PATH=c:\php;%PATH%
- SET PATH=C:\Program Files\OpenSSL;c:\tools\php;C:\tools\composer;%PATH%
- SET COMPOSER_NO_INTERACTION=1
- SET PHP=1
SET COMPOSER_ROOT_VERSION=dev-master
- 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
- ps: |
if (!(Test-Path c:\tools\php)) {
appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
Get-ChildItem -Path c:\tools\php
cd c:\tools\php
# Set PHP environment items that are always needed
copy php.ini-production php.ini
Add-Content php.ini "`n date.timezone=UTC"
Add-Content php.ini "`n extension_dir=ext"
Add-Content php.ini "`n extension=php_openssl.dll"
Add-Content php.ini "`n extension=php_curl.dll"
Add-Content php.ini "`n extension=php_mbstring.dll"
Add-Content php.ini "`n extension=php_fileinfo.dll"
# download Composer
if (!(Test-Path C:\tools\composer)) {
New-Item -path c:\tools -name composer -itemtype directory
}
if (!(Test-Path c:\tools\composer\composer.phar)) {
appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar -Filename C:\tools\composer\composer.phar
Set-Content -path 'C:\tools\composer\composer.bat' -Value ('@php C:\tools\composer\composer.phar %*')
}
}
- cd c:\projects\phpspec
- SET COMPOSER_ROOT_VERSION=dev-master
- composer update --no-progress --ansi
- appveyor-retry composer self-update
- appveyor-retry composer install --no-progress --ansi
test_script:
- cd c:\projects\phpspec

View File

@@ -9,8 +9,6 @@ default:
smoke:
contexts: [ IsolatedProcessContext, FilesystemContext ]
filters: { tags: "@smoke && ~@isolated" }
extensions:
Cjm\Behat\VersionBasedTestSkipperExtension: ~
no-smoke:
suites:

View File

@@ -1,26 +1,27 @@
#!/usr/bin/env php
<?php
define('PHPSPEC_VERSION', '2.5.8');
(function ($version) {
if (is_file($autoload = getcwd() . '/vendor/autoload.php')) {
require $autoload;
} elseif (is_file($autoload = getcwd() . '/../../autoload.php')) {
require $autoload;
}
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);
}
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();
(new PhpSpec\Console\Application($version))->run();
})('4.3.1');

View File

@@ -1,6 +1,6 @@
{
"name": "phpspec/phpspec",
"description": "Specification-oriented BDD framework for PHP 5.3+",
"description": "Specification-oriented BDD framework for PHP 5.6+",
"keywords": ["BDD", "SpecBDD", "TDD", "spec", "specification", "tests", "testing"],
"homepage": "http://phpspec.net/",
"type": "library",
@@ -14,32 +14,35 @@
{
"name": "Marcello Duarte",
"homepage": "http://marcelloduarte.net/"
},
{
"name": "Ciaran McNulty",
"homepage": "https://ciaranmcnulty.com/"
}
],
"require": {
"php": ">=5.3.3",
"phpspec/prophecy": "~1.4",
"phpspec/php-diff": "~1.0.0",
"sebastian/exporter": "~1.0|~2.0|^3.0",
"symfony/console": "~2.3|~3.0,!=3.2.8",
"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",
"php": "^7.0,<7.3",
"phpspec/prophecy": "^1.5",
"phpspec/php-diff": "^1.0.0",
"sebastian/exporter": "^1.0 || ^2.0 || ^3.0",
"symfony/console": "^3.2 || ^4.0",
"symfony/event-dispatcher": "^3.2 || ^4.0",
"symfony/process": "^3.2 || ^4.0",
"symfony/finder": "^3.2 || ^4.0",
"symfony/yaml": "^3.2 || ^4.0",
"doctrine/instantiator": "^1.0.5",
"ext-tokenizer": "*"
},
"require-dev": {
"behat/behat": "^3.0.11,!=3.3.1",
"symfony/filesystem": "~2.1|~3.0",
"phpunit/phpunit": "~4.4",
"ciaranmcnulty/versionbasedtestskipper": "^0.2.1"
"behat/behat": "^3.3",
"symfony/filesystem": "^3.2 || ^4.0",
"phpunit/phpunit": "^5.7|^6.0"
},
"suggest": {
"phpspec/nyan-formatters": "~1.0 Adds Nyan formatters"
"phpspec/nyan-formatters": "Adds Nyan formatters"
},
"autoload": {
@@ -58,7 +61,7 @@
"extra": {
"branch-alias": {
"dev-master": "2.5.x-dev"
"dev-master": "4.3.x-dev"
}
}
}

View File

@@ -49,6 +49,7 @@ class ApplicationContext implements Context
$this->application = new Application('2.1-dev');
$this->application->setAutoExit(false);
$this->setFixedTerminalDimensions();
$this->tester = new ApplicationTester($this->application);
@@ -56,6 +57,12 @@ class ApplicationContext implements Context
$this->setupPrompter();
}
private function setFixedTerminalDimensions()
{
putenv('COLUMNS=130');
putenv('LINES=30');
}
private function setupPrompter()
{
$this->prompter = new Prompter();
@@ -305,6 +312,18 @@ class ApplicationContext implements Context
}
}
/**
* @Given there is a PSR-:namespaceType namespace :namespace configured for the :source folder
*/
public function thereIsAPsrNamespaceConfiguredForTheFolder($namespaceType, $namespace, $source)
{
if (!is_dir(__DIR__ . '/src')) {
mkdir(__DIR__ . '/src');
}
require_once __DIR__ .'/autoloader/fake_autoload.php';
}
/**
* @When I run phpspec with the :config (custom) config and answer :answer when asked if I want to generate the code
*/
@@ -363,10 +382,12 @@ class ApplicationContext implements Context
private function normalize($string)
{
$string = preg_replace('/\([0-9]+ms\)/', '', $string);
$string = str_replace("\r", '', $string);
$string = preg_replace('#(Double\\\\.+?\\\\P)\d+#u', '$1', $string);
return $string;
}
/**
* @Then I should not be prompted for more questions
*/
@@ -378,4 +399,14 @@ class ApplicationContext implements Context
);
}
}
/**
* @Then I should an error about invalid class name :className to generate spec for
*/
public function iShouldAnErrorAboutImpossibleSpecGenerationForClass($className)
{
$this->checkApplicationOutput("I cannot generate spec for '$className' because class");
$this->checkApplicationOutput('name contains reserved keyword');
}
}

View File

@@ -16,7 +16,7 @@ class Prompter implements PrompterInterface
$this->answers[] = $answer;
}
public function askConfirmation($question, $default = true)
public function askConfirmation(string $question, bool $default = true) : bool
{
$this->hasBeenAsked = true;
$this->question = $question;

View File

@@ -2,6 +2,7 @@
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use PHPUnit\Framework\Assert;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
@@ -35,6 +36,15 @@ class FilesystemContext implements Context
$this->filesystem->mkdir($this->workingDirectory);
chdir($this->workingDirectory);
$fakeHomeDirectory = sprintf('%s/fake-home/', $this->workingDirectory);
$this->filesystem->mkdir($fakeHomeDirectory . '.phpspec');
if (!empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) {
$_SERVER['HOMEPATH'] = substr($fakeHomeDirectory, 2);
} else {
putenv(sprintf('HOME=%s', $fakeHomeDirectory));
}
$this->filesystem->mkdir($this->workingDirectory . '/vendor');
$this->filesystem->copy(
__DIR__ . '/autoloader/autoload.php',
@@ -54,6 +64,14 @@ class FilesystemContext implements Context
}
}
/**
* @Given I have a custom :template template that contains:
*/
public function iHaveACustomTemplateThatContains($template, PyStringNode $contents)
{
$this->filesystem->dumpFile(sprintf('fake-home/.phpspec/%s.tpl', $template), $contents);
}
/**
* @Given the bootstrap file :file contains:
*/
@@ -140,4 +158,12 @@ class FilesystemContext implements Context
{
$this->filesystem->remove($this->workingDirectory . '/vendor/autoload.php');
}
/**
* @Given there should be no file :path
*/
public function thereShouldBeNoFile($path)
{
Assert::assertFileNotExists($path);
}
}

View File

@@ -42,6 +42,7 @@ class IsolatedProcessContext implements Context, SnippetAcceptingContext
'SHELL_INTERACTIVE' => true,
'HOME' => getenv('HOME'),
'PATH' => getenv('PATH'),
'COLUMNS' => 80,
);
$this->process = $process = new Process($command);
@@ -81,7 +82,7 @@ class IsolatedProcessContext implements Context, SnippetAcceptingContext
public function iShouldSeeAnErrorAboutTheMissingAutoloader()
{
if (!preg_match('/autoload/', $this->process->getErrorOutput().$this->process->getOutput())) {
throw new \Exception('There was no error regarding a missing autoloader:');
throw new \Exception(sprintf('There was no error regarding a missing autoloader: %s', $this->process->getErrorOutput().$this->process->getOutput()));
}
}
@@ -120,4 +121,16 @@ class IsolatedProcessContext implements Context, SnippetAcceptingContext
}
}
/**
* @Then the suite should pass
*/
public function theSuiteShouldPass()
{
$exitCode = $this->process->getExitCode();
if ($exitCode !== 0) {
throw new \Exception(sprintf('Expected that tests will pass, but exit code was %s.', $exitCode));
}
}
}

View File

@@ -3,3 +3,6 @@ spl_autoload_register(function ($classname) {
$classname = __DIR__ . '/../src/' . str_replace("\\", "/", trim($classname, "\\")) . ".php";
if (file_exists($classname)) { include $classname; }
});
if (class_exists('FakeLoader')) {
return new FakeLoader();
}

View File

@@ -0,0 +1,21 @@
<?php
class FakeLoader
{
public function getPrefixes()
{
return array(
'Andromeda\\N4S4Arm\\' => array(
__DIR__ . '/../src/'
)
);
}
public function getPrefixesPsr4()
{
return array(
'MilkyWay\\OrionCygnusArm\\' => array(
__DIR__ . '/../src/'
)
);
}
}

View File

@@ -3,7 +3,7 @@ Feature: Developer generates a class
I want to automate creating classes
In order to avoid repetitive tasks and interruptions in development flow
@smoke @php:~5.4||~7.0
@smoke
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
@@ -19,6 +19,33 @@ Feature: Developer generates a class
"""
@issue1008
Scenario: Generating a class with a custom template
Given I have started describing the "CodeGeneration/CustomExample/Markdown" class
And I have a custom "class" template that contains:
"""
<?php
/* Custom class template */%namespace_block%
final class %name%
{
}
"""
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/CustomExample/Markdown.php":
"""
<?php
/* Custom class template */
namespace CodeGeneration\CustomExample;
final class Markdown
{
}
"""
@issue269
Scenario: Generating a class with psr4 prefix
Given the config file contains:
@@ -132,7 +159,7 @@ Feature: Developer generates a class
"""
@isolated @php:~5.4||~7.0
@isolated
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

View File

@@ -1,4 +1,3 @@
@php:~7.0
Feature: Developer generates a collaborator
As a Developer
I want to automate creating collaborators

View File

@@ -53,59 +53,6 @@ Feature: Developer generates a collaborator's method
[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:
"""
@@ -264,48 +211,3 @@ Feature: Developer generates a collaborator's method
"""
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
Scenario: Being warned when a collaborator method is a restricted word
Given the spec file "spec/CodeGeneration/CollaboratorMethodExample6/MarkdownSpec.php" contains:
"""
<?php
namespace spec\CodeGeneration\CollaboratorMethodExample6;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use CodeGeneration\CollaboratorMethodExample1\Parser;
class MarkdownSpec extends ObjectBehavior
{
function it_interacts_with_a_collaborator(Parser $parser)
{
$parser->throw()->willReturn(true);
}
}
"""
And the class file "src/CodeGeneration/CollaboratorMethodExample6/Markdown.php" contains:
"""
<?php
namespace CodeGeneration\CollaboratorMethodExample6;
class Markdown
{
}
"""
And the class file "src/CodeGeneration/CollaboratorMethodExample6/Parser.php" contains:
"""
<?php
namespace CodeGeneration\CollaboratorMethodExample6;
interface Parser
{
}
"""
When I run phpspec and answer "n" when asked if I want to generate the code
Then I should see "I cannot generate the method 'throw' for you"

View File

@@ -372,8 +372,9 @@ Feature: Developer generates a method
"""
Scenario: Generating a method named with a restricted keyword
Given the spec file "spec/MyNamespace/RestrictedSpec.php" contains:
@php:~7 @isolated
Scenario: Successful generation of a method named with a reserved keyword in previous PHP versions
Given the spec file "spec/MyNamespace/KeywordMethodSpec.php" contains:
"""
<?php
@@ -382,36 +383,40 @@ Feature: Developer generates a method
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class RestrictedSpec extends ObjectBehavior
class KeywordMethodSpec extends ObjectBehavior
{
function it_tries_to_call_wrong_method()
{
$this->throw()->shouldReturn();
$this->throw()->shouldReturn(null);
}
}
"""
And the class file "src/MyNamespace/Restricted.php" contains:
And the class file "src/MyNamespace/KeywordMethod.php" contains:
"""
<?php
namespace MyNamespace;
class Restricted
class KeywordMethod
{
}
"""
When I run phpspec interactively
Then I should see "I cannot generate the method 'throw' for you"
And the class in "src/MyNamespace/Restricted.php" should contain:
When I run phpspec and answer "y" when asked if I want to generate the code
Then the class in "src/MyNamespace/KeywordMethod.php" should contain:
"""
<?php
namespace MyNamespace;
class Restricted
class KeywordMethod
{
public function throw()
{
// TODO: write logic here
}
}
"""
And the suite should pass

View File

@@ -260,7 +260,6 @@ Feature: Developer generates a method returning a constant
When I run phpspec interactively
Then I should be prompted for code generation
@php:~5.4||~7.0
Scenario: Generating a scalar return type when method is in trait
Given the spec file "spec/CodeGeneration/ConstantExample7/MarkdownSpec.php" contains:
"""

View File

@@ -11,6 +11,7 @@ Feature: Developer generates a spec
namespace spec\CodeGeneration\SpecExample1;
use CodeGeneration\SpecExample1\Markdown;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -18,7 +19,7 @@ Feature: Developer generates a spec
{
function it_is_initializable()
{
$this->shouldHaveType('CodeGeneration\SpecExample1\Markdown');
$this->shouldHaveType(Markdown::class);
}
}
@@ -43,6 +44,7 @@ Feature: Developer generates a spec
namespace CodeGeneration\SpecExample2;
use CodeGeneration\SpecExample2\Markdown;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -50,7 +52,7 @@ Feature: Developer generates a spec
{
function it_is_initializable()
{
$this->shouldHaveType('CodeGeneration\SpecExample2\Markdown');
$this->shouldHaveType(Markdown::class);
}
}
@@ -75,6 +77,7 @@ Feature: Developer generates a spec
namespace CodeGeneration\SpecExample2;
use CodeGeneration\SpecExample2\Markdown;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -82,7 +85,7 @@ Feature: Developer generates a spec
{
function it_is_initializable()
{
$this->shouldHaveType('CodeGeneration\SpecExample2\Markdown');
$this->shouldHaveType(Markdown::class);
}
}
@@ -97,6 +100,7 @@ Feature: Developer generates a spec
namespace spec\CodeGeneration\SpecExample1;
use CodeGeneration\SpecExample1\Text_Markdown;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -104,7 +108,7 @@ Feature: Developer generates a spec
{
function it_is_initializable()
{
$this->shouldHaveType('CodeGeneration\SpecExample1\Text_Markdown');
$this->shouldHaveType(Text_Markdown::class);
}
}
@@ -119,6 +123,7 @@ Feature: Developer generates a spec
namespace spec\CodeGeneration\Spec_Example2;
use CodeGeneration\Spec_Example2\Text_Markdown;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -126,7 +131,7 @@ Feature: Developer generates a spec
{
function it_is_initializable()
{
$this->shouldHaveType('CodeGeneration\Spec_Example2\Text_Markdown');
$this->shouldHaveType(Text_Markdown::class);
}
}
@@ -147,6 +152,7 @@ Feature: Developer generates a spec
namespace spec\Behat\CodeGeneration;
use Behat\CodeGeneration\Markdown;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -154,8 +160,13 @@ Feature: Developer generates a spec
{
function it_is_initializable()
{
$this->shouldHaveType('Behat\CodeGeneration\Markdown');
$this->shouldHaveType(Markdown::class);
}
}
"""
"""
Scenario: Generating a spec for class with namespace containing reserved keyword
Given I have started describing the "Namespace/ClassExample1/Markdown" class
Then I should an error about invalid class name "Namespace\ClassExample1\Markdown" to generate spec for
And there should be no file "spec/Namespace/ClassExample1/MarkdownSpec.php"

View File

@@ -3,7 +3,7 @@ Feature: Developer generates a class
I want the tests to automatically rerun after code generation events
In order to avoid repetitive tasks and interruptions in development flow
@smoke @php:~5.4||~7.0
@smoke
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

View File

@@ -0,0 +1,59 @@
Feature: Composer can be leveraged to create suites
As a Developer
I need the autoload rules I defined to be reused by phpspec
So I may enable the Composer namespace provider and get one suite per autoload rule
Scenario: Using composer as namespace_provider in a PSR0 namespace
Given the config file located in "." contains:
"""
composer_suite_detection: true
"""
And there is a PSR-0 namespace "Andromeda\N4S4Arm\" configured for the "src" folder
When I start describing the "Andromeda/N4S4Arm/Gazorpazorp" class with the "phpspec.yml" custom config
Then a new spec should be generated in the "spec/Andromeda/N4S4Arm/GazorpazorpSpec.php":
"""
<?php
namespace spec\Andromeda\N4S4Arm;
use Andromeda\N4S4Arm\Gazorpazorp;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class GazorpazorpSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Gazorpazorp::class);
}
}
"""
Scenario: Using composer as namespace_provider in a PSR4 namespace
Given the config file located in "." contains:
"""
composer_suite_detection : true
"""
And there is a PSR-4 namespace "MilkyWay\OrionCygnusArm\" configured for the "src" folder
When I start describing the "MilkyWay/OrionCygnusArm/LocalBubble" class with the "phpspec.yml" custom config
Then a new spec should be generated in the "spec/LocalBubbleSpec.php":
"""
<?php
namespace spec\MilkyWay\OrionCygnusArm;
use MilkyWay\OrionCygnusArm\LocalBubble;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class LocalBubbleSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(LocalBubble::class);
}
}
"""

View File

@@ -9,7 +9,7 @@ Feature: Config directory can be used in spec and src paths
suites:
behat_suite:
namespace: MilkyWay\OrionCygnusArm
spec_path: %paths.config%
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":
@@ -18,6 +18,7 @@ Feature: Config directory can be used in spec and src paths
namespace spec\MilkyWay\OrionCygnusArm;
use MilkyWay\OrionCygnusArm\LocalBubble;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -25,7 +26,7 @@ Feature: Config directory can be used in spec and src paths
{
function it_is_initializable()
{
$this->shouldHaveType('MilkyWay\OrionCygnusArm\LocalBubble');
$this->shouldHaveType(LocalBubble::class);
}
}
@@ -45,6 +46,7 @@ Feature: Config directory can be used in spec and src paths
namespace spec\MilkyWay\OrionCygnusArm;
use MilkyWay\OrionCygnusArm\ButterflyCluster;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -52,7 +54,7 @@ Feature: Config directory can be used in spec and src paths
{
function it_is_initializable()
{
$this->shouldHaveType('MilkyWay\OrionCygnusArm\ButterflyCluster');
$this->shouldHaveType(ButterflyCluster::class);
}
}
@@ -64,7 +66,7 @@ Feature: Config directory can be used in spec and src paths
suites:
behat_suite:
namespace: MilkyWay\OrionCygnusArm
src_path: %paths.config%/src
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

View File

@@ -0,0 +1,102 @@
Feature: Developer enables extensions
As a Developer
I want to enable and configure extensions
In order to customize or add features to phpspec behavior
Scenario: Adding parametrized extensions with correct config
Given the class file "src/Configuration/Extension2.php" contains:
"""
<?php
namespace Configuration;
class Extension2 implements \PhpSpec\Extension
{
public function load(\PhpSpec\ServiceContainer $container, array $params)
{
throw new \Exception(get_class().' enabled'. print_r($params, true));
}
}
"""
And the config file contains:
"""
extensions:
Configuration\Extension2: ~
Configuration\Extension2: [testParam]
"""
When I run phpspec
Then I should see "Extension2 enabled"
And I should see "testParam"
Scenario: Adding parametrized extensions with incorrect config
Given the class file "src/Configuration/Extension3.php" contains:
"""
<?php
namespace Configuration;
class Extension3 implements \PhpSpec\Extension
{
public function load(\PhpSpec\ServiceContainer $container, array $params)
{
throw new \Exception(get_class().' enabled'. print_r($params, true));
}
}
"""
And the config file contains:
"""
extensions:
Configuration\Extension3: test
"""
When I run phpspec
Then I should see "Extension configuration must be an array or null"
Scenario: Adding a non existent class as extension
Given the class file "src/Configuration/Extension4.php" contains:
"""
<?php
namespace Configuration;
class NOPE implements \PhpSpec\Extension
{
public function load(\PhpSpec\ServiceContainer $container, array $params)
{
throw new \Exception(get_class().' enabled'. print_r($params, true));
}
}
"""
And the config file contains:
"""
extensions:
Configuration\Extension4: ~
"""
When I run phpspec
Then I should see "Extension class `Configuration\Extension4` does not exist"
Scenario: Adding parametrized extensions without parameters
Given the class file "src/Configuration/Extension4.php" contains:
"""
<?php
namespace Configuration;
class Extension4 implements \PhpSpec\Extension
{
public function load(\PhpSpec\ServiceContainer $container, array $params)
{
throw new \Exception(get_class().' enabled'. print_r($params, true));
}
}
"""
And the config file contains:
"""
extensions:
Configuration\Extension4: ~
"""
When I run phpspec
Then I should see "Extension4 enabled"

View File

@@ -1,85 +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:~5.4||~7.0
Scenario: Fatal error writer message not shown, when formatter does not support it.
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"

View File

@@ -3,8 +3,7 @@ Feature: Developer is shown a parse error
I want to know if a parse error was thrown
So that I can know that I can handle pass errors
@isolated @php:~5.4||~7.0
Scenario: Spec attempts to call an undeclared function
Scenario: Parse error in class
Given the spec file "spec/Message/Fatal/ParseSpec.php" contains:
"""
<?php
@@ -15,6 +14,44 @@ Feature: Developer is shown a parse error
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ParseSpec extends ObjectBehavior
{
function it_throws_a_syntax_error()
{
$this->cool();
}
}
"""
And the spec file "src/Message/Fatal/Parse.php" contains:
"""
<?php
namespace Message\Parse;
class Par se
{
public function cool()
{
return true;
}
}
"""
When I run phpspec
Then I should see "1 broken"
Scenario: Parse error in spec
Given the spec file "spec/Message/Fatal2/ParseSpec.php" contains:
"""
<?php
namespace spec\Message\Fatal2;
use Parse;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ParseSpec extends ObjectBehavior
{
function it_thro ws_a_syntax_error()
@@ -24,11 +61,11 @@ Feature: Developer is shown a parse error
}
"""
And the spec file "src/Message/Fatal/Parse.php" contains:
And the spec file "src/Message/Fatal2/Parse.php" contains:
"""
<?php
namespace Message\Parse;
namespace Message\Parse2;
class Parse
{
@@ -39,5 +76,6 @@ Feature: Developer is shown a parse error
}
"""
When I run phpspec with the "junit" formatter
Then I should see "syntax error"
When I run phpspec
Then I should see "1 broken"
And I should see "syntax error"

View File

@@ -0,0 +1,87 @@
Feature: Developer is shown runtime errors
As a developer
To debug fatal errors better
I should be shown errors but the rest of the suite should run
Scenario: Runtime error in class being specified
Given the spec file "spec/Message/Fatal/RuntimeSpec.php" contains:
"""
<?php
namespace spec\Message\Fatal;
use PhpSpec\ObjectBehavior;
class RuntimeSpec extends ObjectBehavior
{
function it_breaks()
{
$this->broken();
}
function it_passes()
{
$this->passing();
}
}
"""
And the class file "src/Message/Fatal/Runtime.php" contains:
"""
<?php
namespace Message\Fatal;
class Runtime
{
public function broken()
{
foo();
}
public function passing()
{
}
}
"""
When I run phpspec
Then I should see "1 passed, 1 broken"
Scenario: Runtime error in spec
Given the spec file "spec/Message/Fatal2/RuntimeSpec.php" contains:
"""
<?php
namespace spec\Message\Fatal2;
use PhpSpec\ObjectBehavior;
class RuntimeSpec extends ObjectBehavior
{
function it_breaks()
{
foo();
}
function it_passes()
{
$this->passing();
}
}
"""
And the class file "src/Message/Fatal2/Runtime.php" contains:
"""
<?php
namespace Message\Fatal2;
class Runtime
{
public function passing()
{
}
}
"""
When I run phpspec
Then I should see "1 passed, 1 broken"

View File

@@ -6,7 +6,7 @@ Feature: Developer uses bootstrap config key in any place
Given the config file contains:
"""
extensions:
- Example1\PhpSpec\LoadsConsoleIoExtension\Extension
Example1\PhpSpec\LoadsConsoleIoExtension\Extension: ~
bootstrap: NotExisting.php
"""
@@ -16,12 +16,12 @@ Feature: Developer uses bootstrap config key in any place
namespace Example1\PhpSpec\LoadsConsoleIoExtension;
use PhpSpec\Extension\ExtensionInterface as PhpSpecExtension;
use PhpSpec\Extension as PhpSpecExtension;
use PhpSpec\ServiceContainer;
class Extension implements PhpSpecExtension
{
public function load(ServiceContainer $container)
public function load(ServiceContainer $container, array $params)
{
$container->get('console.io');
}

View File

@@ -6,7 +6,7 @@ Feature: Developer uses extension
Given the config file contains:
"""
extensions:
- Example1\PhpSpec\MatcherExtension\Extension
Example1\PhpSpec\MatcherExtension\Extension: ~
"""
And the class file "src/Example1/PhpSpec/MatcherExtension/Extension.php" contains:
"""
@@ -14,19 +14,16 @@ Feature: Developer uses extension
namespace Example1\PhpSpec\MatcherExtension;
use PhpSpec\Extension\ExtensionInterface;
use PhpSpec\Extension as PhpSpecExtension;
use PhpSpec\ServiceContainer;
class Extension implements ExtensionInterface
class Extension implements PhpSpecExtension
{
/**
* @param ServiceContainer $container
*/
public function load(ServiceContainer $container)
public function load(ServiceContainer $container, array $params)
{
$container->set('matchers.seven', function (ServiceContainer $c) {
$container->define('matchers.seven', function (ServiceContainer $c) {
return new BeSevenMatcher($c->get('formatter.presenter'));
});
}, ['matchers']);
}
}
@@ -37,21 +34,21 @@ Feature: Developer uses extension
namespace Example1\PhpSpec\MatcherExtension;
use PhpSpec\Formatter\Presenter\PresenterInterface;
use PhpSpec\Formatter\Presenter\Presenter;
use PhpSpec\Exception\Example\FailureException;
use PhpSpec\Matcher\BasicMatcher;
class BeSevenMatcher extends BasicMatcher
{
/**
* @var \PhpSpec\Formatter\Presenter\PresenterInterface
* @var \PhpSpec\Formatter\Presenter\Presenter
*/
private $presenter;
/**
* @param PresenterInterface $presenter
* @param Presenter $presenter
*/
public function __construct(PresenterInterface $presenter)
public function __construct(Presenter $presenter)
{
$this->presenter = $presenter;
}
@@ -63,7 +60,7 @@ Feature: Developer uses extension
*
* @return bool
*/
public function supports($name, $subject, array $arguments)
public function supports(string $name, $subject, array $arguments): bool
{
return 'beSeven' === $name
&& is_int($subject)
@@ -77,7 +74,7 @@ Feature: Developer uses extension
*
* @return bool
*/
protected function matches($subject, array $arguments)
protected function matches($subject, array $arguments): bool
{
return ($subject === 7);
}
@@ -89,7 +86,7 @@ Feature: Developer uses extension
*
* @return FailureException
*/
protected function getFailureException($name, $subject, array $arguments)
protected function getFailureException(string $name, $subject, array $arguments): FailureException
{
return new FailureException(sprintf(
'Seven expected %s to be 7, but it is not.',
@@ -104,7 +101,7 @@ Feature: Developer uses extension
*
* @return FailureException
*/
protected function getNegativeFailureException($name, $subject, array $arguments)
protected function getNegativeFailureException(string $name, $subject, array $arguments): FailureException
{
return new FailureException(sprintf(
'Seven did not expect %s to 7, but it is.',
@@ -158,3 +155,93 @@ Feature: Developer uses extension
"""
When I run phpspec
Then the suite should pass
Scenario: Using an extension with an event listener
Given the config file contains:
"""
extensions:
Example2\PhpSpec\Extensions\EventSubscriberExtension: ~
"""
And the class file "src/Example2/PhpSpec/Extensions/EventSubscriberExtension.php" contains:
"""
<?php
namespace Example2\PhpSpec\Extensions;
use PhpSpec\Extension as PhpSpecExtension;
use PhpSpec\ServiceContainer;
class EventSubscriberExtension implements PhpSpecExtension
{
public function load(ServiceContainer $compositeContainer, array $params)
{
$io = $compositeContainer->get('console.io');
$eventDispatcher = $compositeContainer->get('event_dispatcher');
$eventDispatcher->addSubscriber(new MyEventSubscriber($io));
}
}
"""
And the class file "src/Example2/PhpSpec/Extensions/MyEventSubscriber.php" contains:
"""
<?php
namespace Example2\PhpSpec\Extensions;
use PhpSpec\Event\SuiteEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MyEventSubscriber implements EventSubscriberInterface
{
private $io;
public function __construct($io)
{
$this->io = $io;
}
public static function getSubscribedEvents()
{
return ['afterSuite' => ['afterSuite', 11]];
}
public function afterSuite(SuiteEvent $event)
{
$this->io->writeln('Omg suite ran! :-)');
}
}
"""
And the spec file "spec/Example2/DummySpec.php" contains:
"""
<?php
namespace spec\Example2;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Example2\Dummy;
class DummySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Dummy::class);
}
}
"""
And the class file "src/Example2/Dummy.php" contains:
"""
<?php
namespace Example2;
class Dummy
{
}
"""
When I run phpspec
Then I should see "Omg suite ran! :-)"

View File

@@ -396,7 +396,7 @@ Feature: Developer is shown diffs
"""
method call:
- methodTwo("value")
on Double\Diffs\DiffExample7\ClassBeingMocked\P14 was not expected, expected calls were:
on Double\Diffs\DiffExample7\ClassBeingMocked\P13 was not expected, expected calls were:
- methodOne(exact("value"))
"""
@@ -460,7 +460,7 @@ Feature: Developer is shown diffs
"""
method call:
- methodTwo("another value")
on Double\Diffs\DiffExample8\ClassBeingMocked\P15 was not expected, expected calls were:
on Double\Diffs\DiffExample8\ClassBeingMocked\P14 was not expected, expected calls were:
- methodTwo(exact("value"))
- methodOne(exact("another value"))
"""
@@ -564,3 +564,43 @@ Feature: Developer is shown diffs
+ Integer euismod in nunc nec lobortis",
]
"""
Scenario: Integer diff in verbose mode
Given the spec file "spec/Diffs/DiffExample11/CalculatorSpec.php" contains:
"""
<?php
namespace spec\Diffs\DiffExample11;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class CalculatorSpec extends ObjectBehavior
{
function it_is_equal()
{
$this->calculate()->shouldReturn(2);
}
}
"""
And the class file "src/Diffs/DiffExample11/Calculator.php" contains:
"""
<?php
namespace Diffs\DiffExample11;
class Calculator
{
public function calculate()
{
return 1;
}
}
"""
When I run phpspec with the "verbose" option
Then I should see:
"""
expected [integer:2], but got [integer:1]
"""

View File

@@ -41,7 +41,7 @@ Feature: Use the JUnit formatter
// skipped
function it_does_some_incompatible_things()
{
throw new \PhpSpec\Exception\Example\SkippingException();
throw new \PhpSpec\Exception\Example\SkippingException('skipped');
}
}

View File

@@ -43,7 +43,6 @@ Feature: Developer uses unsupported collaborator type hinting
spec\InvalidUsage\InvalidUsageExample1\StorageSpec::it_can_store_data.
"""
@php:~5.4||~7.0
Scenario: Callable collaborator type hinting
Given the spec file "spec/InvalidUsage/InvalidUsageExample2/InvokerSpec.php" contains:
"""
@@ -85,8 +84,6 @@ Feature: Developer uses unsupported collaborator type hinting
spec\InvalidUsage\InvalidUsageExample2\InvokerSpec::it_invokes_callable.
"""
@php:~7.0
Scenario: Integer collaborator type hinting
Given the spec file "spec/InvalidUsage/InvalidUsageExample3/StorageSpec.php" contains:
"""

View File

@@ -0,0 +1,42 @@
Feature: Developer uses approximately matcher
As a Developer
I want an approximately matcher
In order to verify if two floats can be close
@issue581
Scenario: "Approximately" alias matches using the approximately matcher
Given the spec file "spec/Matchers/FloatApproximatelyExample1/GeoCoordSpec.php" contains:
"""
<?php
namespace spec\Matchers\FloatApproximatelyExample1;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class GeoCoordSpec extends ObjectBehavior
{
function it_should_have_lat_approximate()
{
$this->getLat()->shouldBeApproximately(1.4477, 1.0e-2);
}
}
"""
And the class file "src/Matchers/FloatApproximatelyExample1/GeoCoord.php" contains:
"""
<?php
namespace Matchers\FloatApproximatelyExample1;
class GeoCoord
{
public function getLat()
{
return 1.444444;
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -0,0 +1,99 @@
Feature: Developer uses custom matcher
As a Developer
I want a custom matcher
In order to confirm any custom assertion I need
Scenario: Succesfully register a custom matcher
Given the spec file "spec/Matchers/Custom/MovieSpec.php" contains:
"""
<?php
namespace spec\Matchers\Custom;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class MovieSpec extends ObjectBehavior
{
function it_should_have_some_specific_options_by_default()
{
$this->getEntries()->shouldTotalize(130);
}
}
"""
And the class file "src/Matchers/Custom/TotalizeMatcher.php" contains:
"""
<?php
namespace Matchers\Custom;
use PhpSpec\Matcher\BasicMatcher;
use PhpSpec\Exception\Example\FailureException;
class TotalizeMatcher extends BasicMatcher
{
public function supports(string $name, $subject, array $arguments): bool
{
return 'totalize' === $name &&
is_array($subject) &&
isset($arguments[0]) &&
is_int($arguments[0])
;
}
protected function matches($subject, array $arguments): bool
{
return array_sum($subject) === $arguments[0];
}
protected function getFailureException(string $name, $subject, array $arguments): FailureException
{
return new FailureException(sprintf(
'Expected to totalize %d, but got %d.',
$arguments[0],
array_sum($subject)
));
}
protected function getNegativeFailureException(string $name, $subject, array $arguments): FailureException
{
return new FailureException(sprintf(
'Expected to not totalize %d, but it does.',
$arguments[0]
));
}
}
"""
And the class file "src/Matchers/Custom/Movie.php" contains:
"""
<?php
namespace Matchers\Custom;
class Movie
{
public function getEntries()
{
return [100, 10, 20];
}
}
"""
And the config file contains:
"""
matchers:
- Matchers\Custom\TotalizeMatcher
"""
When I run phpspec
Then the suite should pass
Scenario: Developer adds class that is not Matcher to custom matchers list
Given the config file contains:
"""
matchers:
- ArrayObject
"""
When I run phpspec
Then I should see "Custom matcher ArrayObject must implement PhpSpec\Matcher\Matcher interface, but it does not"

View File

@@ -1,4 +1,4 @@
Feature: Developer uses identity matcher
Feature: Developer uses inline matcher
As a Developer
I want an inline matcher
So I can create expectations in a language closer to the domain I am describing
@@ -21,7 +21,7 @@ Feature: Developer uses identity matcher
$this->shouldBePositive();
}
function getMatchers()
function getMatchers(): array
{
return array ('bePositive' => function($subject) {
return $subject->getTotal() > 0;
@@ -74,7 +74,7 @@ Feature: Developer uses identity matcher
$this->shouldTotal(3);
}
function getMatchers()
function getMatchers() : array
{
return array ('total' => function($subject, $total) {
return $subject->getTotal() === $total;
@@ -127,7 +127,7 @@ Feature: Developer uses identity matcher
$this->shouldDoSomething('abc');
}
function getMatchers()
function getMatchers(): array
{
return array ('doSomething' => function($subject, $param) {
throw new FailureException(sprintf(

View File

@@ -0,0 +1,40 @@
Feature: Developer uses iterate-as matcher
As a Developer
I want an iterate-as matcher
In order to confirm an traversable the expected value for a key
Scenario: "Iterate" alias matches using the iterate-as matcher
Given the spec file "spec/Matchers/IterateExample1/MovieSpec.php" contains:
"""
<?php
namespace spec\Matchers\IterateExample1;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class MovieSpec extends ObjectBehavior
{
function it_should_contain_jane_smith_in_the_cast()
{
$this->getCast()->shouldIterateAs(['supportingRole' => 'Jane Smith', 'leadRole' => 'John Smith']);
}
}
"""
And the class file "src/Matchers/IterateExample1/Movie.php" contains:
"""
<?php
namespace Matchers\IterateExample1;
class Movie
{
public function getCast()
{
yield 'supportingRole' => 'Jane Smith';
yield 'leadRole' => 'John Smith';
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -0,0 +1,39 @@
Feature: Developer uses iterate-as matcher
As a Developer
I want an iterate-like matcher
In order to confirm an traversable the expected loosely-typed value for a key
Scenario: "Iterate" alias matches using the iterate-like matcher
Given the spec file "spec/Matchers/IterateLikeExample1/IterSpec.php" contains:
"""
<?php
namespace spec\Matchers\IterateLikeExample1;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class IterSpec extends ObjectBehavior
{
function it_should_contain_object_in_the_elements()
{
$this->getElements()->shouldIterateLike([ (object)['foo' => 'bar'] ]);
}
}
"""
And the class file "src/Matchers/IterateLikeExample1/Iter.php" contains:
"""
<?php
namespace Matchers\IterateLikeExample1;
class Iter
{
public function getElements()
{
yield (object)['foo' => 'bar'];
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -0,0 +1,41 @@
Feature: Developer uses start-iterate-as matcher
As a Developer
I want an start-iterate-as matcher
In order to confirm an traversable the expected value for a key
Scenario: "StartIterating" alias matches using the start-iterate-as matcher
Given the spec file "spec/Matchers/StartIteratingExample1/MovieSpec.php" contains:
"""
<?php
namespace spec\Matchers\StartIteratingExample1;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class MovieSpec extends ObjectBehavior
{
function it_should_contain_jane_smith_in_the_cast()
{
$this->getCast()->shouldStartIteratingAs(['supportingRole' => 'Jane Smith', 'leadRole' => 'John Smith']);
}
}
"""
And the class file "src/Matchers/StartIteratingExample1/Movie.php" contains:
"""
<?php
namespace Matchers\StartIteratingExample1;
class Movie
{
public function getCast()
{
yield 'supportingRole' => 'Jane Smith';
yield 'leadRole' => 'John Smith';
yield 'supportingRole' => 'Will Smith';
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -213,3 +213,44 @@ Feature: Developer uses throw matcher
"""
When I run phpspec
Then the suite should pass
Scenario: Throw matcher supports Error
Given the spec file "spec/Runner/ThrowExample6/CalculatorSpec.php" contains:
"""
<?php
namespace spec\Runner\ThrowExample6;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class CalculatorSpec extends ObjectBehavior
{
function it_throws_error_during_division_by_zero()
{
$this->shouldThrow(new \DivisionByZeroError())->duringDivide(10, 0);
}
}
"""
And the class file "src/Runner/ThrowExample6/Calculator.php" contains:
"""
<?php
namespace Runner\ThrowExample6;
class Calculator
{
public function divide(int $dividend, int $divider): float
{
if ($divider === 0) {
throw new \DivisionByZeroError();
}
return $dividend / $divider;
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -0,0 +1,40 @@
Feature: Developer uses traversable-contain matcher
As a Developer
I want an traversable-contain matcher
In order to confirm an traversable contains an expected value
Scenario: "Contain" alias matches using the traversable-contain matcher
Given the spec file "spec/Matchers/TraversableContainExample1/MovieSpec.php" contains:
"""
<?php
namespace spec\Matchers\TraversableContainExample1;
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/TraversableContainExample1/Movie.php" contains:
"""
<?php
namespace Matchers\TraversableContainExample1;
class Movie
{
public function getCast()
{
yield 'John Smith';
yield 'Jane Smith';
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -0,0 +1,42 @@
Feature: Developer uses traversable-count matcher
As a Developer
I want an traversable-count matcher
In order to compare an array count against an expectation
Scenario: "HaveCount" alias matches using the traversable-count matcher
Given the spec file "spec/Matchers/TraversableCountExample1/CarSpec.php" contains:
"""
<?php
namespace spec\Matchers\TraversableCountExample1;
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/TraversableCountExample1/Car.php" contains:
"""
<?php
namespace Matchers\TraversableCountExample1;
class Car
{
public function getWheels()
{
yield 'wheel';
yield 'wheel';
yield 'wheel';
yield 'wheel';
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -0,0 +1,40 @@
Feature: Developer uses traversable-key matcher
As a Developer
I want an traversable-key matcher
In order to confirm an array contains an expected key
Scenario: "HaveKey" alias matches using the traversable-key matcher
Given the spec file "spec/Matchers/TraversableKeyExample1/MovieSpec.php" contains:
"""
<?php
namespace spec\Matchers\TraversableKeyExample1;
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/TraversableKeyExample1/Movie.php" contains:
"""
<?php
namespace Matchers\TraversableKeyExample1;
class Movie
{
public function getReleaseDates()
{
yield 'Australia' => '12 April 2013';
yield 'France' => '24 April 2013';
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -0,0 +1,40 @@
Feature: Developer uses traversable-key-value matcher
As a Developer
I want an traversable-key-value matcher
In order to confirm an traversable the expected value for a key
Scenario: "HaveKeyWithValue" alias matches using the traversable-key-value matcher
Given the spec file "spec/Matchers/TraversableKeyValueExample1/MovieSpec.php" contains:
"""
<?php
namespace spec\Matchers\TraversableKeyValueExample1;
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/TraversableKeyValueExample1/Movie.php" contains:
"""
<?php
namespace Matchers\TraversableKeyValueExample1;
class Movie
{
public function getCast()
{
yield 'supportingRole' => 'Jane Smith';
yield 'leadRole' => 'John Smith';
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -0,0 +1,119 @@
Feature: Developer uses trigger matcher
As a Developer
I want a trigger matcher
In order to validate triggered exceptions against my expectations
Scenario: Checking if a deprecated error has been triggered
Given the spec file "spec/Matchers/TriggerExample1/FooSpec.php" contains:
"""
<?php
namespace spec\Matchers\TriggerExample1;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class FooSpec extends ObjectBehavior
{
function it_triggers_an_error_when_calling_something_deprecated()
{
$this->shouldTrigger(E_USER_DEPRECATED)->duringDoDeprecatedStuff();
}
}
"""
And the class file "src/Matchers/TriggerExample1/Foo.php" contains:
"""
<?php
namespace Matchers\TriggerExample1;
class Foo
{
public function doDeprecatedStuff()
{
trigger_error('Foo', E_USER_DEPRECATED);
}
}
"""
When I run phpspec
Then the suite should pass
Scenario: Checking that a deprecated error has the right message
Given the spec file "spec/Matchers/TriggerExample2/FooSpec.php" contains:
"""
<?php
namespace spec\Matchers\TriggerExample3;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class FooSpec extends ObjectBehavior
{
function it_triggers_a_specific_deprecated_error_when_calling_deprecated_method()
{
$this->shouldTrigger(E_USER_DEPRECATED, 'This is deprecated')->duringDoDeprecatedStuff();
}
}
"""
And the class file "src/Matchers/TriggerExample2/Foo.php" contains:
"""
<?php
namespace Matchers\TriggerExample2;
class Foo
{
public function doDeprecatedStuff()
{
trigger_error('This is deprecated', E_USER_DEPRECATED);
}
}
"""
When I run phpspec
Then the suite should pass
Scenario: "Trigger" alias matches using the trigger matcher and let the code continue afterwards
Given the spec file "spec/Matchers/TriggerExample3/FooSpec.php" contains:
"""
<?php
namespace spec\Matchers\TriggerExample3;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class FooSpec extends ObjectBehavior
{
function it_triggers_a_deprecated_error_when_calling_deprecated_method_but_do_not_interrupt()
{
$this->shouldTrigger(E_USER_DEPRECATED, 'This is deprecated')->duringDoDeprecatedStuff(0);
$this->getDeprecated()->shouldBe(0);
}
}
"""
And the class file "src/Matchers/TriggerExample3/Foo.php" contains:
"""
<?php
namespace Matchers\TriggerExample3;
class Foo
{
private $deprecated;
public function getDeprecated()
{
return $this->deprecated;
}
public function doDeprecatedStuff($value)
{
trigger_error('This is deprecated', E_USER_DEPRECATED);
$this->deprecated = $value;
}
}
"""
When I run phpspec
Then the suite should pass

View File

@@ -89,7 +89,6 @@ Feature: Developer is told about pending specs
1 examples (1 passed)
"""
@php:~5.4||~7.0
Scenario: Spec defined in trait does not cause pending
Given the trait file "spec/Runner/PendingExample4/PartialSpecTrait.php" contains:
"""

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -3,12 +3,13 @@
namespace integration\PhpSpec\Console\Prompter;
use PhpSpec\Console\Prompter\Question;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Question\ConfirmationQuestion;
/**
* @requires function \Symfony\Component\Console\Helper\QuestionHelper::ask
*/
class QuestionTest extends \PHPUnit_Framework_TestCase
class QuestionTest extends TestCase
{
/**
* @var \Symfony\Component\Console\Input\InputInterface
@@ -32,9 +33,9 @@ class QuestionTest extends \PHPUnit_Framework_TestCase
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->input = $this->createMock('Symfony\Component\Console\Input\InputInterface');
$this->output = $this->createMock('Symfony\Component\Console\Output\OutputInterface');
$this->questionHelper = $this->createMock('Symfony\Component\Console\Helper\QuestionHelper');
$this->prompter = new Question($this->input, $this->output, $this->questionHelper);
}

View File

@@ -7,8 +7,9 @@ use PhpSpec\CodeAnalysis\TokenizedTypeHintRewriter;
use PhpSpec\Loader\StreamWrapper;
use PhpSpec\Loader\Transformer\InMemoryTypeHintIndex;
use PhpSpec\Loader\Transformer\TypeHintRewriter;
use PHPUnit\Framework\TestCase;
class StreamWrapperTest extends \PHPUnit_Framework_Testcase
class StreamWrapperTest extends TestCase
{
function setUp()
{

View File

@@ -1,7 +1,10 @@
<phpunit bootstrap="vendor/autoload.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.7/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite>
<directory>integration</directory>
<testsuite name="PhpSpec">
<directory suffix="Test.php">integration</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -2,20 +2,20 @@
namespace spec\PhpSpec\CodeAnalysis;
use Phpspec\CodeAnalysis\AccessInspectorInterface;
use Phpspec\CodeAnalysis\AccessInspector;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class MagicAwareAccessInspectorSpec extends ObjectBehavior
{
function let(AccessInspectorInterface $accessInspector)
function let(AccessInspector $accessInspector)
{
$this->beConstructedWith($accessInspector);
}
function it_should_be_an_access_inspector()
{
$this->shouldImplement('PhpSpec\CodeAnalysis\AccessInspectorInterface');
$this->shouldImplement('PhpSpec\CodeAnalysis\AccessInspector');
}
function it_should_detect_a_magic_getter_if_no_value_is_given()
@@ -33,42 +33,42 @@ class MagicAwareAccessInspectorSpec extends ObjectBehavior
$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)
function it_should_not_detect_a_getter_if_there_is_no_magic_getter_and_wrapped_inspector_finds_none(AccessInspector $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)
function it_should_detect_a_getter_if_there_is_no_magic_getter_but_wrapped_inspector_finds_one(AccessInspector $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)
function it_should_not_detect_a_setter_if_there_is_no_magic_setter_and_wrapped_inspector_finds_none(AccessInspector $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)
function it_should_detect_a_setter_if_there_is_no_magic_setter_but_wrapped_inspector_finds_one(AccessInspector $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)
function it_should_detect_a_method_if_there_is_no_magic_caller_and_wrapped_inspector_finds_none(AccessInspector $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)
function it_should_detect_a_method_if_there_is_no_magic_caller_but_wrapped_inspector_finds_one(AccessInspector $accessInspector)
{
$accessInspector->isMethodCallable(new \StdClass(), 'foo')->willReturn(true);

View File

@@ -2,6 +2,7 @@
namespace spec\PhpSpec\CodeAnalysis;
use PhpSpec\CodeAnalysis\DisallowedNonObjectTypehintException;
use PhpSpec\CodeAnalysis\NamespaceResolver;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -32,11 +33,12 @@ class StaticRejectingNamespaceResolverSpec extends ObjectBehavior
$this->resolve('Bar')->shouldReturn('Foo\Bar');
}
function it_does_not_allow_resolution_of_scalar_types()
function it_does_not_allow_resolution_of_non_object_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');
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('int');
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('float');
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('string');
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('bool');
$this->shouldThrow(DisallowedNonObjectTypehintException::class)->duringResolve('iterable');
}
}

View File

@@ -2,7 +2,7 @@
namespace spec\PhpSpec\CodeAnalysis;
use PhpSpec\CodeAnalysis\DisallowedScalarTypehintException;
use PhpSpec\CodeAnalysis\DisallowedNonObjectTypehintException;
use PhpSpec\CodeAnalysis\NamespaceResolver;
use PhpSpec\Loader\Transformer\TypeHintIndex;
use PhpSpec\ObjectBehavior;
@@ -13,6 +13,8 @@ class TokenizedTypeHintRewriterSpec extends ObjectBehavior
function let(TypeHintIndex $typeHintIndex, NamespaceResolver $namespaceResolver)
{
$this->beConstructedWith($typeHintIndex, $namespaceResolver);
$namespaceResolver->resolve(Argument::cetera())->willReturn('someClass');
$namespaceResolver->analyse(Argument::any())->willReturn();
}
function it_is_a_typehint_rewriter()
@@ -156,7 +158,7 @@ class TokenizedTypeHintRewriterSpec extends ObjectBehavior
TypeHintIndex $typeHintIndex,
NamespaceResolver $namespaceResolver
) {
$e = new DisallowedScalarTypehintException();
$e = new DisallowedNonObjectTypehintException();
$namespaceResolver->analyse(Argument::any())->shouldBeCalled();
$namespaceResolver->resolve('FooSpec')->willReturn('FooSpec');

View File

@@ -9,7 +9,7 @@ class VisibilityAccessInspectorSpec extends ObjectBehavior
{
function it_should_be_an_access_inspector()
{
$this->shouldImplement('PhpSpec\CodeAnalysis\AccessInspectorInterface');
$this->shouldImplement('PhpSpec\CodeAnalysis\AccessInspector');
}
function it_should_reject_an_object_if_the_property_does_not_exist()

View File

@@ -3,32 +3,32 @@
namespace spec\PhpSpec\CodeGenerator\Generator;
use PhpSpec\ObjectBehavior;
use PhpSpec\Process\Context\ExecutionContextInterface;
use PhpSpec\Process\Context\ExecutionContext;
use Prophecy\Argument;
use PhpSpec\Console\IO;
use PhpSpec\Console\ConsoleIO;
use PhpSpec\CodeGenerator\TemplateRenderer;
use PhpSpec\Util\Filesystem;
use PhpSpec\Locator\ResourceInterface;
use PhpSpec\Locator\Resource;
class ClassGeneratorSpec extends ObjectBehavior
{
function let(IO $io, TemplateRenderer $tpl, Filesystem $fs, ExecutionContextInterface $executionContext)
function let(ConsoleIO $io, TemplateRenderer $tpl, Filesystem $fs, ExecutionContext $executionContext)
{
$this->beConstructedWith($io, $tpl, $fs, $executionContext);
}
function it_is_a_generator()
{
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\Generator');
}
function it_supports_class_generation(ResourceInterface $resource)
function it_supports_class_generation(Resource $resource)
{
$this->supports($resource, 'class', array())->shouldReturn(true);
}
function it_does_not_support_anything_else(ResourceInterface $resource)
function it_does_not_support_anything_else(Resource $resource)
{
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
}
@@ -39,7 +39,7 @@ class ClassGeneratorSpec extends ObjectBehavior
}
function it_generates_class_from_resource_and_puts_it_into_appropriate_folder(
$io, $tpl, $fs, ResourceInterface $resource
$io, TemplateRenderer $tpl, $fs, Resource $resource
) {
$resource->getName()->willReturn('App');
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
@@ -53,7 +53,7 @@ class ClassGeneratorSpec extends ObjectBehavior
'%namespace_block%' => "\n\nnamespace Acme;",
);
$tpl->render('class', $values)->willReturn(null);
$tpl->render('class', $values)->willReturn('');
$tpl->renderString(Argument::type('string'), $values)->willReturn('generated code');
$fs->pathExists('/project/src/Acme/App.php')->willReturn(false);
@@ -64,7 +64,7 @@ class ClassGeneratorSpec extends ObjectBehavior
}
function it_uses_template_provided_by_templating_system_if_there_is_one(
$io, $tpl, $fs, ResourceInterface $resource
$io, $tpl, $fs, Resource $resource
) {
$resource->getName()->willReturn('App');
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
@@ -88,8 +88,9 @@ class ClassGeneratorSpec extends ObjectBehavior
$this->generate($resource);
}
function it_creates_folder_for_class_if_needed($io, $tpl, $fs, ResourceInterface $resource)
function it_creates_folder_for_class_if_needed($io, TemplateRenderer $tpl, $fs, Resource $resource)
{
$tpl->render('class', Argument::type('array'))->willReturn('rendered string');
$resource->getName()->willReturn('App');
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
$resource->getSrcNamespace()->willReturn('Acme');
@@ -104,7 +105,7 @@ class ClassGeneratorSpec extends ObjectBehavior
}
function it_asks_confirmation_if_class_already_exists(
$io, $tpl, $fs, ResourceInterface $resource
$io, $tpl, $fs, Resource $resource
) {
$resource->getName()->willReturn('App');
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
@@ -119,8 +120,17 @@ class ClassGeneratorSpec extends ObjectBehavior
$this->generate($resource);
}
function it_records_that_class_was_created_in_executioncontext(ResourceInterface $resource, ExecutionContextInterface $executionContext)
{
function it_records_that_class_was_created_in_executioncontext(
Resource $resource,
ExecutionContext $executionContext,
TemplateRenderer $tpl,
Filesystem $fs
) {
$tpl->render('class', Argument::type('array'))->willReturn('rendered string');
$fs->isDirectory('/project/src/Acme')->willReturn(true);
$fs->pathExists('/project/src/Acme/App.php')->willReturn(false);
$fs->putFileContents('/project/src/Acme/App.php', Argument::any())->shouldBeCalled();
$resource->getName()->willReturn('App');
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
$resource->getSrcNamespace()->willReturn('Acme');

View File

@@ -2,38 +2,38 @@
namespace spec\PhpSpec\CodeGenerator\Generator;
use PhpSpec\CodeGenerator\Generator\GeneratorInterface;
use PhpSpec\Console\IO;
use PhpSpec\CodeGenerator\Generator\Generator;
use PhpSpec\Console\ConsoleIO;
use PhpSpec\ObjectBehavior;
use PhpSpec\Locator\ResourceInterface;
use PhpSpec\Locator\Resource;
class ConfirmingGeneratorSpec extends ObjectBehavior
{
function let(IO $io, GeneratorInterface $generator)
function let(ConsoleIO $io, Generator $generator)
{
$this->beConstructedWith($io, 'Question for {CLASSNAME}', $generator);
}
function it_is_a_Generator()
{
$this->shouldHaveType('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
$this->shouldHaveType('PhpSpec\CodeGenerator\Generator\Generator');
}
function it_supports_the_same_generator_as_its_parent(GeneratorInterface $generator, ResourceInterface $resource)
function it_supports_the_same_generator_as_its_parent(Generator $generator, Resource $resource)
{
$generator->supports($resource, 'generation', array())->willReturn(true);
$this->supports($resource, 'generation', array())->shouldReturn(true);
}
function it_has_the_same_priority_as_its_parent(GeneratorInterface $generator)
function it_has_the_same_priority_as_its_parent(Generator $generator)
{
$generator->getPriority()->willReturn(1324);
$this->getPriority()->shouldReturn(1324);
}
function it_does_not_call_the_parent_generate_method_if_the_user_answers_no(GeneratorInterface $generator, ResourceInterface $resource, IO $io)
function it_does_not_call_the_parent_generate_method_if_the_user_answers_no(Generator $generator, Resource $resource, ConsoleIO $io)
{
$resource->getSrcClassname()->willReturn('Namespace/Classname');
@@ -44,7 +44,7 @@ class ConfirmingGeneratorSpec extends ObjectBehavior
$generator->generate($resource, array())->shouldNotHaveBeenCalled();
}
function it_calls_the_parent_generate_method_if_the_user_answers_yes(GeneratorInterface $generator, ResourceInterface $resource, IO $io)
function it_calls_the_parent_generate_method_if_the_user_answers_yes(Generator $generator, Resource $resource, ConsoleIO $io)
{
$resource->getSrcClassname()->willReturn('Namespace/Classname');

View File

@@ -2,32 +2,33 @@
namespace spec\PhpSpec\CodeGenerator\Generator;
use PhpSpec\CodeGenerator\Writer\CodeWriter;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Console\IO;
use PhpSpec\Console\ConsoleIO;
use PhpSpec\CodeGenerator\TemplateRenderer;
use PhpSpec\Util\Filesystem;
use PhpSpec\Locator\ResourceInterface;
use PhpSpec\Locator\Resource;
class MethodGeneratorSpec extends ObjectBehavior
{
function let(IO $io, TemplateRenderer $tpl, Filesystem $fs)
function let(ConsoleIO $io, TemplateRenderer $tpl, Filesystem $fs, CodeWriter $codeWriter)
{
$this->beConstructedWith($io, $tpl, $fs);
$this->beConstructedWith($io, $tpl, $fs, $codeWriter);
}
function it_is_a_generator()
{
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\Generator');
}
function it_supports_method_generation(ResourceInterface $resource)
function it_supports_method_generation(Resource $resource)
{
$this->supports($resource, 'method', array())->shouldReturn(true);
}
function it_does_not_support_anything_else(ResourceInterface $resource)
function it_does_not_support_anything_else(Resource $resource)
{
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
}
@@ -37,7 +38,7 @@ class MethodGeneratorSpec extends ObjectBehavior
$this->getPriority()->shouldReturn(0);
}
function it_generates_class_method_from_resource($io, $tpl, $fs, ResourceInterface $resource)
function it_generates_class_method_from_resource($io, $tpl, $fs, Resource $resource, CodeWriter $codeWriter)
{
$codeWithoutMethod = <<<CODE
<?php
@@ -68,9 +69,11 @@ CODE;
$resource->getSrcFilename()->willReturn('/project/src/Acme/App.php');
$resource->getSrcClassname()->willReturn('Acme\App');
$tpl->render('method', $values)->willReturn(null);
$tpl->render('method', $values)->willReturn('');
$tpl->renderString(Argument::type('string'), $values)->willReturn('METHOD');
$codeWriter->insertMethodLastInClass($codeWithoutMethod, 'METHOD')->willReturn($codeWithMethod);
$fs->getFileContents('/project/src/Acme/App.php')->willReturn($codeWithoutMethod);
$fs->putFileContents('/project/src/Acme/App.php', $codeWithMethod)->shouldBeCalled();

View File

@@ -3,30 +3,31 @@
namespace spec\PhpSpec\CodeGenerator\Generator;
use PhpSpec\CodeGenerator\TemplateRenderer;
use PhpSpec\Console\IO;
use PhpSpec\Locator\ResourceInterface;
use PhpSpec\CodeGenerator\Writer\CodeWriter;
use PhpSpec\Console\ConsoleIO;
use PhpSpec\Locator\Resource;
use PhpSpec\ObjectBehavior;
use PhpSpec\Util\Filesystem;
use Prophecy\Argument;
class NamedConstructorGeneratorSpec extends ObjectBehavior
{
function let(IO $io, TemplateRenderer $tpl, Filesystem $fs)
function let(ConsoleIO $io, TemplateRenderer $tpl, Filesystem $fs, CodeWriter $codeWriter)
{
$this->beConstructedWith($io, $tpl, $fs);
$this->beConstructedWith($io, $tpl, $fs, $codeWriter);
}
function it_is_a_generator()
{
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\Generator');
}
function it_supports_static_constructor_generation(ResourceInterface $resource)
function it_supports_static_constructor_generation(Resource $resource)
{
$this->supports($resource, 'named_constructor', array())->shouldReturn(true);
}
function it_does_not_support_anything_else(ResourceInterface $resource)
function it_does_not_support_anything_else(Resource $resource)
{
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
}
@@ -36,7 +37,7 @@ class NamedConstructorGeneratorSpec extends ObjectBehavior
$this->getPriority()->shouldReturn(0);
}
function it_generates_static_constructor_method_from_resource($io, $tpl, $fs, ResourceInterface $resource)
function it_generates_static_constructor_method_from_resource($io, $tpl, $fs, Resource $resource, CodeWriter $codeWriter)
{
$codeWithoutMethod = <<<CODE
<?php
@@ -71,9 +72,11 @@ CODE;
$resource->getSrcClassname()->willReturn('Acme\App');
$resource->getName()->willReturn('App');
$tpl->render('named_constructor_create_object', $values)->willReturn(null);
$tpl->render('named_constructor_create_object', $values)->willReturn('');
$tpl->renderString(Argument::type('string'), $values)->willReturn('METHOD');
$codeWriter->insertAfterMethod($codeWithoutMethod, '__construct', 'METHOD')->willReturn($codeWithMethod);
$fs->getFileContents('/project/src/Acme/App.php')->willReturn($codeWithoutMethod);
$fs->putFileContents('/project/src/Acme/App.php', $codeWithMethod)->shouldBeCalled();

View File

@@ -2,9 +2,9 @@
namespace spec\PhpSpec\CodeGenerator\Generator;
use PhpSpec\CodeGenerator\Generator\GeneratorInterface;
use PhpSpec\CodeGenerator\Generator\Generator;
use PhpSpec\Event\FileCreationEvent;
use PhpSpec\Locator\ResourceInterface;
use PhpSpec\Locator\Resource;
use PhpSpec\ObjectBehavior;
use PhpSpec\Util\Filesystem;
use Prophecy\Argument;
@@ -14,17 +14,17 @@ class NewFileNotifyingGeneratorSpec extends ObjectBehavior
{
const EVENT_CLASS = 'PhpSpec\Event\FileCreationEvent';
public function let(GeneratorInterface $generator, EventDispatcherInterface $dispatcher, Filesystem $filesystem)
public function let(Generator $generator, EventDispatcherInterface $dispatcher, Filesystem $filesystem)
{
$this->beConstructedWith($generator, $dispatcher, $filesystem);
}
function it_is_a_code_generator()
{
$this->shouldImplement('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
$this->shouldImplement('PhpSpec\CodeGenerator\Generator\Generator');
}
function it_should_proxy_the_support_call_to_the_decorated_object($generator, ResourceInterface $resource)
function it_should_proxy_the_support_call_to_the_decorated_object($generator, Resource $resource)
{
$generator->supports($resource, 'foo', array('bar'))->willReturn(true);
$this->supports($resource, 'foo', array('bar'))->shouldReturn(true);
@@ -36,25 +36,32 @@ class NewFileNotifyingGeneratorSpec extends ObjectBehavior
$this->getPriority()->shouldReturn(5);
}
function it_should_proxy_the_generate_call_to_the_decorated_object($generator, ResourceInterface $resource)
function it_should_proxy_the_generate_call_to_the_decorated_object(Generator $generator, Resource $resource, Filesystem $filesystem)
{
$generator->supports(Argument::cetera())->willReturn(true);
$resource->getSpecFilename()->willReturn('');
$filesystem->pathExists(Argument::any())->willReturn(true);
$generator->generate($resource, array())->shouldBeCalled();
$this->generate($resource, array());
$generator->generate($resource, array())->shouldHaveBeenCalled();
}
function it_should_dispatch_an_event_when_a_file_is_created($dispatcher, $filesystem, ResourceInterface $resource)
function it_should_dispatch_an_event_when_a_file_is_created(Generator $generator, $dispatcher, $filesystem, Resource $resource)
{
$generator->supports(Argument::cetera())->willReturn(false);
$path = '/foo';
$resource->getSrcFilename()->willReturn($path);
$event = new FileCreationEvent($path);
$filesystem->pathExists($path)->willReturn(false, true);
$generator->generate($resource, array())->shouldBeCalled();
$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)
function it_should_dispatch_an_event_with_the_spec_path_when_a_spec_is_created($generator, $dispatcher, $filesystem, Resource $resource)
{
$path = '/foo';
$generator->supports($resource, 'specification', array())->willReturn(true);
@@ -68,7 +75,7 @@ class NewFileNotifyingGeneratorSpec extends ObjectBehavior
$dispatcher->dispatch('afterFileCreation', $event)->shouldHaveBeenCalled();
}
function it_should_check_that_the_file_was_created($generator, $filesystem, ResourceInterface $resource)
function it_should_check_that_the_file_was_created($generator, $filesystem, Resource $resource)
{
$path = '/foo';
$resource->getSrcFilename()->willReturn($path);
@@ -83,11 +90,12 @@ class NewFileNotifyingGeneratorSpec extends ObjectBehavior
$this->generate($resource, array());
}
function it_should_not_dispatch_an_event_if_the_file_was_not_created($dispatcher, $filesystem, ResourceInterface $resource)
function it_should_not_dispatch_an_event_if_the_file_was_not_created(Generator $generator, $dispatcher, $filesystem, Resource $resource)
{
$generator->supports(Argument::cetera())->willReturn(false);
$generator->generate($resource, array())->shouldBeCalled();
$path = '/foo';
$resource->getSrcFilename()->willReturn($path);
$filesystem->pathExists($path)->willReturn(false);
$this->generate($resource, array());
@@ -95,8 +103,10 @@ class NewFileNotifyingGeneratorSpec extends ObjectBehavior
$dispatcher->dispatch('afterFileCreation', Argument::any())->shouldNotHaveBeenCalled();
}
function it_should_not_dispatch_an_event_if_the_file_already_existed($dispatcher, $filesystem, ResourceInterface $resource)
function it_should_not_dispatch_an_event_if_the_file_already_existed(Generator $generator, $dispatcher, $filesystem, Resource $resource)
{
$generator->supports(Argument::cetera())->willReturn(false);
$generator->generate($resource, array())->shouldBeCalled();
$path = '/foo';
$resource->getSrcFilename()->willReturn($path);

View File

@@ -2,37 +2,37 @@
namespace spec\PhpSpec\CodeGenerator\Generator;
use PhpSpec\CodeGenerator\Generator\GeneratorInterface;
use PhpSpec\CodeGenerator\Generator\Generator;
use PhpSpec\ObjectBehavior;
use PhpSpec\Locator\ResourceInterface;
use PhpSpec\Locator\Resource;
class OneTimeGeneratorSpec extends ObjectBehavior
{
function let(GeneratorInterface $generator)
function let(Generator $generator)
{
$this->beConstructedWith($generator);
}
function it_is_a_Generator()
{
$this->shouldHaveType('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
$this->shouldHaveType('PhpSpec\CodeGenerator\Generator\Generator');
}
function it_supports_the_same_generator_as_its_parent(GeneratorInterface $generator, ResourceInterface $resource)
function it_supports_the_same_generator_as_its_parent(Generator $generator, Resource $resource)
{
$generator->supports($resource, 'generation', array())->willReturn(true);
$this->supports($resource, 'generation', array())->shouldReturn(true);
}
function it_has_the_same_priority_as_its_parent(GeneratorInterface $generator)
function it_has_the_same_priority_as_its_parent(Generator $generator)
{
$generator->getPriority()->willReturn(1324);
$this->getPriority()->shouldReturn(1324);
}
function it_calls_the_parent_generate_method_just_once_for_the_same_classname(GeneratorInterface $generator, ResourceInterface $resource)
function it_calls_the_parent_generate_method_just_once_for_the_same_classname(Generator $generator, Resource $resource)
{
$resource->getSrcClassname()->willReturn('Namespace/Classname');
@@ -42,7 +42,7 @@ class OneTimeGeneratorSpec extends ObjectBehavior
$generator->generate($resource, array())->shouldHaveBeenCalledTimes(1);
}
function it_calls_the_parent_generate_method_once_per_each_classname(GeneratorInterface $generator, ResourceInterface $resource)
function it_calls_the_parent_generate_method_once_per_each_classname(Generator $generator, Resource $resource)
{
$resource->getSrcClassname()->willReturn('Namespace/Classname1', 'Namespace/Classname2');

View File

@@ -3,30 +3,30 @@
namespace spec\PhpSpec\CodeGenerator\Generator;
use PhpSpec\CodeGenerator\TemplateRenderer;
use PhpSpec\Console\IO;
use PhpSpec\Console\ConsoleIO;
use PhpSpec\ObjectBehavior;
use PhpSpec\Util\Filesystem;
use Prophecy\Argument;
use PhpSpec\Locator\ResourceInterface;
use PhpSpec\Locator\Resource;
class ReturnConstantGeneratorSpec extends ObjectBehavior
{
function let(IO $io, TemplateRenderer $templates, Filesystem $filesystem)
function let(ConsoleIO $io, TemplateRenderer $templates, Filesystem $filesystem)
{
$this->beConstructedWith($io, $templates, $filesystem);
}
function it_is_a_generator()
{
$this->shouldHaveType('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
$this->shouldHaveType('PhpSpec\CodeGenerator\Generator\Generator');
}
function it_supports_returnConstant_generation(ResourceInterface $resource)
function it_supports_returnConstant_generation(Resource $resource)
{
$this->supports($resource, 'returnConstant', array())->shouldReturn(true);
}
function it_does_not_support_anything_else(ResourceInterface $resource)
function it_does_not_support_anything_else(Resource $resource)
{
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
}

View File

@@ -3,31 +3,32 @@
namespace spec\PhpSpec\CodeGenerator\Generator;
use PhpSpec\ObjectBehavior;
use PhpSpec\Process\Context\ExecutionContext;
use Prophecy\Argument;
use PhpSpec\Console\IO;
use PhpSpec\Console\ConsoleIO;
use PhpSpec\CodeGenerator\TemplateRenderer;
use PhpSpec\Util\Filesystem;
use PhpSpec\Locator\ResourceInterface;
use PhpSpec\Locator\Resource;
class SpecificationGeneratorSpec extends ObjectBehavior
{
function let(IO $io, TemplateRenderer $tpl, Filesystem $fs)
function let(ConsoleIO $io, TemplateRenderer $tpl, Filesystem $fs, ExecutionContext $context)
{
$this->beConstructedWith($io, $tpl, $fs);
$this->beConstructedWith($io, $tpl, $fs, $context);
}
function it_is_a_generator()
{
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\GeneratorInterface');
$this->shouldBeAnInstanceOf('PhpSpec\CodeGenerator\Generator\Generator');
}
function it_supports_specification_generations(ResourceInterface $resource)
function it_supports_specification_generations(Resource $resource)
{
$this->supports($resource, 'specification', array())->shouldReturn(true);
}
function it_does_not_support_anything_else(ResourceInterface $resource)
function it_does_not_support_anything_else(Resource $resource)
{
$this->supports($resource, 'anything_else', array())->shouldReturn(false);
}
@@ -38,7 +39,7 @@ class SpecificationGeneratorSpec extends ObjectBehavior
}
function it_generates_spec_class_from_resource_and_puts_it_into_appropriate_folder(
$io, $tpl, $fs, ResourceInterface $resource
$io, $tpl, $fs, Resource $resource
) {
$resource->getSpecName()->willReturn('AppSpec');
$resource->getSpecFilename()->willReturn('/project/spec/Acme/AppSpec.php');
@@ -54,7 +55,7 @@ class SpecificationGeneratorSpec extends ObjectBehavior
'%subject_class%' => 'App'
);
$tpl->render('specification', $values)->willReturn(null);
$tpl->render('specification', $values)->willReturn('');
$tpl->renderString(Argument::type('string'), $values)->willReturn('generated code');
$fs->pathExists('/project/spec/Acme/AppSpec.php')->willReturn(false);
@@ -65,7 +66,7 @@ class SpecificationGeneratorSpec extends ObjectBehavior
}
function it_uses_template_provided_by_templating_system_if_there_is_one(
$io, $tpl, $fs, ResourceInterface $resource
$io, $tpl, $fs, Resource $resource
) {
$resource->getSpecName()->willReturn('AppSpec');
$resource->getSpecFilename()->willReturn('/project/spec/Acme/AppSpec.php');
@@ -91,8 +92,9 @@ class SpecificationGeneratorSpec extends ObjectBehavior
$this->generate($resource);
}
function it_creates_folder_for_spec_if_needed($io, $tpl, $fs, ResourceInterface $resource)
function it_creates_folder_for_spec_if_needed($io, TemplateRenderer $tpl, $fs, Resource $resource)
{
$tpl->render('specification', Argument::type('array'))->willReturn('rendered string');
$resource->getSpecName()->willReturn('AppAppSpec');
$resource->getSpecFilename()->willReturn('/project/spec/Acme/AppSpec.php');
$resource->getSpecNamespace()->willReturn('spec\Acme');
@@ -108,7 +110,7 @@ class SpecificationGeneratorSpec extends ObjectBehavior
}
function it_asks_confirmation_if_spec_already_exists(
$io, $tpl, $fs, ResourceInterface $resource
$io, $tpl, $fs, Resource $resource
) {
$resource->getSpecName()->willReturn('AppSpec');
$resource->getSpecFilename()->willReturn('/project/spec/Acme/AppSpec.php');

View File

@@ -0,0 +1,75 @@
<?php
namespace spec\PhpSpec\CodeGenerator\Generator;
use PhpSpec\CodeGenerator\Generator\ValidateClassNameSpecificationGenerator;
use PhpSpec\CodeGenerator\Generator\Generator;
use PhpSpec\CodeGenerator\Generator\SpecificationGenerator;
use PhpSpec\Console\ConsoleIO;
use PhpSpec\Locator\Resource;
use PhpSpec\ObjectBehavior;
use PhpSpec\Util\NameChecker;
use Prophecy\Argument;
class ValidateClassNameSpecificationGeneratorSpec extends ObjectBehavior
{
function let(NameChecker $classNameChecker, ConsoleIO $io, Generator $originalGenerator)
{
$this->beConstructedWith($classNameChecker, $io, $originalGenerator);
}
function it_is_initializable()
{
$this->shouldHaveType(ValidateClassNameSpecificationGenerator::class);
}
function it_supports_generation_when_original_generator_supports_it(
Generator $originalGenerator,
Resource $resource
) {
$originalGenerator->supports($resource, '', [])->willReturn(true);
$this->supports($resource, '', [])->shouldReturn(true);
}
function it_does_not_support_generation_when_original_generator_doesnt(
Generator $originalGenerator,
Resource $resource
) {
$originalGenerator->supports($resource, '', [])->willReturn(false);
$this->supports($resource, '', [])->shouldReturn(false);
}
function it_delegates_generation_to_original_generator_for_valid_class_name(
Generator $originalGenerator,
Resource $resource,
NameChecker $classNameChecker
) {
$className = 'Acme\Markdown';
$resource->getSrcClassname()->willReturn($className);
$classNameChecker->isNameValid($className)->willReturn(true);
$originalGenerator->generate($resource, [])->shouldBeCalled();
$this->generate($resource, []);
}
function it_prints_error_and_skips_generation_for_invalid_class_name(
Generator $originalGenerator,
Resource $resource,
NameChecker $classNameChecker,
ConsoleIO $io
) {
$className = 'Acme\Markdown';
$resource->getSrcClassname()->willReturn($className);
$classNameChecker->isNameValid($className)->willReturn(false);
$io->writeBrokenCodeBlock(Argument::containingString('because class name contains reserved keyword'), 2)->shouldBeCalled();
$originalGenerator->generate($resource, [])->shouldNotBeCalled();
$this->generate($resource, []);
}
}

View File

@@ -5,13 +5,13 @@ namespace spec\PhpSpec\CodeGenerator;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\CodeGenerator\Generator\GeneratorInterface;
use PhpSpec\Locator\ResourceInterface;
use PhpSpec\CodeGenerator\Generator\Generator;
use PhpSpec\Locator\Resource;
class GeneratorManagerSpec extends ObjectBehavior
{
function it_uses_registered_generators_to_generate_code(
GeneratorInterface $generator, ResourceInterface $resource
Generator $generator, Resource $resource
) {
$generator->getPriority()->willReturn(0);
$generator->supports($resource, 'specification', array())->willReturn(true);
@@ -22,7 +22,7 @@ class GeneratorManagerSpec extends ObjectBehavior
}
function it_chooses_generator_by_priority(
GeneratorInterface $generator1, GeneratorInterface $generator2, ResourceInterface $resource
Generator $generator1, Generator $generator2, Resource $resource
) {
$generator1->supports($resource, 'class', array('class' => 'CustomLoader'))
->willReturn(true);
@@ -39,7 +39,7 @@ class GeneratorManagerSpec extends ObjectBehavior
$this->generate($resource, 'class', array('class' => 'CustomLoader'));
}
function it_throws_exception_if_no_generator_found(ResourceInterface $resource)
function it_throws_exception_if_no_generator_found(Resource $resource)
{
$this->shouldThrow()->duringGenerate($resource, 'class', array('class' => 'CustomLoader'));
}

View File

@@ -91,8 +91,8 @@ class TemplateRendererSpec extends ObjectBehavior
))->shouldReturn('Template #2. From tpl spec.');
}
function it_returns_null_if_template_is_not_found_in_any_registered_locations()
function it_returns_empty_string_if_template_is_not_found_in_any_registered_locations()
{
$this->render('some_file')->shouldReturn(null);
$this->render('some_file')->shouldReturn('');
}
}

View File

@@ -4,10 +4,16 @@ namespace spec\PhpSpec\CodeGenerator\Writer;
use PhpSpec\Exception\Generator\NamedMethodNotFoundException;
use PhpSpec\ObjectBehavior;
use PhpSpec\Util\ClassFileAnalyser;
use Prophecy\Argument;
class TokenizedCodeWriterSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(new ClassFileAnalyser());
}
function it_should_write_the_content_after_the_last_method()
{
$class = $this->getSingleMethodClass();

View File

@@ -11,7 +11,7 @@ use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class IOSpec extends ObjectBehavior
class ConsoleIOSpec extends ObjectBehavior
{
function let(InputInterface $input, OutputInterface $output, OptionsConfig $config, Prompter $prompter)
{
@@ -27,7 +27,7 @@ class IOSpec extends ObjectBehavior
function it_has_io_interface()
{
$this->shouldHaveType('PhpSpec\IO\IOInterface');
$this->shouldHaveType('PhpSpec\IO\IO');
}
function it_is_code_generation_ready_if_no_input_config_says_otherwise()
@@ -128,7 +128,7 @@ class IOSpec extends ObjectBehavior
$input->getOption('bootstrap')->willReturn(null);
$config->getBootstrapPath()->willReturn(false);
$this->getBootstrapPath()->shouldReturn(false);
$this->getBootstrapPath()->shouldReturn(null);
}
function it_will_report_bootstrap_path_when_one_is_in_the_config_file($input, $config)

View File

@@ -0,0 +1,49 @@
<?php
namespace spec\PhpSpec\Console\Provider;
use PhpSpec\Locator\SrcPathLocator;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
class NamespacesAutocompleteProviderSpec extends ObjectBehavior
{
function let(Finder $finder, SrcPathLocator $locator)
{
$this->beConstructedWith($finder, [$locator]);
$locator->getFullSrcPath()->willReturn('/app/src');
}
function it_returns_empty_array_if_nothing_found($finder)
{
$finder->files()->willReturn($finder);
$finder->name('*.php')->willReturn($finder);
$finder->in(['/app/src'])->willReturn([]);
$this->getNamespaces()->shouldHaveCount(0);
}
function it_returns_namespaces_from_php_files(
$finder,
SplFileInfo $file1,
SplFileInfo $file2,
SplFileInfo $file3
) {
$finder->files()->shouldBeCalled()->willReturn($finder);
$finder->name('*.php')->shouldBeCalled()->willReturn($finder);
$finder->in(['/app/src'])->shouldBeCalled()->willReturn([$file1, $file2, $file3]);
$file1->getContents()->willReturn('<?php namespace App\Foo; class Foo {}');
$file2->getContents()->willReturn('<?php namespace App\Foo; class Bar {}');
$file3->getContents()->willReturn('<?php namespace App\Bar; class Foo {}');
$namespaces = $this->getNamespaces();
$namespaces->shouldHaveCount(3);
$namespaces->shouldContain('App\\');
$namespaces->shouldContain('App\\Foo\\');
$namespaces->shouldContain('App\\Bar\\');
}
}

View File

@@ -23,7 +23,7 @@ class ExampleEventSpec extends ObjectBehavior
function it_is_an_event()
{
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
$this->shouldBeAnInstanceOf('PhpSpec\Event\PhpSpecEvent');
}
function it_provides_a_link_to_example($example)
@@ -43,7 +43,7 @@ class ExampleEventSpec extends ObjectBehavior
function it_provides_a_link_to_time()
{
$this->getTime()->shouldReturn(10);
$this->getTime()->shouldReturn((double)10.0);
}
function it_provides_a_link_to_result()
@@ -55,4 +55,18 @@ class ExampleEventSpec extends ObjectBehavior
{
$this->getException()->shouldReturn($exception);
}
function it_initializes_a_default_result(ExampleNode $example)
{
$this->beConstructedWith($example);
$this->getResult()->shouldReturn($this->PASSED);
}
function it_initializes_a_default_time(ExampleNode $example)
{
$this->beConstructedWith($example);
$this->getTime()->shouldReturn((double)0.0);
}
}

View File

@@ -6,14 +6,14 @@ use PhpSpec\ObjectBehavior;
use PhpSpec\Loader\Suite;
use PhpSpec\Loader\Node\SpecificationNode;
use PhpSpec\Loader\Node\ExampleNode;
use PhpSpec\Matcher\MatcherInterface;
use PhpSpec\Matcher\Matcher;
use Prophecy\Argument;
use Exception;
class ExpectationEventSpec extends ObjectBehavior
{
function let(Suite $suite, SpecificationNode $specification, ExampleNode $example,
MatcherInterface $matcher, $subject, Exception $exception)
Matcher $matcher, $subject, Exception $exception)
{
$method = 'calledMethod';
$arguments = array('methodArguments');
@@ -27,7 +27,7 @@ class ExpectationEventSpec extends ObjectBehavior
function it_is_an_event()
{
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
$this->shouldBeAnInstanceOf('PhpSpec\Event\PhpSpecEvent');
}
function it_provides_a_link_to_matcher($matcher)
@@ -74,4 +74,14 @@ class ExpectationEventSpec extends ObjectBehavior
{
$this->getException()->shouldReturn($exception);
}
function it_initializes_a_default_result(ExampleNode $example, Matcher $matcher, $subject)
{
$method = 'calledMethod';
$arguments = array('methodArguments');
$this->beConstructedWith($example, $matcher, $subject, $method, $arguments);
$this->getResult()->shouldReturn($this->PASSED);
}
}

View File

@@ -21,7 +21,7 @@ class FileCreationEventSpec extends ObjectBehavior
function it_should_be_a_phpspec_event()
{
$this->shouldImplement('PhpSpec\Event\EventInterface');
$this->shouldImplement('PhpSpec\Event\PhpSpecEvent');
}
function it_should_return_the_created_file_path()

View File

@@ -26,7 +26,7 @@ class MethodCallEventSpec extends ObjectBehavior
function it_is_an_event()
{
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
$this->shouldBeAnInstanceOf('PhpSpec\Event\PhpSpecEvent');
}
function it_provides_a_link_to_example($example)

View File

@@ -20,7 +20,7 @@ class SpecificationEventSpec extends ObjectBehavior
function it_is_an_event()
{
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
$this->shouldBeAnInstanceOf('PhpSpec\Event\PhpSpecEvent');
}
function it_provides_a_link_to_suite($suite)
@@ -35,11 +35,25 @@ class SpecificationEventSpec extends ObjectBehavior
function it_provides_a_link_to_time()
{
$this->getTime()->shouldReturn(10);
$this->getTime()->shouldReturn(10.0);
}
function it_provides_a_link_to_result()
{
$this->getResult()->shouldReturn(Example::FAILED);
}
function it_initializes_a_default_result(SpecificationNode $specification)
{
$this->beConstructedWith($specification);
$this->getResult()->shouldReturn(Example::PASSED);
}
function it_initializes_a_default_time(SpecificationNode $specification)
{
$this->beConstructedWith($specification);
$this->getTime()->shouldReturn((double) 0.0);
}
}

View File

@@ -17,7 +17,7 @@ class SuiteEventSpec extends ObjectBehavior
function it_is_an_event()
{
$this->shouldBeAnInstanceOf('Symfony\Component\EventDispatcher\Event');
$this->shouldBeAnInstanceOf('PhpSpec\Event\EventInterface');
$this->shouldBeAnInstanceOf('PhpSpec\Event\PhpSpecEvent');
}
function it_provides_a_link_to_suite($suite)
@@ -27,7 +27,7 @@ class SuiteEventSpec extends ObjectBehavior
function it_provides_a_link_to_time()
{
$this->getTime()->shouldReturn(10);
$this->getTime()->shouldReturn(10.0);
}
function it_provides_a_link_to_result()
@@ -53,4 +53,18 @@ class SuiteEventSpec extends ObjectBehavior
$this->isWorthRerunning()->shouldReturn(false);
}
function it_initializes_a_default_result(Suite $suite)
{
$this->beConstructedWith($suite);
$this->getResult()->shouldReturn(Example::PASSED);
}
function it_initializes_a_default_time(Suite $suite)
{
$this->beConstructedWith($suite);
$this->getTime()->shouldReturn((double) 0.0);
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace spec\PhpSpec\Exception;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ErrorExceptionSpec extends ObjectBehavior
{
private $error;
function let()
{
$this->beConstructedWith($this->error = new \Error('This is an error', 42));
}
function it_is_an_exception()
{
$this->shouldHaveType(\Exception::class);
}
function its_message_is_the_same_as_the_errors()
{
$this->getMessage()->shouldEqual('This is an error');
}
function its_code_is_the_same_as_the_errors()
{
$this->getCode()->shouldEqual(42);
}
function its_previous_is_the_error()
{
$this->getPrevious()->shouldEqual($this->error);
}
function its_line_is_the_same_as_the_errors()
{
$this->getLine()->shouldEqual($this->error->getLine());
}
}

View File

@@ -5,14 +5,14 @@ namespace spec\PhpSpec\Exception;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Formatter\Presenter\PresenterInterface;
use PhpSpec\Formatter\Presenter\Presenter;
class ExceptionFactorySpec extends ObjectBehavior
{
private $fixture;
private $createdException;
function let(PresenterInterface $presenter)
function let(Presenter $presenter)
{
$this->beConstructedWith($presenter);
$this->fixture = new \stdClass();
@@ -23,7 +23,7 @@ class ExceptionFactorySpec extends ObjectBehavior
$this->fixture->property = 'zoo';
}
function it_creates_a_named_constructor_not_found_exception(PresenterInterface $presenter)
function it_creates_a_named_constructor_not_found_exception(Presenter $presenter)
{
$presenter->presentString("{$this->fixture->classname}::{$this->fixture->method}")
->shouldBeCalled()
@@ -38,7 +38,7 @@ class ExceptionFactorySpec extends ObjectBehavior
$this->shouldCreateNamedConstructorNotFoundException();
}
function it_creates_a_method_not_found_exception(PresenterInterface $presenter)
function it_creates_a_method_not_found_exception(Presenter $presenter)
{
$presenter->presentString("{$this->fixture->classname}::{$this->fixture->method}")
->shouldBeCalled()
@@ -53,7 +53,7 @@ class ExceptionFactorySpec extends ObjectBehavior
$this->shouldCreateMethodNotFoundException();
}
function it_creates_a_method_not_visible_exception(PresenterInterface $presenter)
function it_creates_a_method_not_visible_exception(Presenter $presenter)
{
$presenter->presentString("{$this->fixture->classname}::{$this->fixture->method}")
->shouldBeCalled()
@@ -69,7 +69,7 @@ class ExceptionFactorySpec extends ObjectBehavior
$this->shouldCreateMethodNotVisibleException();
}
function it_creates_a_class_not_found_exception(PresenterInterface $presenter)
function it_creates_a_class_not_found_exception(Presenter $presenter)
{
$presenter->presentString("{$this->fixture->classname}")
->shouldBeCalled()
@@ -82,7 +82,7 @@ class ExceptionFactorySpec extends ObjectBehavior
$this->shouldCreateClassNotFoundException();
}
function it_creates_a_property_not_found_exception(PresenterInterface $presenter)
function it_creates_a_property_not_found_exception(Presenter $presenter)
{
$presenter->presentString("{$this->fixture->property}")
->shouldBeCalled()
@@ -96,7 +96,7 @@ class ExceptionFactorySpec extends ObjectBehavior
$this->shouldCreatePropertyNotFoundException();
}
function it_creates_a_calling_method_on_non_object_exception(PresenterInterface $presenter)
function it_creates_a_calling_method_on_non_object_exception(Presenter $presenter)
{
$presenter->presentString("{$this->fixture->method}()")
->shouldBeCalled()
@@ -107,7 +107,7 @@ class ExceptionFactorySpec extends ObjectBehavior
$exception->getMessage()->shouldBe($fixtureMessage);
}
function it_creates_a_setting_property_on_non_object_exception(PresenterInterface $presenter)
function it_creates_a_setting_property_on_non_object_exception(Presenter $presenter)
{
$presenter->presentString("{$this->fixture->property}")
->shouldBeCalled()
@@ -118,7 +118,7 @@ class ExceptionFactorySpec extends ObjectBehavior
$exception->getMessage()->shouldBe($fixtureMessage);
}
function it_creates_an_accessing_property_on_non_object_exception(PresenterInterface $presenter)
function it_creates_an_accessing_property_on_non_object_exception(Presenter $presenter)
{
$presenter->presentString("{$this->fixture->property}")
->shouldBeCalled()

View File

@@ -6,13 +6,13 @@ use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Formatter\BasicFormatter;
use PhpSpec\Formatter\Presenter\PresenterInterface;
use PhpSpec\IO\IOInterface;
use PhpSpec\Formatter\Presenter\Presenter;
use PhpSpec\IO\IO;
use PhpSpec\Listener\StatisticsCollector;
class BasicFormatterSpec extends ObjectBehavior
{
function let(PresenterInterface $presenter, IOInterface $io, StatisticsCollector $stats)
function let(Presenter $presenter, IO $io, StatisticsCollector $stats)
{
$this->beAnInstanceOf('spec\PhpSpec\Formatter\TestableBasicFormatter');
$this->beConstructedWith($presenter, $io, $stats);

View File

@@ -2,11 +2,12 @@
namespace spec\PhpSpec\Formatter;
use PhpSpec\Formatter\Presenter\PresenterInterface;
use PhpSpec\Console\IO;
use PhpSpec\Formatter\Presenter\Presenter;
use PhpSpec\Console\ConsoleIO;
use PhpSpec\Listener\StatisticsCollector;
use PhpSpec\Event\SuiteEvent;
use PhpSpec\Event\ExampleEvent;
use PhpSpec\Loader\Suite;
use PhpSpec\ObjectBehavior;
use PhpSpec\Exception\Example\PendingException;
use PhpSpec\Loader\Node\SpecificationNode;
@@ -16,9 +17,22 @@ use ReflectionFunctionAbstract;
class DotFormatterSpec extends ObjectBehavior
{
function let(PresenterInterface $presenter, IO $io, StatisticsCollector $stats)
function let(
Presenter $presenter,
ConsoleIO $io,
StatisticsCollector $stats,
SuiteEvent $event
)
{
$this->beConstructedWith($presenter, $io, $stats);
$presenter->presentString(Argument::cetera())->willReturn('presented string');
$presenter->presentException(Argument::cetera())->willReturn('presented exception');
$io->isVerbose()->willReturn(false);
$io->askConfirmation(Argument::any())->willReturn(false);
$io->write(Argument::any())->willReturn(null);
$io->writeln(Argument::cetera())->willReturn(null);
$io->getBlockWidth()->willReturn(80);
$event->getTime()->willReturn(10.0);
}
function it_is_a_console_formatter()
@@ -28,7 +42,7 @@ class DotFormatterSpec extends ObjectBehavior
function it_outputs_a_dot_for_a_passed_example(
ExampleEvent $event,
IO $io,
ConsoleIO $io,
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::PASSED);
@@ -40,7 +54,7 @@ class DotFormatterSpec extends ObjectBehavior
function it_outputs_a_p_for_a_pending_example(
ExampleEvent $event,
IO $io,
ConsoleIO $io,
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::PENDING);
@@ -52,7 +66,7 @@ class DotFormatterSpec extends ObjectBehavior
function it_outputs_an_s_for_a_skipped_example(
ExampleEvent $event,
IO $io,
ConsoleIO $io,
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::SKIPPED);
@@ -64,7 +78,7 @@ class DotFormatterSpec extends ObjectBehavior
function it_outputs_an_f_for_a_failed_example(
ExampleEvent $event,
IO $io,
ConsoleIO $io,
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::FAILED);
@@ -76,7 +90,7 @@ class DotFormatterSpec extends ObjectBehavior
function it_outputs_a_b_for_a_broken_example(
ExampleEvent $event,
IO $io,
ConsoleIO $io,
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::BROKEN);
@@ -89,11 +103,15 @@ class DotFormatterSpec extends ObjectBehavior
function it_outputs_the_progress_every_50_examples(
ExampleEvent $exampleEvent,
SuiteEvent $suiteEvent,
IO $io,
StatisticsCollector $stats
ConsoleIO $io,
StatisticsCollector $stats,
Suite $suite
) {
$exampleEvent->getResult()->willReturn(ExampleEvent::PASSED);
$suiteEvent->getSuite()->willReturn(range(1, 100));
$suiteEvent->getSuite()->willReturn($suite);
$suite->count()->willReturn(100);
$stats->getEventsCount()->willReturn(50);
$this->beforeSuite($suiteEvent);
@@ -105,19 +123,25 @@ class DotFormatterSpec extends ObjectBehavior
function it_outputs_exceptions_for_failed_examples(
SuiteEvent $event,
ExampleEvent $pendingEvent,
IO $io,
ConsoleIO $io,
StatisticsCollector $stats,
SpecificationNode $specification,
ExampleNode $example,
ReflectionFunctionAbstract $reflectionFunction
ExampleNode $example
) {
$reflectionFunction->getStartLine()->willReturn(37);
$example->getFunctionReflection()->willReturn($reflectionFunction);
$example->getLineNumber()->willReturn(37);
$example->getTitle()->willReturn('it tests something');
$specification->getTitle()->willReturn('specification title');
$pendingEvent->getException()->willReturn(new PendingException());
$pendingEvent->getSpecification()->willReturn($specification);
$pendingEvent->getExample()->willReturn($example);
$io->isVerbose()->willReturn(false);
$io->getBlockWidth()->willReturn(10);
$io->write(Argument::type('string'))->willReturn();
$io->writeln(Argument::cetera())->willReturn();
$stats->getEventsCount()->willReturn(1);
$stats->getFailedEvents()->willReturn(array());
$stats->getBrokenEvents()->willReturn(array());
@@ -141,7 +165,7 @@ class DotFormatterSpec extends ObjectBehavior
function it_outputs_a_suite_summary(
SuiteEvent $event,
IO $io,
ConsoleIO $io,
StatisticsCollector $stats
) {
$stats->getEventsCount()->willReturn(1);

View File

@@ -7,7 +7,7 @@ use Prophecy\Argument;
use Symfony\Component\Console\Input\InputInterface;
class IOSpec extends ObjectBehavior
class HtmlIOSpec extends ObjectBehavior
{
function let(InputInterface $input)
{

View File

@@ -1,29 +0,0 @@
<?php
namespace spec\PhpSpec\Formatter\Html;
use PhpSpec\Formatter\Presenter\Differ\Differ;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Exception\Exception;
class HtmlPresenterSpec extends ObjectBehavior
{
function let(Differ $differ)
{
$this->beConstructedWith($differ);
}
function it_is_initializable()
{
$this->shouldImplement('PhpSpec\Formatter\Presenter\PresenterInterface');
}
function it_presents_the_code_around_where_exception_was_thrown(Exception $e)
{
$e->getCause()->willReturn(new \ReflectionClass($this));
$this->presentException($e, true);
}
}

View File

@@ -6,8 +6,9 @@ use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Event\ExampleEvent;
use PhpSpec\Formatter\Presenter\PresenterInterface as Presenter;
use PhpSpec\Formatter\Html\Template;
use PhpSpec\Formatter\Presenter\Presenter;
use PhpSpec\Formatter\Template;
use PhpSpec\Formatter\Html\Template as HtmlTemplate;
class ReportFailedItemSpec extends ObjectBehavior
{
@@ -30,7 +31,7 @@ class ReportFailedItemSpec extends ObjectBehavior
$event->getMessage()->willReturn(self::EVENT_MESSAGE);
$event->getBacktrace()->willReturn(self::$BACKTRACE);
$event->getException()->willReturn(new \Exception());
$template->render(Template::DIR.'/Template/ReportFailed.html', array(
$template->render(HtmlTemplate::DIR.'/Template/ReportFailed.html', array(
'title' => self::EVENT_TITLE,
'message' => self::EVENT_MESSAGE,
'backtrace' => self::BACKTRACE,

View File

@@ -7,7 +7,7 @@ use Prophecy\Argument;
use PhpSpec\Event\ExampleEvent;
use PhpSpec\Formatter\Template;
use PhpSpec\Formatter\Presenter\PresenterInterface as Presenter;
use PhpSpec\Formatter\Presenter\Presenter;
class ReportItemFactorySpec extends ObjectBehavior
{

View File

@@ -6,7 +6,8 @@ use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Event\ExampleEvent;
use PhpSpec\Formatter\Html\Template;
use PhpSpec\Formatter\Html\Template as HtmlTemplate;
use PhpSpec\Formatter\Template;
class ReportPassedItemSpec extends ObjectBehavior
{
@@ -20,7 +21,7 @@ class ReportPassedItemSpec extends ObjectBehavior
function it_writes_a_pass_message_for_a_passing_example(Template $template, ExampleEvent $event)
{
$event->getTitle()->willReturn(self::EVENT_TITLE);
$template->render(Template::DIR.'/Template/ReportPass.html', array(
$template->render(HtmlTemplate::DIR.'/Template/ReportPass.html', array(
'title' => self::EVENT_TITLE
))->shouldBeCalled();
$this->write();

View File

@@ -6,7 +6,8 @@ use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Event\ExampleEvent;
use PhpSpec\Formatter\Html\Template;
use PhpSpec\Formatter\Html\Template as HtmlTemplate;
use PhpSpec\Formatter\Template;
class ReportPendingItemSpec extends ObjectBehavior
{
@@ -20,7 +21,7 @@ class ReportPendingItemSpec extends ObjectBehavior
function it_writes_a_pass_message_for_a_passing_example(Template $template, ExampleEvent $event)
{
$event->getTitle()->willReturn(self::EVENT_TITLE);
$template->render(Template::DIR.'/Template/ReportPending.html', array(
$template->render(HtmlTemplate::DIR.'/Template/ReportPending.html', array(
'title' => self::EVENT_TITLE,
'pendingExamplesCount' => 1
))->shouldBeCalled();

View File

@@ -5,11 +5,11 @@ namespace spec\PhpSpec\Formatter\Html;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\IO\IOInterface;
use PhpSpec\IO\IO;
class TemplateSpec extends ObjectBehavior
{
function let(IOInterface $io)
function let(IO $io)
{
$this->beConstructedWith($io);
}

View File

@@ -2,14 +2,14 @@
namespace spec\PhpSpec\Formatter;
use PhpSpec\IO\IO;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Event\ExampleEvent;
use PhpSpec\Formatter\Html\IO;
use PhpSpec\Formatter\Html\ReportItem;
use PhpSpec\Formatter\Html\ReportItemFactory;
use PhpSpec\Formatter\Presenter\PresenterInterface as Presenter;
use PhpSpec\Formatter\Presenter\Presenter;
use PhpSpec\Listener\StatisticsCollector;
class HtmlFormatterSpec extends ObjectBehavior

View File

@@ -4,8 +4,8 @@ namespace spec\PhpSpec\Formatter;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Formatter\Presenter\PresenterInterface;
use PhpSpec\IO\IOInterface;
use PhpSpec\Formatter\Presenter\Presenter;
use PhpSpec\IO\IO;
use PhpSpec\Listener\StatisticsCollector;
use PhpSpec\Event\SpecificationEvent;
use PhpSpec\Event\ExampleEvent;
@@ -16,8 +16,8 @@ use PhpSpec\Exception\Example\SkippingException;
class JUnitFormatterSpec extends ObjectBehavior
{
function let(
PresenterInterface $presenter,
IOInterface $io,
Presenter $presenter,
IO $io,
StatisticsCollector $stats
) {
$this->beConstructedWith($presenter, $io, $stats);

View File

@@ -9,7 +9,7 @@ class ArrayEngineSpec extends ObjectBehavior
{
function it_is_a_diff_engine()
{
$this->shouldBeAnInstanceOf('PhpSpec\Formatter\Presenter\Differ\EngineInterface');
$this->shouldBeAnInstanceOf('PhpSpec\Formatter\Presenter\Differ\DifferEngine');
}
function it_supports_arrays()

View File

@@ -3,12 +3,12 @@
namespace spec\PhpSpec\Formatter\Presenter\Differ;
use PhpSpec\ObjectBehavior;
use PhpSpec\Formatter\Presenter\Differ\EngineInterface;
use PhpSpec\Formatter\Presenter\Differ\DifferEngine;
class DifferSpec extends ObjectBehavior
{
function it_chooses_proper_engine_based_on_values(
EngineInterface $engine1, EngineInterface $engine2
DifferEngine $engine1, DifferEngine $engine2
) {
$engine1->supports('string1', 'string2')->willReturn(true);
$engine2->supports('string1', 'string2')->willReturn(false);
@@ -30,7 +30,7 @@ class DifferSpec extends ObjectBehavior
$this->compare(1, 2)->shouldReturn(null);
}
function its_constructor_allows_a_list_of_engines(EngineInterface $engine)
function its_constructor_allows_a_list_of_engines(DifferEngine $engine)
{
$this->beConstructedWith(array($engine));
$engine->supports('string1', 'string2')->willReturn(true);

View File

@@ -16,7 +16,7 @@ class ObjectEngineSpec extends ObjectBehavior
function it_is_a_differ_engine()
{
$this->shouldHaveType('PhpSpec\Formatter\Presenter\Differ\EngineInterface');
$this->shouldHaveType('PhpSpec\Formatter\Presenter\Differ\DifferEngine');
}
function it_does_not_support_scalars()

View File

@@ -2,13 +2,14 @@
namespace spec\PhpSpec\Formatter\Presenter\Differ;
use PhpSpec\Exception\Example\FailureException;
use PhpSpec\ObjectBehavior;
class StringEngineSpec extends ObjectBehavior
{
function it_is_a_diff_engine()
{
$this->shouldBeAnInstanceOf('PhpSpec\Formatter\Presenter\Differ\EngineInterface');
$this->shouldBeAnInstanceOf('PhpSpec\Formatter\Presenter\Differ\DifferEngine');
}
function it_supports_string_values()
@@ -26,6 +27,21 @@ class StringEngineSpec extends ObjectBehavior
</code>
DIFF;
$this->compare('string1', 'string2')->shouldReturn($expected);
$this->compare('string1', 'string2')->shouldBeEqualRegardlessOfLineEndings($expected);
}
public function getMatchers() : array
{
return [
'beEqualRegardlessOfLineEndings' => function ($actual, $expected) {
$actual = str_replace("\r", '', $actual);
if ($actual !== $expected) {
throw new FailureException('Strings are not equal.');
}
return true;
}
];
}
}

View File

@@ -1,145 +0,0 @@
<?php
namespace spec\PhpSpec\Formatter\Presenter;
use PhpSpec\ObjectBehavior;
use PhpSpec\Formatter\Presenter\Differ\Differ;
use PhpSpec\Wrapper\Subject;
class StringPresenterSpec extends ObjectBehavior
{
function let(Differ $differ)
{
$this->beConstructedWith($differ);
}
function it_presents_short_string_in_quotes()
{
$this->presentValue('some_string')->shouldReturn('"some_string"');
}
function it_presents_long_string_in_quotes_but_trimmed()
{
$this->presentValue('some_string_longer_than_twenty_five_chars')
->shouldReturn('"some_string_longer_than_t..."');
}
function it_presents_only_first_line_of_multiline_string()
{
$this->presentValue("some\nmultiline\nvalue")->shouldReturn('"some..."');
}
function it_presents_simple_type_as_typed_value()
{
$this->presentValue(42)->shouldReturn('[integer:42]');
$this->presentValue(42.0)->shouldReturn('[double:42]');
}
function it_presents_object_as_classname()
{
$this->presentValue(new \stdClass())->shouldReturn('[obj:stdClass]');
}
function it_presents_array_as_elements_count()
{
$this->presentValue(array(1, 2, 3))->shouldReturn('[array:3]');
}
function it_presents_boolean_as_string()
{
$this->presentValue(true)->shouldReturn('true');
$this->presentValue(false)->shouldReturn('false');
}
function it_presents_closure_as_type()
{
$this->presentValue(function () {})->shouldReturn('[closure]');
}
function it_presents_exception_as_class_with_constructor()
{
$this->presentValue(new \RuntimeException('message'))
->shouldReturn('[exc:RuntimeException("message")]');
}
function it_presents_function_callable_as_string()
{
$this->presentValue('date')
->shouldReturn('[date()]');
}
function it_presents_method_as_string(WithMethod $object)
{
$className = get_class($object->getWrappedObject());
$this->presentValue(array($object, 'specMethod'))
->shouldReturn(sprintf('[obj:%s]::specMethod()', $className));
}
function it_presents_magic_method_as_string(WithMagicCall $object)
{
$className = get_class($object->getWrappedObject());
$this->presentValue(array($object, 'undefinedMethod'))
->shouldReturn(sprintf('[obj:%s]::undefinedMethod()', $className));
}
function it_presents_static_method_as_string(WithMethod $object)
{
$className = get_class($object->getWrappedObject());
$this->presentValue(array($className, 'specMethod'))
->shouldReturn(sprintf('%s::specMethod()', $className));
}
function it_presents_static_magic_method_as_string()
{
$className = __NAMESPACE__ . '\\WithStaticMagicCall';
$this->presentValue(array($className, 'undefinedMethod'))
->shouldReturn(sprintf('%s::undefinedMethod()', $className));
}
function it_presents_invokable_object_as_string(WithMagicInvoke $object)
{
$className = get_class($object->getWrappedObject());
$this->presentValue($object)
->shouldReturn(sprintf('[obj:%s]', $className));
}
function it_presents_string_as_string()
{
$this->presentString('some string')->shouldReturn('some string');
}
}
class WithMethod
{
function specMethod()
{
}
}
class WithStaticMethod
{
function specMethod()
{
}
}
class WithMagicInvoke
{
function __invoke()
{
}
}
class WithStaticMagicCall
{
static function __callStatic($method, $name)
{
}
}
class WithMagicCall
{
function __call($method, $name)
{
}
}

View File

@@ -1,24 +0,0 @@
<?php
namespace spec\PhpSpec\Formatter\Presenter;
use PhpSpec\ObjectBehavior;
use PhpSpec\Formatter\Presenter\Differ\Differ;
class TaggedPresenterSpec extends ObjectBehavior
{
function let(Differ $differ)
{
$this->beConstructedWith($differ);
}
function it_wraps_value_into_tags()
{
$this->presentValue('string')->shouldReturn('<value>"string"</value>');
}
function it_wraps_string_into_tags()
{
$this->presentString('string')->shouldReturn('<value>string</value>');
}
}

View File

@@ -2,6 +2,7 @@
namespace spec\PhpSpec\Formatter\Presenter\Value;
use PhpSpec\Exception\ErrorException;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
@@ -22,4 +23,10 @@ class BaseExceptionTypePresenterSpec extends ObjectBehavior
$this->present(new \Exception('foo'))
->shouldReturn('[exc:Exception("foo")]');
}
function it_should_present_an_error_as_a_string()
{
$this->present(new ErrorException(new \Error('foo')))
->shouldReturn('[err:Error("foo")]');
}
}

View File

@@ -2,18 +2,21 @@
namespace spec\PhpSpec\Formatter;
use PhpSpec\Console\IO;
use PhpSpec\Console\ConsoleIO;
use PhpSpec\Event\ExampleEvent;
use PhpSpec\Formatter\Presenter\PresenterInterface;
use PhpSpec\Formatter\Presenter\Presenter;
use PhpSpec\Listener\StatisticsCollector;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ProgressFormatterSpec extends ObjectBehavior
{
function let(PresenterInterface $presenter, IO $io, StatisticsCollector $stats)
function let(Presenter $presenter, ConsoleIO $io, StatisticsCollector $stats)
{
$this->beConstructedWith($presenter, $io, $stats);
$io->getBlockWidth()->willReturn(80);
$io->isDecorated()->willReturn(false);
$io->writeTemp(Argument::cetera())->willReturn();
}
function it_is_an_event_subscriber()
@@ -21,7 +24,7 @@ class ProgressFormatterSpec extends ObjectBehavior
$this->shouldHaveType('Symfony\Component\EventDispatcher\EventSubscriberInterface');
}
function it_outputs_progress_as_0_when_0_examples_have_run(ExampleEvent $event, IO $io, StatisticsCollector $stats)
function it_outputs_progress_as_0_when_0_examples_have_run(ExampleEvent $event, ConsoleIO $io, StatisticsCollector $stats)
{
$stats->getEventsCount()->willReturn(0);
$stats->getCountsHash()->willReturn(array(
@@ -34,13 +37,16 @@ class ProgressFormatterSpec extends ObjectBehavior
$stats->getTotalSpecs()->willReturn(0);
$stats->getTotalSpecsCount()->willReturn(0);
$this->afterExample($event);
$io->isDecorated()->willReturn(false);
$io->getBlockWidth()->willReturn(0);
$expected = '/ skipped: 0% / pending: 0% / passed: 0% / failed: 0% / broken: 0% / 0 examples';
$io->writeTemp($expected)->shouldHaveBeenCalled();
$io->writeTemp($expected)->shouldBeCalled();
$this->afterExample($event);
}
function it_outputs_progress_as_0_when_0_examples_have_passed(ExampleEvent $event, IO $io, StatisticsCollector $stats)
function it_outputs_progress_as_0_when_0_examples_have_passed(ExampleEvent $event, ConsoleIO $io, StatisticsCollector $stats)
{
$stats->getEventsCount()->willReturn(1);
$stats->getCountsHash()->willReturn(array(
@@ -53,13 +59,16 @@ class ProgressFormatterSpec extends ObjectBehavior
$stats->getTotalSpecs()->willReturn(1);
$stats->getTotalSpecsCount()->willReturn(1);
$this->afterExample($event);
$io->isDecorated()->willReturn(false);
$io->getBlockWidth()->willReturn(0);
$expected = '/ skipped: 0% / pending: 0% / passed: 100% / failed: 0% / broken: 0% / 1 examples';
$io->writeTemp($expected)->shouldHaveBeenCalled();
$io->writeTemp($expected)->shouldBeCalled();
$this->afterExample($event);
}
function it_outputs_progress_as_100_when_1_of_3_examples_have_passed(ExampleEvent $event, IO $io, StatisticsCollector $stats)
function it_outputs_progress_as_100_when_1_of_3_examples_have_passed(ExampleEvent $event, ConsoleIO $io, StatisticsCollector $stats)
{
$stats->getEventsCount()->willReturn(1);
$stats->getCountsHash()->willReturn(array(
@@ -72,13 +81,16 @@ class ProgressFormatterSpec extends ObjectBehavior
$stats->getTotalSpecs()->willReturn(1);
$stats->getTotalSpecsCount()->willReturn(3);
$this->afterExample($event);
$io->isDecorated()->willReturn(false);
$io->getBlockWidth()->willReturn(0);
$expected = '/ skipped: 0% / pending: 0% / passed: 100% / failed: 0% / broken: 0% / 1 examples';
$io->writeTemp($expected)->shouldHaveBeenCalled();
$io->writeTemp($expected)->shouldBeCalled();
$this->afterExample($event);
}
function it_outputs_progress_as_33_when_3_of_3_examples_have_run_and_one_passed(ExampleEvent $event, IO $io, StatisticsCollector $stats)
function it_outputs_progress_as_33_when_3_of_3_examples_have_run_and_one_passed(ExampleEvent $event, ConsoleIO $io, StatisticsCollector $stats)
{
$stats->getEventsCount()->willReturn(3);
$stats->getCountsHash()->willReturn(array(
@@ -91,9 +103,13 @@ class ProgressFormatterSpec extends ObjectBehavior
$stats->getTotalSpecs()->willReturn(3);
$stats->getTotalSpecsCount()->willReturn(3);
$this->afterExample($event);
$io->isDecorated()->willReturn(false);
$io->getBlockWidth()->willReturn(0);
$io->isVerbose()->willReturn(false);
$expected = '/ skipped: 0% / pending: 0% / passed: 33% / failed: 66% / broken: 0% / 3 examples';
$io->writeTemp($expected)->shouldHaveBeenCalled();
$io->writeTemp($expected)->shouldBeCalled();
$this->afterExample($event);
}
}

Some files were not shown because too many files have changed in this diff Show More