pax_global_header00006660000000000000000000000064137026301250014511gustar00rootroot0000000000000052 comment=6cd96e3d42412ac0fa049a8e3d7eb995ade7e338 php-phpspec-prophecy-phpunit-2.0.1/000077500000000000000000000000001370263012500172545ustar00rootroot00000000000000php-phpspec-prophecy-phpunit-2.0.1/.gitignore000066400000000000000000000000411370263012500212370ustar00rootroot00000000000000vendor composer.lock phpunit.xml php-phpspec-prophecy-phpunit-2.0.1/.travis.yml000066400000000000000000000004331370263012500213650ustar00rootroot00000000000000language: php sudo: false php: - 7.3 - 7.4 jobs: include: - php: nightly env: COMPOSER_FLAGS='--ignore-platform-reqs' allow_failures: - php: nightly install: composer update $COMPOSER_FLAGS script: ./vendor/bin/phpunit --coverage-text php-phpspec-prophecy-phpunit-2.0.1/CHANGES.md000066400000000000000000000010221370263012500206410ustar00rootroot00000000000000# 2.0.1 / 2020-07-09 Add support for PHP 8 # 2.0.0 / 2020-04-07 Rewrite of the library for PHPUnit 9.1+, with a new API based on a trait rather than a base class. 1.1.0 / 2015-02-09 ================== * Remove the requirement to call the parent ``setUp`` method * Add the assertion count for predictions to be compatible with PHPUnit strict mode 1.0.1 / 2014-03-04 ================== * Marked the ``ProphecyTestCase`` as abstract to avoid PhpUnit to try running it 1.0.0 / 2013-07-04 ================== * Initial release php-phpspec-prophecy-phpunit-2.0.1/CONTRIBUTING.md000066400000000000000000000012021370263012500215000ustar00rootroot00000000000000Contributing ------------ Prophecy is an open source, community-driven project. If you'd like to contribute, feel free to do this, but remember to follow this few simple rules: - Make your feature addition or bug fix, - Add test for any changes you're making (bugfixes or additions) (please look into the `Tests/` folder for some examples). This is important so we don't break it in a future version unintentionally, - Commit your code, but do not mess with `CHANGES.md`, Running tests ------------- Make sure that you don't break anything with your changes by running: ```bash $> composer install --dev --prefer-dist $> phpunit ``` php-phpspec-prophecy-phpunit-2.0.1/LICENSE000066400000000000000000000020661370263012500202650ustar00rootroot00000000000000Copyright (c) 2013 Christophe Coevoet Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. php-phpspec-prophecy-phpunit-2.0.1/README.md000066400000000000000000000027711370263012500205420ustar00rootroot00000000000000# Prophecy [![Build Status](https://travis-ci.org/phpspec/prophecy-phpunit.png?branch=master)](https://travis-ci.org/phpspec/prophecy-phpunit) Prophecy PhpUnit integrates the [Prophecy](https://github.com/phpspec/prophecy) mocking library with [PHPUnit](https://phpunit.de) to provide an easier mocking in your testsuite. ## Installation ### Prerequisites Prophecy PhpUnit requires PHP 7.3 or greater. Prophecy PhpUnit requires PHPUnit 9.1 or greater. Older versions of PHPUnit are providing the Prophecy integration themselves. ### Setup through composer ```bash $> composer require --dev phpspec/prophecy-phpunit ``` You can read more about Composer on its [official webpage](https://getcomposer.org). ## How to use it The trait ``ProphecyTrait`` provides a method ``prophesize($classOrInterface = null)`` to use Prophecy. For the usage of the Prophecy doubles, please refer to the [Prophecy documentation](https://github.com/phpspec/prophecy). Below is a usage example: ```php prophesize(Hasher::class); $user = new User($hasher->reveal()); $hasher->generateHash($user, 'qwerty')->willReturn('hashed_pass'); $user->setPassword('qwerty'); $this->assertEquals('hashed_pass', $user->getPassword()); } } ``` php-phpspec-prophecy-phpunit-2.0.1/composer.json000066400000000000000000000016251370263012500220020ustar00rootroot00000000000000{ "name": "phpspec/prophecy-phpunit", "description": "Integrating the Prophecy mocking library in PHPUnit test cases", "keywords": ["Phpunit", "Prophecy"], "homepage": "http://phpspec.net", "type": "library", "license": "MIT", "authors": [ { "name": "Christophe Coevoet", "email": "stof@notk.org" } ], "minimum-stability": "dev", "prefer-stable": true, "require": { "php": "^7.3 || ^8", "phpspec/prophecy": "^1.3", "phpunit/phpunit":"^9.1" }, "autoload": { "psr-4": { "Prophecy\\PhpUnit\\": "src" } }, "autoload-dev": { "psr-4": { "Prophecy\\PhpUnit\\Tests\\Fixtures\\": "fixtures", "Prophecy\\PhpUnit\\Tests\\": "tests" } }, "extra": { "branch-alias": { "dev-master": "2.0-dev" } } } php-phpspec-prophecy-phpunit-2.0.1/fixtures/000077500000000000000000000000001370263012500211255ustar00rootroot00000000000000php-phpspec-prophecy-phpunit-2.0.1/fixtures/Error.php000066400000000000000000000005111370263012500227240ustar00rootroot00000000000000prophesize('stdClass'); $prophecy->talk()->willReturn('Hello world!'); } } php-phpspec-prophecy-phpunit-2.0.1/fixtures/MockFailure.php000066400000000000000000000006371370263012500240450ustar00rootroot00000000000000prophesize('DateTime'); $prophecy->format('Y-m-d')->shouldBeCalledTimes(2); $double = $prophecy->reveal(); $double->format('Y-m-d'); } } php-phpspec-prophecy-phpunit-2.0.1/fixtures/SpyFailure.php000066400000000000000000000005611370263012500237230ustar00rootroot00000000000000prophesize('DateTime'); $prophecy->reveal(); $prophecy->format('Y-m-d')->shouldHaveBeenCalled(); } } php-phpspec-prophecy-phpunit-2.0.1/fixtures/Success.php000066400000000000000000000006251370263012500232510ustar00rootroot00000000000000prophesize('DateTime'); $prophecy->format('Y-m-d')->shouldBeCalled(); $double = $prophecy->reveal(); $double->format('Y-m-d'); } } php-phpspec-prophecy-phpunit-2.0.1/phpunit.xml.dist000066400000000000000000000006061370263012500224310ustar00rootroot00000000000000 ./tests/ ./src php-phpspec-prophecy-phpunit-2.0.1/src/000077500000000000000000000000001370263012500200435ustar00rootroot00000000000000php-phpspec-prophecy-phpunit-2.0.1/src/ProphecyTrait.php000066400000000000000000000053031370263012500233520ustar00rootroot00000000000000recordDoubledType($classOrInterface); } return $this->getProphet()->prophesize($classOrInterface); } /** * @postCondition */ protected function verifyProphecyDoubles(): void { if ($this->prophet === null) { return; } try { $this->prophet->checkPredictions(); } catch (PredictionException $e) { throw new AssertionFailedError($e->getMessage()); } finally { $this->countProphecyAssertions(); } } /** * @after */ protected function tearDownProphecy(): void { if (null !== $this->prophet && !$this->prophecyAssertionsCounted) { // Some Prophecy assertions may have been done in tests themselves even when a failure happened before checking mock objects. $this->countProphecyAssertions(); } $this->prophet = null; } /** * @internal */ private function countProphecyAssertions(): void { \assert($this instanceof TestCase); $this->prophecyAssertionsCounted = true; foreach ($this->prophet->getProphecies() as $objectProphecy) { foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) { foreach ($methodProphecies as $methodProphecy) { \assert($methodProphecy instanceof MethodProphecy); $this->addToAssertionCount(\count($methodProphecy->getCheckedPredictions())); } } } } /** * @internal */ private function getProphet(): Prophet { if ($this->prophet === null) { $this->prophet = new Prophet; } return $this->prophet; } } php-phpspec-prophecy-phpunit-2.0.1/tests/000077500000000000000000000000001370263012500204165ustar00rootroot00000000000000php-phpspec-prophecy-phpunit-2.0.1/tests/ProphecyTraitTest.php000066400000000000000000000044651370263012500245750ustar00rootroot00000000000000run(); $this->assertSame(0, $result->errorCount()); $this->assertSame(0, $result->failureCount()); $this->assertCount(1, $result); $this->assertSame(1, $test->getNumAssertions()); $this->assertSame(BaseTestRunner::STATUS_PASSED, $test->getStatus()); } public function testSpyPredictionFailure(): void { $test = new SpyFailure('testMethod'); $result = $test->run(); $this->assertSame(0, $result->errorCount()); $this->assertSame(1, $result->failureCount()); $this->assertCount(1, $result); $this->assertSame(1, $test->getNumAssertions()); $this->assertSame(BaseTestRunner::STATUS_FAILURE, $test->getStatus()); } public function testMockPredictionFailure(): void { $test = new MockFailure('testMethod'); $result = $test->run(); $this->assertSame(0, $result->errorCount()); $this->assertSame(1, $result->failureCount()); $this->assertCount(1, $result); $this->assertSame(1, $test->getNumAssertions()); $this->assertSame(BaseTestRunner::STATUS_FAILURE, $test->getStatus()); } public function testDoublingError(): void { $test = new Error('testMethod'); $result = $test->run(); $this->assertSame(1, $result->errorCount()); $this->assertSame(0, $result->failureCount()); $this->assertCount(1, $result); $this->assertSame(0, $test->getNumAssertions()); $this->assertSame(BaseTestRunner::STATUS_ERROR, $test->getStatus()); } }