diff --git a/composer.json b/composer.json index b019292..157c375 100644 --- a/composer.json +++ b/composer.json @@ -26,8 +26,6 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.22", - "jangregor/phpstan-prophecy": "^1.0", - "phpspec/prophecy-phpunit": "^2.0", "phpunit/php-code-coverage": "^9.2", "phpunit/phpunit": "^9.5", "psr/cache": "^3", diff --git a/composer.lock b/composer.lock index f886f95..8c4bdb9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f0e3df385c9f4c11fc0701ba0d81491a", + "content-hash": "99313d2d3b3beeba954951f388c3b90f", "packages": [ { "name": "guzzlehttp/guzzle", @@ -1991,53 +1991,6 @@ } ], "packages-dev": [ - { - "name": "doctrine/deprecations", - "version": "1.1.2", - "source": { - "type": "git", - "url": "https://github.com/doctrine/deprecations.git", - "reference": "4f2d4f2836e7ec4e7a8625e75c6aa916004db931" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/4f2d4f2836e7ec4e7a8625e75c6aa916004db931", - "reference": "4f2d4f2836e7ec4e7a8625e75c6aa916004db931", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0" - }, - "require-dev": { - "doctrine/coding-standard": "^9", - "phpstan/phpstan": "1.4.10 || 1.10.15", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "psalm/plugin-phpunit": "0.18.4", - "psr/log": "^1 || ^2 || ^3", - "vimeo/psalm": "4.30.0 || 5.12.0" - }, - "suggest": { - "psr/log": "Allows logging deprecations via PSR-3 logger implementation" - }, - "type": "library", - "autoload": { - "psr-4": { - "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", - "homepage": "https://www.doctrine-project.org/", - "support": { - "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/1.1.2" - }, - "time": "2023-09-27T20:04:15+00:00" - }, { "name": "doctrine/instantiator", "version": "2.0.0", @@ -2108,71 +2061,6 @@ ], "time": "2022-12-30T00:23:10+00:00" }, - { - "name": "jangregor/phpstan-prophecy", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/Jan0707/phpstan-prophecy.git", - "reference": "2bc7ca9460395690c6bf7332bdfb2f25d5cae8e0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Jan0707/phpstan-prophecy/zipball/2bc7ca9460395690c6bf7332bdfb2f25d5cae8e0", - "reference": "2bc7ca9460395690c6bf7332bdfb2f25d5cae8e0", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^1.0.0" - }, - "conflict": { - "phpspec/prophecy": "<1.7.0,>=2.0.0", - "phpunit/phpunit": "<6.0.0,>=10.0.0" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.1.1", - "ergebnis/license": "^1.0.0", - "ergebnis/php-cs-fixer-config": "~2.2.0", - "phpspec/prophecy": "^1.7.0", - "phpunit/phpunit": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0" - }, - "type": "phpstan-extension", - "extra": { - "phpstan": { - "includes": [ - "extension.neon" - ] - } - }, - "autoload": { - "psr-4": { - "JanGregor\\Prophecy\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jan Gregor Emge-Triebel", - "email": "jan@jangregor.me" - } - ], - "description": "Provides a phpstan/phpstan extension for phpspec/prophecy", - "support": { - "issues": "https://github.com/Jan0707/phpstan-prophecy/issues", - "source": "https://github.com/Jan0707/phpstan-prophecy/tree/1.0.0" - }, - "funding": [ - { - "url": "https://github.com/localheinz", - "type": "github" - } - ], - "time": "2021-11-08T16:37:47+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.11.1", @@ -2451,341 +2339,6 @@ }, "time": "2023-12-03T09:22:01+00:00" }, - { - "name": "phpdocumentor/reflection-common", - "version": "2.2.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b", - "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-2.x": "2.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jaap van Otterdijk", - "email": "opensource@ijaap.nl" - } - ], - "description": "Common reflection classes used by phpdocumentor to reflect the code structure", - "homepage": "http://www.phpdoc.org", - "keywords": [ - "FQSEN", - "phpDocumentor", - "phpdoc", - "reflection", - "static analysis" - ], - "support": { - "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", - "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" - }, - "time": "2020-06-27T09:03:43+00:00" - }, - { - "name": "phpdocumentor/reflection-docblock", - "version": "5.3.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", - "shasum": "" - }, - "require": { - "ext-filter": "*", - "php": "^7.2 || ^8.0", - "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.3", - "webmozart/assert": "^1.9.1" - }, - "require-dev": { - "mockery/mockery": "~1.3.2", - "psalm/phar": "^4.8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - }, - { - "name": "Jaap van Otterdijk", - "email": "account@ijaap.nl" - } - ], - "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "support": { - "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" - }, - "time": "2021-10-19T17:43:47+00:00" - }, - { - "name": "phpdocumentor/type-resolver", - "version": "1.7.3", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", - "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", - "shasum": "" - }, - "require": { - "doctrine/deprecations": "^1.0", - "php": "^7.4 || ^8.0", - "phpdocumentor/reflection-common": "^2.0", - "phpstan/phpdoc-parser": "^1.13" - }, - "require-dev": { - "ext-tokenizer": "*", - "phpbench/phpbench": "^1.2", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.8", - "phpstan/phpstan-phpunit": "^1.1", - "phpunit/phpunit": "^9.5", - "rector/rector": "^0.13.9", - "vimeo/psalm": "^4.25" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - } - ], - "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "support": { - "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.3" - }, - "time": "2023-08-12T11:01:26+00:00" - }, - { - "name": "phpspec/prophecy", - "version": "v1.17.0", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "15873c65b207b07765dbc3c95d20fdf4a320cbe2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/15873c65b207b07765dbc3c95d20fdf4a320cbe2", - "reference": "15873c65b207b07765dbc3c95d20fdf4a320cbe2", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.2 || ^2.0", - "php": "^7.2 || 8.0.* || 8.1.* || 8.2.*", - "phpdocumentor/reflection-docblock": "^5.2", - "sebastian/comparator": "^3.0 || ^4.0", - "sebastian/recursion-context": "^3.0 || ^4.0" - }, - "require-dev": { - "phpspec/phpspec": "^6.0 || ^7.0", - "phpstan/phpstan": "^1.9", - "phpunit/phpunit": "^8.0 || ^9.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Prophecy\\": "src/Prophecy" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "support": { - "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/v1.17.0" - }, - "time": "2023-02-02T15:41:36+00:00" - }, - { - "name": "phpspec/prophecy-phpunit", - "version": "v2.0.2", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy-phpunit.git", - "reference": "9f26c224a2fa335f33e6666cc078fbf388255e87" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/9f26c224a2fa335f33e6666cc078fbf388255e87", - "reference": "9f26c224a2fa335f33e6666cc078fbf388255e87", - "shasum": "" - }, - "require": { - "php": "^7.3 || ^8", - "phpspec/prophecy": "^1.3", - "phpunit/phpunit": "^9.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "psr-4": { - "Prophecy\\PhpUnit\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christophe Coevoet", - "email": "stof@notk.org" - } - ], - "description": "Integrating the Prophecy mocking library in PHPUnit test cases", - "homepage": "http://phpspec.net", - "keywords": [ - "phpunit", - "prophecy" - ], - "support": { - "issues": "https://github.com/phpspec/prophecy-phpunit/issues", - "source": "https://github.com/phpspec/prophecy-phpunit/tree/v2.0.2" - }, - "time": "2023-04-18T11:58:05+00:00" - }, - { - "name": "phpstan/phpdoc-parser", - "version": "1.24.4", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6bd0c26f3786cd9b7c359675cb789e35a8e07496", - "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "require-dev": { - "doctrine/annotations": "^2.0", - "nikic/php-parser": "^4.15", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.5", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^9.5", - "symfony/process": "^5.2" - }, - "type": "library", - "autoload": { - "psr-4": { - "PHPStan\\PhpDocParser\\": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHPDoc parser with support for nullable, intersection and generic types", - "support": { - "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.4" - }, - "time": "2023-11-26T18:29:22+00:00" - }, { "name": "phpstan/phpstan", "version": "1.10.47", @@ -4578,64 +4131,6 @@ } ], "time": "2023-11-20T00:12:19+00:00" - }, - { - "name": "webmozart/assert", - "version": "1.11.0", - "source": { - "type": "git", - "url": "https://github.com/webmozarts/assert.git", - "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", - "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", - "shasum": "" - }, - "require": { - "ext-ctype": "*", - "php": "^7.2 || ^8.0" - }, - "conflict": { - "phpstan/phpstan": "<0.12.20", - "vimeo/psalm": "<4.6.1 || 4.6.2" - }, - "require-dev": { - "phpunit/phpunit": "^8.5.13" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.10-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "support": { - "issues": "https://github.com/webmozarts/assert/issues", - "source": "https://github.com/webmozarts/assert/tree/1.11.0" - }, - "time": "2022-06-03T18:03:27+00:00" } ], "aliases": [], diff --git a/tests/Command/ScanCommandTest.php b/tests/Command/ScanCommandTest.php index 3b25a86..3a036b0 100644 --- a/tests/Command/ScanCommandTest.php +++ b/tests/Command/ScanCommandTest.php @@ -4,10 +4,8 @@ namespace Siketyan\Loxcan\Command; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\DependencyCollectionDiff; use Siketyan\Loxcan\Model\Repository; use Siketyan\Loxcan\UseCase\ReportUseCase; @@ -16,50 +14,42 @@ class ScanCommandTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $scanUseCase; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $reportUseCase; - + private MockObject&ScanUseCase $scanUseCase; + private MockObject&ReportUseCase $reportUseCase; private CommandTester $tester; protected function setUp(): void { - $this->scanUseCase = $this->prophesize(ScanUseCase::class); - $this->reportUseCase = $this->prophesize(ReportUseCase::class); + $this->scanUseCase = $this->createMock(ScanUseCase::class); + $this->reportUseCase = $this->createMock(ReportUseCase::class); $this->tester = new CommandTester( new ScanCommand( - $this->scanUseCase->reveal(), - $this->reportUseCase->reveal(), + $this->scanUseCase, + $this->reportUseCase, ), ); } public function test(): void { - $diff = $this->prophesize(DependencyCollectionDiff::class); + $diff = $this->createStub(DependencyCollectionDiff::class); $diffs = [ - 'foo.lock' => $diff->reveal(), - 'bar.lock' => $diff->reveal(), + 'foo.lock' => $diff, + 'bar.lock' => $diff, ]; $this->scanUseCase - ->scan(Argument::type(Repository::class), 'foo', 'bar') + ->expects($this->once()) + ->method('scan') + ->with($this->isInstanceOf(Repository::class), 'foo', 'bar') ->willReturn($diffs) - ->shouldBeCalledOnce() ; $this->reportUseCase - ->report($diffs, ['console'], Argument::type('array')) - ->shouldBeCalledOnce() + ->expects($this->once()) + ->method('report') + ->with($diffs, ['console'], $this->isType('array')) ; $exitCode = $this->tester->execute([ diff --git a/tests/Comparator/DependencyCollectionComparatorTest.php b/tests/Comparator/DependencyCollectionComparatorTest.php index c6ecc69..5fcd2a3 100644 --- a/tests/Comparator/DependencyCollectionComparatorTest.php +++ b/tests/Comparator/DependencyCollectionComparatorTest.php @@ -4,9 +4,8 @@ namespace Siketyan\Loxcan\Comparator; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\DependencyCollectionDiff; @@ -14,43 +13,43 @@ class DependencyCollectionComparatorTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $subtractor; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $intersector; - + private DependencyCollectionSubtractor&MockObject $subtractor; + private DependencyCollectionIntersector&MockObject $intersector; private DependencyCollectionComparator $comparator; protected function setUp(): void { - $this->subtractor = $this->prophesize(DependencyCollectionSubtractor::class); - $this->intersector = $this->prophesize(DependencyCollectionIntersector::class); - + $this->subtractor = $this->createMock(DependencyCollectionSubtractor::class); + $this->intersector = $this->createMock(DependencyCollectionIntersector::class); $this->comparator = new DependencyCollectionComparator( - $this->subtractor->reveal(), - $this->intersector->reveal(), + $this->subtractor, + $this->intersector, ); } public function test(): void { - $added = [$this->prophesize(Dependency::class)->reveal()]; - $updated = [$this->prophesize(DependencyDiff::class)->reveal()]; - $removed = [$this->prophesize(Dependency::class)->reveal()]; - - $before = $this->prophesize(DependencyCollection::class)->reveal(); - $after = $this->prophesize(DependencyCollection::class)->reveal(); - - $this->subtractor->subtract($after, $before)->willReturn($added); - $this->subtractor->subtract($before, $after)->willReturn($removed); - $this->intersector->intersect($before, $after)->willReturn($updated); + $added = [$this->createStub(Dependency::class)]; + $updated = [$this->createStub(DependencyDiff::class)]; + $removed = [$this->createStub(Dependency::class)]; + + $before = $this->createStub(DependencyCollection::class); + $after = $this->createStub(DependencyCollection::class); + + $this->subtractor + ->expects($this->exactly(2)) + ->method('subtract') + ->with($this->isInstanceOf(DependencyCollection::class), $this->isInstanceOf(DependencyCollection::class)) + ->willReturnCallback( + fn (DependencyCollection $a, DependencyCollection $b): array => ($a === $before && $b === $after) ? $removed : $added, + ) + ; + + $this->intersector + ->method('intersect') + ->with($this->identicalTo($before), $this->identicalTo($after)) + ->willReturn($updated) + ; $diff = $this->comparator->compare($before, $after); diff --git a/tests/Comparator/DependencyCollectionIntersectorTest.php b/tests/Comparator/DependencyCollectionIntersectorTest.php index e79b2fc..5e1d599 100644 --- a/tests/Comparator/DependencyCollectionIntersectorTest.php +++ b/tests/Comparator/DependencyCollectionIntersectorTest.php @@ -4,9 +4,9 @@ namespace Siketyan\Loxcan\Comparator; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\DependencyDiff; @@ -14,56 +14,47 @@ class DependencyCollectionIntersectorTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $comparator; - + private DependencyComparator&MockObject $comparator; private DependencyCollectionIntersector $intersector; protected function setUp(): void { - $this->comparator = $this->prophesize(DependencyComparator::class); - - $this->intersector = new DependencyCollectionIntersector( - $this->comparator->reveal(), - ); + $this->comparator = $this->createMock(DependencyComparator::class); + $this->intersector = new DependencyCollectionIntersector($this->comparator); } public function test(): void { - $package = $this->prophesize(Package::class)->reveal(); - $diff = $this->prophesize(DependencyDiff::class)->reveal(); + $package = $this->createStub(Package::class); + $diff = $this->createStub(DependencyDiff::class); - $before = $this->prophesize(Dependency::class); - $after = $this->prophesize(Dependency::class); + $before = $this->createStub(Dependency::class); + $after = $this->createStub(Dependency::class); - $before->getPackage()->willReturn($package); - $after->getPackage()->willReturn($package); + $before->method('getPackage')->willReturn($package); + $after->method('getPackage')->willReturn($package); - $this->comparator->compare($before->reveal(), $after->reveal())->willReturn($diff); + $this->comparator->method('compare')->with($before, $after)->willReturn($diff); - $a = $this->prophesize(DependencyCollection::class); - $b = $this->prophesize(DependencyCollection::class); + $a = $this->createStub(DependencyCollection::class); + $b = $this->createStub(DependencyCollection::class); - $a->getDependencies()->willReturn([$before->reveal(), $this->createDummyDependency()]); - $b->getDependencies()->willReturn([$after->reveal(), $this->createDummyDependency()]); + $a->method('getDependencies')->willReturn([$before, $this->createDummyDependency()]); + $b->method('getDependencies')->willReturn([$after, $this->createDummyDependency()]); - $this->assertSame([$diff], $this->intersector->intersect($a->reveal(), $b->reveal())); + $this->assertSame([$diff], $this->intersector->intersect($a, $b)); } - private function createDummyDependency(): Dependency + private function createDummyDependency(): Dependency&Stub { - $package = $this->prophesize(Package::class)->reveal(); - $dependency = $this->prophesize(Dependency::class); + $package = $this->createStub(Package::class); + $dependency = $this->createStub(Dependency::class); $dependency - ->getPackage() + ->method('getPackage') ->willReturn($package) ; - return $dependency->reveal(); + return $dependency; } } diff --git a/tests/Comparator/DependencyCollectionSubtractorTest.php b/tests/Comparator/DependencyCollectionSubtractorTest.php index 3b16a49..7a0c353 100644 --- a/tests/Comparator/DependencyCollectionSubtractorTest.php +++ b/tests/Comparator/DependencyCollectionSubtractorTest.php @@ -5,15 +5,12 @@ namespace Siketyan\Loxcan\Comparator; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\Package; class DependencyCollectionSubtractorTest extends TestCase { - use ProphecyTrait; - private DependencyCollectionSubtractor $subtractor; protected function setUp(): void @@ -23,21 +20,21 @@ protected function setUp(): void public function test(): void { - $added = $this->prophesize(Dependency::class); - $removed = $this->prophesize(Dependency::class); - $common = $this->prophesize(Dependency::class); + $added = $this->createStub(Dependency::class); + $removed = $this->createStub(Dependency::class); + $common = $this->createStub(Dependency::class); - $added->getPackage()->willReturn($this->prophesize(Package::class)->reveal()); - $removed->getPackage()->willReturn($this->prophesize(Package::class)->reveal()); - $common->getPackage()->willReturn($this->prophesize(Package::class)->reveal()); + $added->method('getPackage')->willReturn($this->createStub(Package::class)); + $removed->method('getPackage')->willReturn($this->createStub(Package::class)); + $common->method('getPackage')->willReturn($this->createStub(Package::class)); - $a = $this->prophesize(DependencyCollection::class); - $b = $this->prophesize(DependencyCollection::class); + $a = $this->createStub(DependencyCollection::class); + $b = $this->createStub(DependencyCollection::class); - $a->getDependencies()->willReturn([$common->reveal(), $removed->reveal()]); - $b->getDependencies()->willReturn([$common->reveal(), $added->reveal()]); + $a->method('getDependencies')->willReturn([$common, $removed]); + $b->method('getDependencies')->willReturn([$common, $added]); - $this->assertSame([$added->reveal()], $this->subtractor->subtract($b->reveal(), $a->reveal())); - $this->assertSame([$removed->reveal()], $this->subtractor->subtract($a->reveal(), $b->reveal())); + $this->assertSame([$added], $this->subtractor->subtract($b, $a)); + $this->assertSame([$removed], $this->subtractor->subtract($a, $b)); } } diff --git a/tests/Comparator/DependencyComparatorTest.php b/tests/Comparator/DependencyComparatorTest.php index 229ffd6..2d57925 100644 --- a/tests/Comparator/DependencyComparatorTest.php +++ b/tests/Comparator/DependencyComparatorTest.php @@ -4,9 +4,8 @@ namespace Siketyan\Loxcan\Comparator; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Exception\InvalidComparisonException; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\DependencyDiff; @@ -18,47 +17,39 @@ class DependencyComparatorTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $versionComparatorResolver; - + private MockObject&VersionComparatorResolver $versionComparatorResolver; private DependencyComparator $comparator; protected function setUp(): void { - $this->versionComparatorResolver = $this->prophesize(VersionComparatorResolver::class); - - $this->comparator = new DependencyComparator( - $this->versionComparatorResolver->reveal(), - ); + $this->versionComparatorResolver = $this->createMock(VersionComparatorResolver::class); + $this->comparator = new DependencyComparator($this->versionComparatorResolver); } public function test(): void { - $package = $this->prophesize(Package::class)->reveal(); - $versionDiff = $this->prophesize(VersionDiff::class)->reveal(); - $beforeVersion = $this->prophesize(SimpleVersion::class)->reveal(); - $afterVersion = $this->prophesize(SimpleVersion::class)->reveal(); - $before = $this->prophesize(Dependency::class); - $after = $this->prophesize(Dependency::class); + $package = $this->createStub(Package::class); + $versionDiff = $this->createStub(VersionDiff::class); + $beforeVersion = $this->createStub(SimpleVersion::class); + $afterVersion = $this->createStub(SimpleVersion::class); + $before = $this->createStub(Dependency::class); + $after = $this->createStub(Dependency::class); - $before->getPackage()->willReturn($package); - $before->getVersion()->willReturn($beforeVersion); - $after->getPackage()->willReturn($package); - $after->getVersion()->willReturn($afterVersion); + $before->method('getPackage')->willReturn($package); + $before->method('getVersion')->willReturn($beforeVersion); + $after->method('getPackage')->willReturn($package); + $after->method('getVersion')->willReturn($afterVersion); - $versionComparator = $this->prophesize(VersionComparatorInterface::class); - $versionComparator->compare($beforeVersion, $afterVersion)->willReturn($versionDiff); + $versionComparator = $this->createMock(VersionComparatorInterface::class); + $versionComparator->method('compare')->with($beforeVersion, $afterVersion)->willReturn($versionDiff); $this->versionComparatorResolver - ->resolve($beforeVersion, $afterVersion) - ->willReturn($versionComparator->reveal()) + ->method('resolve') + ->with($beforeVersion, $afterVersion) + ->willReturn($versionComparator) ; - $diff = $this->comparator->compare($before->reveal(), $after->reveal()); + $diff = $this->comparator->compare($before, $after); $this->assertInstanceOf(DependencyDiff::class, $diff); $this->assertSame($package, $diff->getPackage()); @@ -69,14 +60,14 @@ public function testInvalidComparison(): void { $this->expectException(InvalidComparisonException::class); - $beforePackage = $this->prophesize(Package::class)->reveal(); - $afterPackage = $this->prophesize(Package::class)->reveal(); - $before = $this->prophesize(Dependency::class); - $after = $this->prophesize(Dependency::class); + $beforePackage = $this->createStub(Package::class); + $afterPackage = $this->createStub(Package::class); + $before = $this->createStub(Dependency::class); + $after = $this->createStub(Dependency::class); - $before->getPackage()->willReturn($beforePackage); - $after->getPackage()->willReturn($afterPackage); + $before->method('getPackage')->willReturn($beforePackage); + $after->method('getPackage')->willReturn($afterPackage); - $this->comparator->compare($before->reveal(), $after->reveal()); + $this->comparator->compare($before, $after); } } diff --git a/tests/Git/GitProcessFactoryTest.php b/tests/Git/GitProcessFactoryTest.php index 623e2d9..01709d7 100644 --- a/tests/Git/GitProcessFactoryTest.php +++ b/tests/Git/GitProcessFactoryTest.php @@ -6,14 +6,11 @@ use Eloquent\Pathogen\PathInterface; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Siketyan\Loxcan\Model\Repository; use Symfony\Component\Process\Process; class GitProcessFactoryTest extends TestCase { - use ProphecyTrait; - private const GIT_PATH = '/usr/bin/git'; private GitProcessFactory $factory; @@ -27,13 +24,13 @@ protected function setUp(): void public function test(): void { - $path = $this->prophesize(PathInterface::class); - $repository = $this->prophesize(Repository::class); + $path = $this->createStub(PathInterface::class); + $repository = $this->createStub(Repository::class); - $path->string()->willReturn(__DIR__); - $repository->getPath()->willReturn($path->reveal()); + $path->method('string')->willReturn(__DIR__); + $repository->method('getPath')->willReturn($path); - $process = $this->factory->create($repository->reveal(), ['foo', 'bar']); + $process = $this->factory->create($repository, ['foo', 'bar']); $this->assertInstanceOf(Process::class, $process); $this->assertSame("'/usr/bin/git' 'foo' 'bar'", $process->getCommandLine()); diff --git a/tests/Git/GitTest.php b/tests/Git/GitTest.php index 67ca8a9..66651dd 100644 --- a/tests/Git/GitTest.php +++ b/tests/Git/GitTest.php @@ -6,29 +6,21 @@ use Eloquent\Pathogen\Path; use Eloquent\Pathogen\RelativePathInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Repository; use Symfony\Component\Process\Process; class GitTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $processFactory; - + private GitProcessFactory&MockObject $processFactory; private Git $git; protected function setUp(): void { - $this->processFactory = $this->prophesize(GitProcessFactory::class); - + $this->processFactory = $this->createMock(GitProcessFactory::class); $this->git = new Git( - $this->processFactory->reveal(), + $this->processFactory, ); } @@ -36,20 +28,21 @@ public function testFetchChangedFiles(): void { $base = 'master'; $head = 'feature'; - $repository = $this->prophesize(Repository::class)->reveal(); + $repository = $this->createStub(Repository::class); - $process = $this->prophesize(Process::class); - $process->run()->willReturn(0)->shouldBeCalledOnce(); - $process->isSuccessful()->willReturn(true); - $process->getOutput()->willReturn(<<<'EOS' + $process = $this->createMock(Process::class); + $process->expects($this->once())->method('run')->willReturn(0); + $process->method('isSuccessful')->willReturn(true); + $process->method('getOutput')->willReturn(<<<'EOS' foo/bar.json baz.lock EOS); $this->processFactory - ->create($repository, ['diff', '--name-only', 'master', 'feature']) - ->willReturn($process->reveal()) - ->shouldBeCalledOnce() + ->expects($this->once()) + ->method('create') + ->with($repository, ['diff', '--name-only', 'master', 'feature']) + ->willReturn($process) ; $files = $this->git->fetchChangedFiles($repository, $base, $head); @@ -61,26 +54,26 @@ public function testFetchChangedFiles(): void public function testFetchOriginalFile(): void { - $repository = $this->prophesize(Repository::class)->reveal(); + $repository = $this->createMock(Repository::class); $expected = <<<'EOS' dummy foobar EOS; - $process = $this->prophesize(Process::class); - $process->run()->willReturn(0)->shouldBeCalledOnce(); - $process->isSuccessful()->willReturn(true); - $process->getOutput()->willReturn($expected); + $process = $this->createMock(Process::class); + $process->expects($this->once())->method('run')->willReturn(0); + $process->method('isSuccessful')->willReturn(true); + $process->method('getOutput')->willReturn($expected); $this->processFactory - ->create($repository, ['show', 'master:bar.lock']) - ->willReturn($process->reveal()) - ->shouldBeCalledOnce() + ->expects($this->once()) + ->method('create') + ->with($repository, ['show', 'master:bar.lock']) + ->willReturn($process) ; - $path = $this->prophesize(RelativePathInterface::class); - $path->string()->willReturn('bar.lock'); - $path = $path->reveal(); + $path = $this->createStub(RelativePathInterface::class); + $path->method('string')->willReturn('bar.lock'); $actual = $this->git->fetchOriginalFile($repository, 'master', $path); @@ -89,28 +82,26 @@ public function testFetchOriginalFile(): void public function testCheckFileExists(): void { - $repository = $this->prophesize(Repository::class)->reveal(); + $repository = $this->createStub(Repository::class); - $process = $this->prophesize(Process::class); - $process->run()->willReturn(0)->shouldBeCalledTimes(2); - $process->isSuccessful()->willReturn(true); + $process = $this->createMock(Process::class); + $process->expects($this->exactly(2))->method('run')->willReturn(0); + $process->method('isSuccessful')->willReturnOnConsecutiveCalls(true, false); $this->processFactory - ->create($repository, ['cat-file', '-e', 'master:bar.lock']) - ->willReturn($process->reveal()) - ->shouldBeCalledTimes(2) + ->expects($this->exactly(2)) + ->method('create') + ->with($repository, ['cat-file', '-e', 'master:bar.lock']) + ->willReturn($process) ; - $path = $this->prophesize(RelativePathInterface::class); - $path->string()->willReturn('bar.lock'); - $path = $path->reveal(); + $path = $this->createStub(RelativePathInterface::class); + $path->method('string')->willReturn('bar.lock'); $this->assertTrue( $this->git->checkFileExists($repository, 'master', $path), ); - $process->isSuccessful()->willReturn(false); - $this->assertFalse( $this->git->checkFileExists($repository, 'master', $path), ); diff --git a/tests/Model/DependencyCollectionDiffTest.php b/tests/Model/DependencyCollectionDiffTest.php index c49fe3f..a32290a 100644 --- a/tests/Model/DependencyCollectionDiffTest.php +++ b/tests/Model/DependencyCollectionDiffTest.php @@ -5,19 +5,16 @@ namespace Siketyan\Loxcan\Model; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; class DependencyCollectionDiffTest extends TestCase { - use ProphecyTrait; - public function testCount(): void { $diff = new DependencyCollectionDiff(); $this->assertSame(0, $diff->count()); - $dummy = $this->prophesize(Dependency::class)->reveal(); - $dummyDiff = $this->prophesize(DependencyDiff::class)->reveal(); + $dummy = $this->createStub(Dependency::class); + $dummyDiff = $this->createStub(DependencyDiff::class); $diff = new DependencyCollectionDiff( [$dummy], [$dummyDiff, $dummyDiff], diff --git a/tests/Reporter/Console/ConsoleReporterTest.php b/tests/Reporter/Console/ConsoleReporterTest.php index 8411ca3..7abb447 100644 --- a/tests/Reporter/Console/ConsoleReporterTest.php +++ b/tests/Reporter/Console/ConsoleReporterTest.php @@ -5,7 +5,6 @@ namespace Siketyan\Loxcan\Reporter\Console; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\DependencyCollectionDiff; use Siketyan\Loxcan\Model\DependencyDiff; @@ -19,26 +18,24 @@ class ConsoleReporterTest extends TestCase { - use ProphecyTrait; - public function test(): void { - $diff = $this->prophesize(DependencyCollectionDiff::class); - $diff->count()->willReturn(5); - $diff->getAdded()->willReturn([$this->createDependency('added', 'v1.2.3')]); - $diff->getRemoved()->willReturn([$this->createDependency('removed', 'v3.2.1')]); - $diff->getUpdated()->willReturn([ + $diff = $this->createStub(DependencyCollectionDiff::class); + $diff->method('count')->willReturn(5); + $diff->method('getAdded')->willReturn([$this->createDependency('added', 'v1.2.3')]); + $diff->method('getRemoved')->willReturn([$this->createDependency('removed', 'v3.2.1')]); + $diff->method('getUpdated')->willReturn([ $this->createDependencyDiff('upgraded', 'v1.1.1', 'v2.2.2', VersionDiff::UPGRADED), $this->createDependencyDiff('downgraded', 'v4.4.4', 'v3.3.3', VersionDiff::DOWNGRADED), $this->createDependencyDiff('unknown', 'v5.5.5', 'v5.5.5', VersionDiff::UNKNOWN), ]); - $emptyDiff = $this->prophesize(DependencyCollectionDiff::class); - $emptyDiff->count()->willReturn(0); + $emptyDiff = $this->createStub(DependencyCollectionDiff::class); + $emptyDiff->method('count')->willReturn(0); $diffs = [ - 'foo.lock' => $diff->reveal(), - 'bar.lock' => $emptyDiff->reveal(), + 'foo.lock' => $diff, + 'bar.lock' => $emptyDiff, ]; $input = new ArrayInput([]); @@ -98,41 +95,41 @@ public function testNoDiff(): void private function createDependency(string $name, string $versionName): Dependency { - $package = $this->prophesize(Package::class); - $package->getName()->willReturn($name); + $package = $this->createStub(Package::class); + $package->method('getName')->willReturn($name); - $version = $this->prophesize(SimpleVersion::class); - $version->__toString()->willReturn($versionName); + $version = $this->createStub(SimpleVersion::class); + $version->method('__toString')->willReturn($versionName); - $dependency = $this->prophesize(Dependency::class); - $dependency->getPackage()->willReturn($package->reveal()); - $dependency->getVersion()->willReturn($version->reveal()); + $dependency = $this->createStub(Dependency::class); + $dependency->method('getPackage')->willReturn($package); + $dependency->method('getVersion')->willReturn($version); - return $dependency->reveal(); + return $dependency; } private function createDependencyDiff(string $name, string $before, string $after, int $type): DependencyDiff { - $package = $this->prophesize(Package::class); - $package->getName()->willReturn($name); + $package = $this->createStub(Package::class); + $package->method('getName')->willReturn($name); - $beforeVersion = $this->prophesize(SimpleVersion::class); - $beforeVersion->__toString()->willReturn($before); + $beforeVersion = $this->createStub(SimpleVersion::class); + $beforeVersion->method('__toString')->willReturn($before); - $afterVersion = $this->prophesize(SimpleVersion::class); - $afterVersion->__toString()->willReturn($after); + $afterVersion = $this->createStub(SimpleVersion::class); + $afterVersion->method('__toString')->willReturn($after); - $versionDiff = $this->prophesize(VersionDiff::class); - $versionDiff->isCompatible()->willReturn(false); - $versionDiff->getType()->willReturn($type); - $versionDiff->getBefore()->willReturn($beforeVersion->reveal()); - $versionDiff->getAfter()->willReturn($afterVersion->reveal()); + $versionDiff = $this->createStub(VersionDiff::class); + $versionDiff->method('isCompatible')->willReturn(false); + $versionDiff->method('getType')->willReturn($type); + $versionDiff->method('getBefore')->willReturn($beforeVersion); + $versionDiff->method('getAfter')->willReturn($afterVersion); - $diff = $this->prophesize(DependencyDiff::class); - $diff->getPackage()->willReturn($package->reveal()); - $diff->getVersionDiff()->willReturn($versionDiff->reveal()); + $diff = $this->createStub(DependencyDiff::class); + $diff->method('getPackage')->willReturn($package); + $diff->method('getVersionDiff')->willReturn($versionDiff); - return $diff->reveal(); + return $diff; } private function removeTextStyles(string $text): string diff --git a/tests/Reporter/GitHub/GitHubClientTest.php b/tests/Reporter/GitHub/GitHubClientTest.php index 1c7e500..a0e7f53 100644 --- a/tests/Reporter/GitHub/GitHubClientTest.php +++ b/tests/Reporter/GitHub/GitHubClientTest.php @@ -5,50 +5,35 @@ namespace Siketyan\Loxcan\Reporter\GitHub; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\GuzzleException; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; class GitHubClientTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $httpClient; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $userPool; + private ClientInterface&MockObject $httpClient; + private GitHubUserPool&MockObject $userPool; private GitHubClient $client; protected function setUp(): void { - $this->httpClient = $this->prophesize(ClientInterface::class); - $this->userPool = $this->prophesize(GitHubUserPool::class); + $this->httpClient = $this->createMock(ClientInterface::class); + $this->userPool = $this->createMock(GitHubUserPool::class); $this->client = new GitHubClient( - $this->httpClient->reveal(), - $this->userPool->reveal(), + $this->httpClient, + $this->userPool, ); putenv('LOXCAN_REPORTER_GITHUB_TOKEN=dummy_token'); } - /** - * @throws GuzzleException - */ public function testGetComments(): void { - $stream = $this->prophesize(StreamInterface::class); - $stream->getContents()->willReturn(<<<'EOS' + $stream = $this->createStub(StreamInterface::class); + $stream->method('getContents')->willReturn(<<<'EOS' [ { "id": 123, @@ -69,11 +54,13 @@ public function testGetComments(): void ] EOS); - $response = $this->prophesize(ResponseInterface::class); - $response->getBody()->willReturn($stream->reveal()); + $response = $this->createStub(ResponseInterface::class); + $response->method('getBody')->willReturn($stream); $this->httpClient - ->request( + ->expects($this->once()) + ->method('request') + ->with( 'GET', '/repos/foo/bar/issues/123/comments', [ @@ -83,20 +70,27 @@ public function testGetComments(): void ], ], ) - ->willReturn($response->reveal()) - ->shouldBeCalledOnce() + ->willReturn($response) ; - $pool = $this->userPool; + $user = null; + + $this->userPool + ->expects($this->exactly(2)) + ->method('get') + ->with(111) + ->willReturnCallback(static function () use (&$user): ?GitHubUser { + return $user; + }) + ; - $this->userPool->get(111)->willReturn(null)->shouldBeCalledTimes(2); $this->userPool - ->add(Argument::type(GitHubUser::class)) - ->will(function (array $args) use ($pool): void { - /* @noinspection PhpUndefinedMethodInspection */ - $pool->get(111)->willReturn($args[0]); + ->expects($this->once()) + ->method('add') + ->with($this->isInstanceOf(GitHubUser::class)) + ->willReturnCallback(static function (GitHubUser $u) use (&$user): void { + $user = $u; }) - ->shouldBeCalledOnce() ; $comments = $this->client->getComments('foo', 'bar', 123); @@ -110,13 +104,12 @@ public function testGetComments(): void $this->assertSame($comments[0]->getAuthor(), $comments[1]->getAuthor()); } - /** - * @throws GuzzleException - */ public function testCreateComment(): void { $this->httpClient - ->request( + ->expects($this->once()) + ->method('request') + ->with( 'POST', '/repos/foo/bar/issues/123/comments', [ @@ -127,8 +120,7 @@ public function testCreateComment(): void ], ], ) - ->willReturn($this->prophesize(ResponseInterface::class)->reveal()) - ->shouldBeCalledOnce() + ->willReturn($this->createStub(ResponseInterface::class)) ; $this->client->createComment( @@ -139,16 +131,15 @@ public function testCreateComment(): void ); } - /** - * @throws GuzzleException - */ public function testUpdateComment(): void { - $comment = $this->prophesize(GitHubComment::class); - $comment->getId()->willReturn(123); + $comment = $this->createStub(GitHubComment::class); + $comment->method('getId')->willReturn(123); $this->httpClient - ->request( + ->expects($this->once()) + ->method('request') + ->with( 'PATCH', '/repos/foo/bar/issues/comments/123', [ @@ -159,14 +150,13 @@ public function testUpdateComment(): void ], ], ) - ->willReturn($this->prophesize(ResponseInterface::class)->reveal()) - ->shouldBeCalledOnce() + ->willReturn($this->createStub(ResponseInterface::class)) ; $this->client->updateComment( 'foo', 'bar', - $comment->reveal(), + $comment, 'dummy_body', ); } diff --git a/tests/Reporter/GitHub/GitHubMarkdownBuilderTest.php b/tests/Reporter/GitHub/GitHubMarkdownBuilderTest.php index 72b297a..91343c7 100644 --- a/tests/Reporter/GitHub/GitHubMarkdownBuilderTest.php +++ b/tests/Reporter/GitHub/GitHubMarkdownBuilderTest.php @@ -5,7 +5,6 @@ namespace Siketyan\Loxcan\Reporter\GitHub; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\DependencyCollectionDiff; use Siketyan\Loxcan\Model\DependencyDiff; @@ -16,8 +15,6 @@ class GitHubMarkdownBuilderTest extends TestCase { - use ProphecyTrait; - private MarkdownBuilder $builder; protected function setUp(): void @@ -27,22 +24,22 @@ protected function setUp(): void public function test(): void { - $diff = $this->prophesize(DependencyCollectionDiff::class); - $diff->count()->willReturn(5); - $diff->getAdded()->willReturn([$this->createDependency('added', 'v1.2.3')]); - $diff->getRemoved()->willReturn([$this->createDependency('removed', 'v3.2.1')]); - $diff->getUpdated()->willReturn([ + $diff = $this->createStub(DependencyCollectionDiff::class); + $diff->method('count')->willReturn(5); + $diff->method('getAdded')->willReturn([$this->createDependency('added', 'v1.2.3')]); + $diff->method('getRemoved')->willReturn([$this->createDependency('removed', 'v3.2.1')]); + $diff->method('getUpdated')->willReturn([ $this->createDependencyDiff('upgraded', 'v1.1.1', 'v2.2.2', VersionDiff::UPGRADED), $this->createDependencyDiff('downgraded', 'v4.4.4', 'v3.3.3', VersionDiff::DOWNGRADED), $this->createDependencyDiff('unknown', 'v5.5.5', 'v5.5.5', VersionDiff::UNKNOWN), ]); - $emptyDiff = $this->prophesize(DependencyCollectionDiff::class); - $emptyDiff->count()->willReturn(0); + $emptyDiff = $this->createStub(DependencyCollectionDiff::class); + $emptyDiff->method('count')->willReturn(0); $markdown = $this->builder->build([ - 'foo.lock' => $diff->reveal(), - 'bar.lock' => $emptyDiff->reveal(), + 'foo.lock' => $diff, + 'bar.lock' => $emptyDiff, ]); $this->assertSame( @@ -75,40 +72,40 @@ public function testNoDiff(): void private function createDependency(string $name, string $versionName): Dependency { - $package = $this->prophesize(Package::class); - $package->getName()->willReturn($name); + $package = $this->createStub(Package::class); + $package->method('getName')->willReturn($name); - $version = $this->prophesize(SimpleVersion::class); - $version->__toString()->willReturn($versionName); + $version = $this->createStub(SimpleVersion::class); + $version->method('__toString')->willReturn($versionName); - $dependency = $this->prophesize(Dependency::class); - $dependency->getPackage()->willReturn($package->reveal()); - $dependency->getVersion()->willReturn($version->reveal()); + $dependency = $this->createStub(Dependency::class); + $dependency->method('getPackage')->willReturn($package); + $dependency->method('getVersion')->willReturn($version); - return $dependency->reveal(); + return $dependency; } private function createDependencyDiff(string $name, string $before, string $after, int $type): DependencyDiff { - $package = $this->prophesize(Package::class); - $package->getName()->willReturn($name); + $package = $this->createStub(Package::class); + $package->method('getName')->willReturn($name); - $beforeVersion = $this->prophesize(SimpleVersion::class); - $beforeVersion->__toString()->willReturn($before); + $beforeVersion = $this->createStub(SimpleVersion::class); + $beforeVersion->method('__toString')->willReturn($before); - $afterVersion = $this->prophesize(SimpleVersion::class); - $afterVersion->__toString()->willReturn($after); + $afterVersion = $this->createStub(SimpleVersion::class); + $afterVersion->method('__toString')->willReturn($after); - $versionDiff = $this->prophesize(VersionDiff::class); - $versionDiff->isCompatible()->willReturn(false); - $versionDiff->getType()->willReturn($type); - $versionDiff->getBefore()->willReturn($beforeVersion->reveal()); - $versionDiff->getAfter()->willReturn($afterVersion->reveal()); + $versionDiff = $this->createStub(VersionDiff::class); + $versionDiff->method('isCompatible')->willReturn(false); + $versionDiff->method('getType')->willReturn($type); + $versionDiff->method('getBefore')->willReturn($beforeVersion); + $versionDiff->method('getAfter')->willReturn($afterVersion); - $diff = $this->prophesize(DependencyDiff::class); - $diff->getPackage()->willReturn($package->reveal()); - $diff->getVersionDiff()->willReturn($versionDiff->reveal()); + $diff = $this->createStub(DependencyDiff::class); + $diff->method('getPackage')->willReturn($package); + $diff->method('getVersionDiff')->willReturn($versionDiff); - return $diff->reveal(); + return $diff; } } diff --git a/tests/Reporter/GitHub/GitHubReporterTest.php b/tests/Reporter/GitHub/GitHubReporterTest.php index 3d13314..8e38246 100644 --- a/tests/Reporter/GitHub/GitHubReporterTest.php +++ b/tests/Reporter/GitHub/GitHubReporterTest.php @@ -4,36 +4,25 @@ namespace Siketyan\Loxcan\Reporter\GitHub; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\DependencyCollectionDiff; use Siketyan\Loxcan\Reporter\MarkdownBuilder; class GitHubReporterTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $markdownBuilder; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $client; - + private MarkdownBuilder&MockObject $markdownBuilder; + private GitHubClient&MockObject $client; private GitHubReporter $reporter; protected function setUp(): void { - $this->markdownBuilder = $this->prophesize(MarkdownBuilder::class); - $this->client = $this->prophesize(GitHubClient::class); + $this->markdownBuilder = $this->createMock(MarkdownBuilder::class); + $this->client = $this->createMock(GitHubClient::class); $this->reporter = new GitHubReporter( - $this->markdownBuilder->reveal(), - $this->client->reveal(), + $this->markdownBuilder, + $this->client, ); putenv('LOXCAN_REPORTER_GITHUB=1'); @@ -47,13 +36,13 @@ public function test(): void { $filename = 'foo.lock'; $markdown = '## Markdown'; - $diff = $this->prophesize(DependencyCollectionDiff::class)->reveal(); + $diff = $this->createStub(DependencyCollectionDiff::class); $diffs = [$filename => $diff]; - $this->markdownBuilder->build($diffs)->willReturn($markdown); + $this->markdownBuilder->method('build')->with($diffs)->willReturn($markdown); - $this->client->getComments('foo', 'bar', 123)->willReturn([])->shouldBeCalledOnce(); - $this->client->createComment('foo', 'bar', 123, $markdown)->shouldBeCalledOnce(); + $this->client->expects($this->once())->method('getComments')->with('foo', 'bar', 123)->willReturn([]); + $this->client->expects($this->once())->method('createComment')->with('foo', 'bar', 123, $markdown); $this->reporter->report($diffs); } @@ -62,20 +51,20 @@ public function testUpdate(): void { $filename = 'foo.lock'; $markdown = '## Markdown'; - $diff = $this->prophesize(DependencyCollectionDiff::class)->reveal(); + $diff = $this->createStub(DependencyCollectionDiff::class); $diffs = [$filename => $diff]; - $me = $this->prophesize(GitHubUser::class); - $me->getLogin()->willReturn('me'); + $me = $this->createStub(GitHubUser::class); + $me->method('getLogin')->willReturn('me'); - $comment = $this->prophesize(GitHubComment::class); - $comment->getId()->willReturn(123); - $comment->getAuthor()->willReturn($me->reveal()); + $comment = $this->createStub(GitHubComment::class); + $comment->method('getId')->willReturn(123); + $comment->method('getAuthor')->willReturn($me); - $this->markdownBuilder->build($diffs)->willReturn($markdown); + $this->markdownBuilder->method('build')->with($diffs)->willReturn($markdown); - $this->client->getComments('foo', 'bar', 123)->willReturn([$comment->reveal()])->shouldBeCalledOnce(); - $this->client->updateComment('foo', 'bar', $comment->reveal(), $markdown)->shouldBeCalledOnce(); + $this->client->expects($this->once())->method('getComments')->with('foo', 'bar', 123)->willReturn([$comment]); + $this->client->expects($this->once())->method('updateComment')->with('foo', 'bar', $comment, $markdown); $this->reporter->report($diffs); } diff --git a/tests/Reporter/GitHub/GitHubUserPoolTest.php b/tests/Reporter/GitHub/GitHubUserPoolTest.php index d521cbe..a1a7929 100644 --- a/tests/Reporter/GitHub/GitHubUserPoolTest.php +++ b/tests/Reporter/GitHub/GitHubUserPoolTest.php @@ -5,12 +5,9 @@ namespace Siketyan\Loxcan\Reporter\GitHub; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; class GitHubUserPoolTest extends TestCase { - use ProphecyTrait; - private GitHubUserPool $pool; protected function setUp(): void @@ -22,9 +19,8 @@ public function test(): void { $id = 123; - $user = $this->prophesize(GitHubUser::class); - $user->getId()->willReturn($id); - $user = $user->reveal(); + $user = $this->createStub(GitHubUser::class); + $user->method('getId')->willReturn($id); $this->pool->add($user); diff --git a/tests/Scanner/AbstractPackagePoolTest.php b/tests/Scanner/AbstractPackagePoolTest.php index bf14e71..9cd4fc8 100644 --- a/tests/Scanner/AbstractPackagePoolTest.php +++ b/tests/Scanner/AbstractPackagePoolTest.php @@ -5,13 +5,10 @@ namespace Siketyan\Loxcan\Scanner; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Siketyan\Loxcan\Model\Package; abstract class AbstractPackagePoolTest extends TestCase { - use ProphecyTrait; - private AbstractPackagePool $pool; protected function setUp(): void @@ -25,10 +22,9 @@ public function test(): void { $name = 'dummy/dummy'; - $package = $this->prophesize(Package::class); - $package->getName()->willReturn($name); - $package->getConstraint()->willReturn(null); - $package = $package->reveal(); + $package = $this->createStub(Package::class); + $package->method('getName')->willReturn($name); + $package->method('getConstraint')->willReturn(null); $this->pool->add($package); @@ -41,10 +37,9 @@ public function testWithConstraint(): void $name = 'dummy/dummy'; $constraint = '^1.2.3'; - $package = $this->prophesize(Package::class); - $package->getName()->willReturn($name); - $package->getConstraint()->willReturn($constraint); - $package = $package->reveal(); + $package = $this->createStub(Package::class); + $package->method('getName')->willReturn($name); + $package->method('getConstraint')->willReturn($constraint); $this->pool->add($package); diff --git a/tests/Scanner/Cargo/CargoLockParserTest.php b/tests/Scanner/Cargo/CargoLockParserTest.php index 5cd8daa..7c2a6ac 100644 --- a/tests/Scanner/Cargo/CargoLockParserTest.php +++ b/tests/Scanner/Cargo/CargoLockParserTest.php @@ -4,10 +4,8 @@ namespace Siketyan\Loxcan\Scanner\Cargo; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\Package; use Siketyan\Loxcan\Versioning\SemVer\SemVerVersion; @@ -15,8 +13,6 @@ class CargoLockParserTest extends TestCase { - use ProphecyTrait; - private const CONTENTS = <<<'EOS' [[package]] name = "foo/bar" @@ -27,41 +23,39 @@ class CargoLockParserTest extends TestCase version = "3.2.1" EOS; - /** - * @var ObjectProphecy - */ - private ObjectProphecy $packagePool; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $versionParser; - + private CargoPackagePool&MockObject $packagePool; + private MockObject&SemVerVersionParser $versionParser; private CargoLockParser $parser; protected function setUp(): void { - $this->packagePool = $this->prophesize(CargoPackagePool::class); - $this->versionParser = $this->prophesize(SemVerVersionParser::class); + $this->packagePool = $this->createMock(CargoPackagePool::class); + $this->versionParser = $this->createMock(SemVerVersionParser::class); $this->parser = new CargoLockParser( - $this->packagePool->reveal(), - $this->versionParser->reveal(), + $this->packagePool, + $this->versionParser, ); } public function test(): void { - $cache = $this->prophesize(Package::class)->reveal(); - $fooBarVersion = $this->prophesize(SemVerVersion::class)->reveal(); - $barBazVersion = $this->prophesize(SemVerVersion::class)->reveal(); - - $this->packagePool->get('foo/bar')->willReturn(null); - $this->packagePool->get('bar/baz')->willReturn($cache); - $this->packagePool->add(Argument::type(Package::class))->shouldBeCalledOnce(); - - $this->versionParser->parse('1.2.3-dev')->willReturn($fooBarVersion); - $this->versionParser->parse('3.2.1')->willReturn($barBazVersion); + $cache = $this->createStub(Package::class); + $fooBarVersion = $this->createStub(SemVerVersion::class); + $barBazVersion = $this->createStub(SemVerVersion::class); + + $this->packagePool->method('get')->willReturnCallback(fn (string $name) => match ($name) { + 'foo/bar' => null, + 'bar/baz' => $cache, + default => $this->fail('unexpected pattern'), + }); + + $this->packagePool->expects($this->once())->method('add')->with($this->isInstanceOf(Package::class)); + + $this->versionParser->method('parse')->willReturnMap([ + ['1.2.3-dev', $fooBarVersion], + ['3.2.1', $barBazVersion], + ]); $collection = $this->parser->parse(self::CONTENTS); $dependencies = $collection->getDependencies(); diff --git a/tests/Scanner/Cargo/CargoScannerTest.php b/tests/Scanner/Cargo/CargoScannerTest.php index abc4fb2..759efa9 100644 --- a/tests/Scanner/Cargo/CargoScannerTest.php +++ b/tests/Scanner/Cargo/CargoScannerTest.php @@ -4,31 +4,21 @@ namespace Siketyan\Loxcan\Scanner\Cargo; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\DependencyCollectionPair; use Siketyan\Loxcan\Model\FileDiff; class CargoScannerTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $parser; - + private CargoLockParser&MockObject $parser; private CargoScanner $scanner; protected function setUp(): void { - $this->parser = $this->prophesize(CargoLockParser::class); - - $this->scanner = new CargoScanner( - $this->parser->reveal(), - ); + $this->parser = $this->createMock(CargoLockParser::class); + $this->scanner = new CargoScanner($this->parser); } public function test(): void @@ -36,17 +26,19 @@ public function test(): void $beforeFile = 'dummy_before'; $afterFile = 'dummy_after'; - $fileDiff = $this->prophesize(FileDiff::class); - $fileDiff->getBefore()->willReturn($beforeFile); - $fileDiff->getAfter()->willReturn($afterFile); + $fileDiff = $this->createStub(FileDiff::class); + $fileDiff->method('getBefore')->willReturn($beforeFile); + $fileDiff->method('getAfter')->willReturn($afterFile); - $before = $this->prophesize(DependencyCollection::class)->reveal(); - $after = $this->prophesize(DependencyCollection::class)->reveal(); + $before = $this->createStub(DependencyCollection::class); + $after = $this->createStub(DependencyCollection::class); - $this->parser->parse($beforeFile)->willReturn($before); - $this->parser->parse($afterFile)->willReturn($after); + $this->parser->method('parse')->willReturnMap([ + [$beforeFile, $before], + [$afterFile, $after], + ]); - $pair = $this->scanner->scan($fileDiff->reveal()); + $pair = $this->scanner->scan($fileDiff); $this->assertInstanceOf(DependencyCollectionPair::class, $pair); $this->assertSame($before, $pair->getBefore()); diff --git a/tests/Scanner/Composer/ComposerLockParserTest.php b/tests/Scanner/Composer/ComposerLockParserTest.php index 060cfb5..ca7d5f0 100644 --- a/tests/Scanner/Composer/ComposerLockParserTest.php +++ b/tests/Scanner/Composer/ComposerLockParserTest.php @@ -4,10 +4,8 @@ namespace Siketyan\Loxcan\Scanner\Composer; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\Package; use Siketyan\Loxcan\Versioning\Composer\ComposerVersion; @@ -15,8 +13,6 @@ class ComposerLockParserTest extends TestCase { - use ProphecyTrait; - private const CONTENTS = <<<'EOS' { "packages": [ @@ -40,41 +36,39 @@ class ComposerLockParserTest extends TestCase } EOS; - /** - * @var ObjectProphecy - */ - private ObjectProphecy $packagePool; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $versionParser; - + private ComposerPackagePool&MockObject $packagePool; + private ComposerVersionParser&MockObject $versionParser; private ComposerLockParser $parser; protected function setUp(): void { - $this->packagePool = $this->prophesize(ComposerPackagePool::class); - $this->versionParser = $this->prophesize(ComposerVersionParser::class); + $this->packagePool = $this->createMock(ComposerPackagePool::class); + $this->versionParser = $this->createMock(ComposerVersionParser::class); $this->parser = new ComposerLockParser( - $this->packagePool->reveal(), - $this->versionParser->reveal(), + $this->packagePool, + $this->versionParser, ); } public function test(): void { - $cache = $this->prophesize(Package::class)->reveal(); - $fooBarVersion = $this->prophesize(ComposerVersion::class)->reveal(); - $barBazVersion = $this->prophesize(ComposerVersion::class)->reveal(); - - $this->packagePool->get('foo/bar')->willReturn(null); - $this->packagePool->get('bar/baz')->willReturn($cache); - $this->packagePool->add(Argument::type(Package::class))->shouldBeCalledOnce(); - - $this->versionParser->parse('v1.2.3.4', 'hash')->willReturn($fooBarVersion); - $this->versionParser->parse('3.2.1', 'hash')->willReturn($barBazVersion); + $cache = $this->createStub(Package::class); + $fooBarVersion = $this->createStub(ComposerVersion::class); + $barBazVersion = $this->createStub(ComposerVersion::class); + + $this->packagePool->method('get')->willReturnCallback(fn (string $name) => match ($name) { + 'foo/bar' => null, + 'bar/baz' => $cache, + default => $this->fail('unexpected pattern'), + }); + + $this->packagePool->expects($this->once())->method('add')->with($this->isInstanceOf(Package::class)); + + $this->versionParser->method('parse')->willReturnMap([ + ['v1.2.3.4', 'hash', $fooBarVersion], + ['3.2.1', 'hash', $barBazVersion], + ]); $collection = $this->parser->parse(self::CONTENTS); $dependencies = $collection->getDependencies(); diff --git a/tests/Scanner/Composer/ComposerScannerTest.php b/tests/Scanner/Composer/ComposerScannerTest.php index 2db9496..495c785 100644 --- a/tests/Scanner/Composer/ComposerScannerTest.php +++ b/tests/Scanner/Composer/ComposerScannerTest.php @@ -4,31 +4,22 @@ namespace Siketyan\Loxcan\Scanner\Composer; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\DependencyCollectionPair; use Siketyan\Loxcan\Model\FileDiff; class ComposerScannerTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $parser; + private ComposerLockParser&MockObject $parser; private ComposerScanner $scanner; protected function setUp(): void { - $this->parser = $this->prophesize(ComposerLockParser::class); - - $this->scanner = new ComposerScanner( - $this->parser->reveal(), - ); + $this->parser = $this->createMock(ComposerLockParser::class); + $this->scanner = new ComposerScanner($this->parser); } public function test(): void @@ -36,17 +27,19 @@ public function test(): void $beforeFile = 'dummy_before'; $afterFile = 'dummy_after'; - $fileDiff = $this->prophesize(FileDiff::class); - $fileDiff->getBefore()->willReturn($beforeFile); - $fileDiff->getAfter()->willReturn($afterFile); + $fileDiff = $this->createStub(FileDiff::class); + $fileDiff->method('getBefore')->willReturn($beforeFile); + $fileDiff->method('getAfter')->willReturn($afterFile); - $before = $this->prophesize(DependencyCollection::class)->reveal(); - $after = $this->prophesize(DependencyCollection::class)->reveal(); + $before = $this->createStub(DependencyCollection::class); + $after = $this->createStub(DependencyCollection::class); - $this->parser->parse($beforeFile)->willReturn($before); - $this->parser->parse($afterFile)->willReturn($after); + $this->parser->method('parse')->willReturnMap([ + [$beforeFile, $before], + [$afterFile, $after], + ]); - $pair = $this->scanner->scan($fileDiff->reveal()); + $pair = $this->scanner->scan($fileDiff); $this->assertInstanceOf(DependencyCollectionPair::class, $pair); $this->assertSame($before, $pair->getBefore()); diff --git a/tests/Scanner/Npm/NpmLockParserTest.php b/tests/Scanner/Npm/NpmLockParserTest.php index 6282d77..310beb7 100644 --- a/tests/Scanner/Npm/NpmLockParserTest.php +++ b/tests/Scanner/Npm/NpmLockParserTest.php @@ -4,10 +4,8 @@ namespace Siketyan\Loxcan\Scanner\Npm; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\Package; use Siketyan\Loxcan\Versioning\SemVer\SemVerVersion; @@ -15,8 +13,6 @@ class NpmLockParserTest extends TestCase { - use ProphecyTrait; - private const CONTENTS = <<<'EOS' { "packages": { @@ -30,41 +26,39 @@ class NpmLockParserTest extends TestCase } EOS; - /** - * @var ObjectProphecy - */ - private ObjectProphecy $packagePool; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $versionParser; - + private MockObject&NpmPackagePool $packagePool; + private MockObject&SemVerVersionParser $versionParser; private NpmLockParser $parser; protected function setUp(): void { - $this->packagePool = $this->prophesize(NpmPackagePool::class); - $this->versionParser = $this->prophesize(SemVerVersionParser::class); + $this->packagePool = $this->createMock(NpmPackagePool::class); + $this->versionParser = $this->createMock(SemVerVersionParser::class); $this->parser = new NpmLockParser( - $this->packagePool->reveal(), - $this->versionParser->reveal(), + $this->packagePool, + $this->versionParser, ); } public function test(): void { - $cache = $this->prophesize(Package::class)->reveal(); - $fooBarVersion = $this->prophesize(SemVerVersion::class)->reveal(); - $barBazVersion = $this->prophesize(SemVerVersion::class)->reveal(); - - $this->packagePool->get('@foo/bar')->willReturn(null); - $this->packagePool->get('baz')->willReturn($cache); - $this->packagePool->add(Argument::type(Package::class))->shouldBeCalledOnce(); - - $this->versionParser->parse('1.2.3-dev')->willReturn($fooBarVersion); - $this->versionParser->parse('3.2.1')->willReturn($barBazVersion); + $cache = $this->createStub(Package::class); + $fooBarVersion = $this->createStub(SemVerVersion::class); + $barBazVersion = $this->createStub(SemVerVersion::class); + + $this->packagePool->method('get')->willReturnCallback(fn (string $name) => match ($name) { + '@foo/bar' => null, + 'baz' => $cache, + default => $this->fail('unexpected pattern'), + }); + + $this->packagePool->expects($this->once())->method('add')->with($this->isInstanceOf(Package::class)); + + $this->versionParser->method('parse')->willReturnMap([ + ['1.2.3-dev', $fooBarVersion], + ['3.2.1', $barBazVersion], + ]); $collection = $this->parser->parse(self::CONTENTS); $dependencies = $collection->getDependencies(); diff --git a/tests/Scanner/Npm/NpmScannerTest.php b/tests/Scanner/Npm/NpmScannerTest.php index 4264842..4c87ff0 100644 --- a/tests/Scanner/Npm/NpmScannerTest.php +++ b/tests/Scanner/Npm/NpmScannerTest.php @@ -4,31 +4,21 @@ namespace Siketyan\Loxcan\Scanner\Npm; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\DependencyCollectionPair; use Siketyan\Loxcan\Model\FileDiff; class NpmScannerTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $parser; - + private MockObject&NpmLockParser $parser; private NpmScanner $scanner; protected function setUp(): void { - $this->parser = $this->prophesize(NpmLockParser::class); - - $this->scanner = new NpmScanner( - $this->parser->reveal(), - ); + $this->parser = $this->createMock(NpmLockParser::class); + $this->scanner = new NpmScanner($this->parser); } public function test(): void @@ -36,17 +26,19 @@ public function test(): void $beforeFile = 'dummy_before'; $afterFile = 'dummy_after'; - $fileDiff = $this->prophesize(FileDiff::class); - $fileDiff->getBefore()->willReturn($beforeFile); - $fileDiff->getAfter()->willReturn($afterFile); + $fileDiff = $this->createStub(FileDiff::class); + $fileDiff->method('getBefore')->willReturn($beforeFile); + $fileDiff->method('getAfter')->willReturn($afterFile); - $before = $this->prophesize(DependencyCollection::class)->reveal(); - $after = $this->prophesize(DependencyCollection::class)->reveal(); + $before = $this->createStub(DependencyCollection::class); + $after = $this->createStub(DependencyCollection::class); - $this->parser->parse($beforeFile)->willReturn($before); - $this->parser->parse($afterFile)->willReturn($after); + $this->parser->method('parse')->willReturnMap([ + [$beforeFile, $before], + [$afterFile, $after], + ]); - $pair = $this->scanner->scan($fileDiff->reveal()); + $pair = $this->scanner->scan($fileDiff); $this->assertInstanceOf(DependencyCollectionPair::class, $pair); $this->assertSame($before, $pair->getBefore()); diff --git a/tests/Scanner/Pip/PipLockParserTest.php b/tests/Scanner/Pip/PipLockParserTest.php index d34f989..c7dcc83 100644 --- a/tests/Scanner/Pip/PipLockParserTest.php +++ b/tests/Scanner/Pip/PipLockParserTest.php @@ -4,10 +4,8 @@ namespace Siketyan\Loxcan\Scanner\Pip; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\Package; use Siketyan\Loxcan\Versioning\Simple\SimpleVersion; @@ -15,8 +13,6 @@ class PipLockParserTest extends TestCase { - use ProphecyTrait; - private const CONTENTS = <<<'EOS' { "default": { @@ -32,41 +28,39 @@ class PipLockParserTest extends TestCase } EOS; - /** - * @var ObjectProphecy - */ - private ObjectProphecy $packagePool; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $versionParser; - + private MockObject&PipPackagePool $packagePool; + private MockObject&SimpleVersionParser $versionParser; private PipLockParser $parser; protected function setUp(): void { - $this->packagePool = $this->prophesize(PipPackagePool::class); - $this->versionParser = $this->prophesize(SimpleVersionParser::class); + $this->packagePool = $this->createMock(PipPackagePool::class); + $this->versionParser = $this->createMock(SimpleVersionParser::class); $this->parser = new PipLockParser( - $this->packagePool->reveal(), - $this->versionParser->reveal(), + $this->packagePool, + $this->versionParser, ); } public function test(): void { - $cache = $this->prophesize(Package::class)->reveal(); - $fooBarVersion = $this->prophesize(SimpleVersion::class)->reveal(); - $barBazVersion = $this->prophesize(SimpleVersion::class)->reveal(); - - $this->packagePool->get('@foo/bar')->willReturn(null); - $this->packagePool->get('baz')->willReturn($cache); - $this->packagePool->add(Argument::type(Package::class))->shouldBeCalledOnce(); - - $this->versionParser->parse('1.2.3.4')->willReturn($fooBarVersion); - $this->versionParser->parse('3.2.1')->willReturn($barBazVersion); + $cache = $this->createStub(Package::class); + $fooBarVersion = $this->createStub(SimpleVersion::class); + $barBazVersion = $this->createStub(SimpleVersion::class); + + $this->packagePool->method('get')->willReturnCallback(fn (string $name) => match ($name) { + '@foo/bar' => null, + 'baz' => $cache, + default => $this->fail('unexpected pattern'), + }); + + $this->packagePool->expects($this->once())->method('add')->with($this->isInstanceOf(Package::class)); + + $this->versionParser->method('parse')->willReturnMap([ + ['1.2.3.4', $fooBarVersion], + ['3.2.1', $barBazVersion], + ]); $collection = $this->parser->parse(self::CONTENTS); $dependencies = $collection->getDependencies(); diff --git a/tests/Scanner/Pip/PipScannerTest.php b/tests/Scanner/Pip/PipScannerTest.php index 44a1c98..5ed2789 100644 --- a/tests/Scanner/Pip/PipScannerTest.php +++ b/tests/Scanner/Pip/PipScannerTest.php @@ -4,31 +4,21 @@ namespace Siketyan\Loxcan\Scanner\Pip; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\DependencyCollectionPair; use Siketyan\Loxcan\Model\FileDiff; class PipScannerTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $parser; - + private MockObject&PipLockParser $parser; private PipScanner $scanner; protected function setUp(): void { - $this->parser = $this->prophesize(PipLockParser::class); - - $this->scanner = new PipScanner( - $this->parser->reveal(), - ); + $this->parser = $this->createMock(PipLockParser::class); + $this->scanner = new PipScanner($this->parser); } public function test(): void @@ -36,17 +26,19 @@ public function test(): void $beforeFile = 'dummy_before'; $afterFile = 'dummy_after'; - $fileDiff = $this->prophesize(FileDiff::class); - $fileDiff->getBefore()->willReturn($beforeFile); - $fileDiff->getAfter()->willReturn($afterFile); + $fileDiff = $this->createStub(FileDiff::class); + $fileDiff->method('getBefore')->willReturn($beforeFile); + $fileDiff->method('getAfter')->willReturn($afterFile); - $before = $this->prophesize(DependencyCollection::class)->reveal(); - $after = $this->prophesize(DependencyCollection::class)->reveal(); + $before = $this->createStub(DependencyCollection::class); + $after = $this->createStub(DependencyCollection::class); - $this->parser->parse($beforeFile)->willReturn($before); - $this->parser->parse($afterFile)->willReturn($after); + $this->parser->method('parse')->willReturnMap([ + [$beforeFile, $before], + [$afterFile, $after], + ]); - $pair = $this->scanner->scan($fileDiff->reveal()); + $pair = $this->scanner->scan($fileDiff); $this->assertInstanceOf(DependencyCollectionPair::class, $pair); $this->assertSame($before, $pair->getBefore()); diff --git a/tests/Scanner/Pnpm/PnpmLockParserTest.php b/tests/Scanner/Pnpm/PnpmLockParserTest.php index d0017a1..f4c07ed 100644 --- a/tests/Scanner/Pnpm/PnpmLockParserTest.php +++ b/tests/Scanner/Pnpm/PnpmLockParserTest.php @@ -4,10 +4,8 @@ namespace Siketyan\Loxcan\Scanner\Pnpm; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\Package; use Siketyan\Loxcan\Versioning\SemVer\SemVerVersion; @@ -15,28 +13,18 @@ class PnpmLockParserTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $packagePool; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $versionParser; - + private MockObject&PnpmPackagePool $packagePool; + private MockObject&SemVerVersionParser $versionParser; private PnpmLockParser $parser; protected function setUp(): void { - $this->packagePool = $this->prophesize(PnpmPackagePool::class); - $this->versionParser = $this->prophesize(SemVerVersionParser::class); + $this->packagePool = $this->createMock(PnpmPackagePool::class); + $this->versionParser = $this->createMock(SemVerVersionParser::class); $this->parser = new PnpmLockParser( - $this->packagePool->reveal(), - $this->versionParser->reveal(), + $this->packagePool, + $this->versionParser, ); } @@ -45,16 +33,22 @@ protected function setUp(): void */ public function test(string $yaml): void { - $cache = $this->prophesize(Package::class)->reveal(); - $fooBarVersion = $this->prophesize(SemVerVersion::class)->reveal(); - $barBazVersion = $this->prophesize(SemVerVersion::class)->reveal(); + $cache = $this->createStub(Package::class); + $fooVersion = $this->createStub(SemVerVersion::class); + $barVersion = $this->createStub(SemVerVersion::class); + + $this->packagePool->method('get')->willReturnCallback(fn (string $name) => match ($name) { + 'foo' => null, + 'bar' => $cache, + default => $this->fail('unexpected pattern'), + }); - $this->packagePool->get('foo', Argument::any())->willReturn(null); - $this->packagePool->get('bar', Argument::any())->willReturn($cache); - $this->packagePool->add(Argument::type(Package::class))->shouldBeCalledOnce(); + $this->packagePool->expects($this->once())->method('add')->with($this->isInstanceOf(Package::class)); - $this->versionParser->parse('1.2.3-dev')->willReturn($fooBarVersion); - $this->versionParser->parse('3.2.1')->willReturn($barBazVersion); + $this->versionParser->method('parse')->willReturnMap([ + ['1.2.3-dev', $fooVersion], + ['3.2.1', $barVersion], + ]); $collection = $this->parser->parse($yaml); $dependencies = $collection->getDependencies(); @@ -63,10 +57,10 @@ public function test(string $yaml): void $this->assertContainsOnlyInstancesOf(Dependency::class, $dependencies); $this->assertSame('foo', $dependencies[0]->getPackage()->getName()); - $this->assertSame($fooBarVersion, $dependencies[0]->getVersion()); + $this->assertSame($fooVersion, $dependencies[0]->getVersion()); $this->assertSame($cache, $dependencies[1]->getPackage()); - $this->assertSame($barBazVersion, $dependencies[1]->getVersion()); + $this->assertSame($barVersion, $dependencies[1]->getVersion()); } /** diff --git a/tests/Scanner/Pnpm/PnpmScannerTest.php b/tests/Scanner/Pnpm/PnpmScannerTest.php index 1d10877..00b1429 100644 --- a/tests/Scanner/Pnpm/PnpmScannerTest.php +++ b/tests/Scanner/Pnpm/PnpmScannerTest.php @@ -4,31 +4,21 @@ namespace Siketyan\Loxcan\Scanner\Pnpm; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\DependencyCollectionPair; use Siketyan\Loxcan\Model\FileDiff; class PnpmScannerTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $parser; - + private MockObject&PnpmLockParser $parser; private PnpmScanner $scanner; protected function setUp(): void { - $this->parser = $this->prophesize(PnpmLockParser::class); - - $this->scanner = new PnpmScanner( - $this->parser->reveal(), - ); + $this->parser = $this->createMock(PnpmLockParser::class); + $this->scanner = new PnpmScanner($this->parser); } public function test(): void @@ -36,17 +26,19 @@ public function test(): void $beforeFile = 'dummy_before'; $afterFile = 'dummy_after'; - $fileDiff = $this->prophesize(FileDiff::class); - $fileDiff->getBefore()->willReturn($beforeFile); - $fileDiff->getAfter()->willReturn($afterFile); + $fileDiff = $this->createStub(FileDiff::class); + $fileDiff->method('getBefore')->willReturn($beforeFile); + $fileDiff->method('getAfter')->willReturn($afterFile); - $before = $this->prophesize(DependencyCollection::class)->reveal(); - $after = $this->prophesize(DependencyCollection::class)->reveal(); + $before = $this->createStub(DependencyCollection::class); + $after = $this->createStub(DependencyCollection::class); - $this->parser->parse($beforeFile)->willReturn($before); - $this->parser->parse($afterFile)->willReturn($after); + $this->parser->method('parse')->willReturnMap([ + [$beforeFile, $before], + [$afterFile, $after], + ]); - $pair = $this->scanner->scan($fileDiff->reveal()); + $pair = $this->scanner->scan($fileDiff); $this->assertInstanceOf(DependencyCollectionPair::class, $pair); $this->assertSame($before, $pair->getBefore()); diff --git a/tests/Scanner/Pub/PubLockParserTest.php b/tests/Scanner/Pub/PubLockParserTest.php index 8b34417..9e51765 100644 --- a/tests/Scanner/Pub/PubLockParserTest.php +++ b/tests/Scanner/Pub/PubLockParserTest.php @@ -4,10 +4,8 @@ namespace Siketyan\Loxcan\Scanner\Pub; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\Package; use Siketyan\Loxcan\Versioning\SemVer\SemVerVersion; @@ -15,8 +13,6 @@ class PubLockParserTest extends TestCase { - use ProphecyTrait; - private const CONTENTS = <<<'EOS' packages: foo: @@ -25,41 +21,39 @@ class PubLockParserTest extends TestCase version: "3.2.1" EOS; - /** - * @var ObjectProphecy - */ - private ObjectProphecy $packagePool; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $versionParser; - + private MockObject&PubPackagePool $packagePool; + private MockObject&SemVerVersionParser $versionParser; private PubLockParser $parser; protected function setUp(): void { - $this->packagePool = $this->prophesize(PubPackagePool::class); - $this->versionParser = $this->prophesize(SemVerVersionParser::class); + $this->packagePool = $this->createMock(PubPackagePool::class); + $this->versionParser = $this->createMock(SemVerVersionParser::class); $this->parser = new PubLockParser( - $this->packagePool->reveal(), - $this->versionParser->reveal(), + $this->packagePool, + $this->versionParser, ); } public function test(): void { - $cache = $this->prophesize(Package::class)->reveal(); - $fooBarVersion = $this->prophesize(SemVerVersion::class)->reveal(); - $barBazVersion = $this->prophesize(SemVerVersion::class)->reveal(); + $cache = $this->createStub(Package::class); + $fooVersion = $this->createStub(SemVerVersion::class); + $barVersion = $this->createStub(SemVerVersion::class); + + $this->packagePool->method('get')->willReturnCallback(fn (string $name) => match ($name) { + 'foo' => null, + 'bar' => $cache, + default => $this->fail('unexpected pattern'), + }); - $this->packagePool->get('foo')->willReturn(null); - $this->packagePool->get('bar')->willReturn($cache); - $this->packagePool->add(Argument::type(Package::class))->shouldBeCalledOnce(); + $this->packagePool->expects($this->once())->method('add')->with($this->isInstanceOf(Package::class)); - $this->versionParser->parse('1.2.3-dev')->willReturn($fooBarVersion); - $this->versionParser->parse('3.2.1')->willReturn($barBazVersion); + $this->versionParser->method('parse')->willReturnMap([ + ['1.2.3-dev', $fooVersion], + ['3.2.1', $barVersion], + ]); $collection = $this->parser->parse(self::CONTENTS); $dependencies = $collection->getDependencies(); @@ -68,9 +62,9 @@ public function test(): void $this->assertContainsOnlyInstancesOf(Dependency::class, $dependencies); $this->assertSame('foo', $dependencies[0]->getPackage()->getName()); - $this->assertSame($fooBarVersion, $dependencies[0]->getVersion()); + $this->assertSame($fooVersion, $dependencies[0]->getVersion()); $this->assertSame($cache, $dependencies[1]->getPackage()); - $this->assertSame($barBazVersion, $dependencies[1]->getVersion()); + $this->assertSame($barVersion, $dependencies[1]->getVersion()); } } diff --git a/tests/Scanner/Pub/PubScannerTest.php b/tests/Scanner/Pub/PubScannerTest.php index cadae88..84c2a1a 100644 --- a/tests/Scanner/Pub/PubScannerTest.php +++ b/tests/Scanner/Pub/PubScannerTest.php @@ -4,30 +4,21 @@ namespace Siketyan\Loxcan\Scanner\Pub; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\DependencyCollectionPair; use Siketyan\Loxcan\Model\FileDiff; class PubScannerTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $parser; + private MockObject&PubLockParser $parser; private PubScanner $scanner; protected function setUp(): void { - $this->parser = $this->prophesize(PubLockParser::class); - - $this->scanner = new PubScanner( - $this->parser->reveal(), - ); + $this->parser = $this->createMock(PubLockParser::class); + $this->scanner = new PubScanner($this->parser); } public function test(): void @@ -35,17 +26,19 @@ public function test(): void $beforeFile = 'dummy_before'; $afterFile = 'dummy_after'; - $fileDiff = $this->prophesize(FileDiff::class); - $fileDiff->getBefore()->willReturn($beforeFile); - $fileDiff->getAfter()->willReturn($afterFile); + $fileDiff = $this->createStub(FileDiff::class); + $fileDiff->method('getBefore')->willReturn($beforeFile); + $fileDiff->method('getAfter')->willReturn($afterFile); - $before = $this->prophesize(DependencyCollection::class)->reveal(); - $after = $this->prophesize(DependencyCollection::class)->reveal(); + $before = $this->createStub(DependencyCollection::class); + $after = $this->createStub(DependencyCollection::class); - $this->parser->parse($beforeFile)->willReturn($before); - $this->parser->parse($afterFile)->willReturn($after); + $this->parser->method('parse')->willReturnMap([ + [$beforeFile, $before], + [$afterFile, $after], + ]); - $pair = $this->scanner->scan($fileDiff->reveal()); + $pair = $this->scanner->scan($fileDiff); $this->assertInstanceOf(DependencyCollectionPair::class, $pair); $this->assertSame($before, $pair->getBefore()); diff --git a/tests/Scanner/ScannerResolverTest.php b/tests/Scanner/ScannerResolverTest.php index 2551b08..3792459 100644 --- a/tests/Scanner/ScannerResolverTest.php +++ b/tests/Scanner/ScannerResolverTest.php @@ -5,51 +5,44 @@ namespace Siketyan\Loxcan\Scanner; use Eloquent\Pathogen\PathInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; class ScannerResolverTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $fooScanner; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $barScanner; - + private MockObject&ScannerInterface $fooScanner; + private MockObject&ScannerInterface $barScanner; private ScannerResolver $resolver; protected function setUp(): void { - $this->fooScanner = $this->prophesize(ScannerInterface::class); - $this->barScanner = $this->prophesize(ScannerInterface::class); + $this->fooScanner = $this->createMock(ScannerInterface::class); + $this->barScanner = $this->createMock(ScannerInterface::class); $this->resolver = new ScannerResolver([ - $this->fooScanner->reveal(), - $this->barScanner->reveal(), + $this->fooScanner, + $this->barScanner, ]); } public function test(): void { - $foo = $this->prophesize(PathInterface::class)->reveal(); - $bar = $this->prophesize(PathInterface::class)->reveal(); - $dummy = $this->prophesize(PathInterface::class)->reveal(); - - $this->fooScanner->supports($foo)->willReturn(true); - $this->fooScanner->supports(Argument::type(PathInterface::class))->willReturn(false); - $this->barScanner->supports($bar)->willReturn(true); - $this->barScanner->supports(Argument::type(PathInterface::class))->willReturn(false); - - $this->assertSame($this->fooScanner->reveal(), $this->resolver->resolve($foo)); - $this->assertSame($this->barScanner->reveal(), $this->resolver->resolve($bar)); + $foo = $this->createStub(PathInterface::class); + $bar = $this->createStub(PathInterface::class); + $dummy = $this->createStub(PathInterface::class); + + $this->fooScanner->method('supports')->willReturnCallback(static fn (PathInterface $p) => match ($p) { + $foo => true, + default => false, + }); + + $this->barScanner->method('supports')->willReturnCallback(static fn (PathInterface $p) => match ($p) { + $bar => true, + default => false, + }); + + $this->assertSame($this->fooScanner, $this->resolver->resolve($foo)); + $this->assertSame($this->barScanner, $this->resolver->resolve($bar)); $this->assertNull($this->resolver->resolve($dummy)); } } diff --git a/tests/Scanner/Yarn/YarnLockParserTest.php b/tests/Scanner/Yarn/YarnLockParserTest.php index 84194a6..8b58710 100644 --- a/tests/Scanner/Yarn/YarnLockParserTest.php +++ b/tests/Scanner/Yarn/YarnLockParserTest.php @@ -4,10 +4,8 @@ namespace Siketyan\Loxcan\Scanner\Yarn; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\Dependency; use Siketyan\Loxcan\Model\Package; use Siketyan\Loxcan\Versioning\SemVer\SemVerVersion; @@ -15,8 +13,6 @@ class YarnLockParserTest extends TestCase { - use ProphecyTrait; - private const CONTENTS = <<<'EOS' # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 @@ -33,41 +29,39 @@ class YarnLockParserTest extends TestCase integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== EOS; - /** - * @var ObjectProphecy - */ - private ObjectProphecy $packagePool; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $versionParser; - + private MockObject&YarnPackagePool $packagePool; + private MockObject&SemVerVersionParser $versionParser; private YarnLockParser $parser; protected function setUp(): void { - $this->packagePool = $this->prophesize(YarnPackagePool::class); - $this->versionParser = $this->prophesize(SemVerVersionParser::class); + $this->packagePool = $this->createMock(YarnPackagePool::class); + $this->versionParser = $this->createMock(SemVerVersionParser::class); $this->parser = new YarnLockParser( - $this->packagePool->reveal(), - $this->versionParser->reveal(), + $this->packagePool, + $this->versionParser, ); } public function test(): void { - $cache = $this->prophesize(Package::class)->reveal(); - $fooBarVersion = $this->prophesize(SemVerVersion::class)->reveal(); - $barBazVersion = $this->prophesize(SemVerVersion::class)->reveal(); + $cache = $this->createStub(Package::class); + $typesNodeVersion = $this->createStub(SemVerVersion::class); + $typescriptVersion = $this->createStub(SemVerVersion::class); + + $this->packagePool->method('get')->willReturnCallback(fn (string $name) => match ($name) { + '@types/node' => null, + 'typescript' => $cache, + default => $this->fail('unexpected pattern'), + }); - $this->packagePool->get('@types/node', '^18')->willReturn(null); - $this->packagePool->get('typescript', '^5')->willReturn($cache); - $this->packagePool->add(Argument::type(Package::class))->shouldBeCalledOnce(); + $this->packagePool->expects($this->once())->method('add')->with($this->isInstanceOf(Package::class)); - $this->versionParser->parse('18.16.16')->willReturn($fooBarVersion); - $this->versionParser->parse('5.0.4')->willReturn($barBazVersion); + $this->versionParser->method('parse')->willReturnMap([ + ['18.16.16', $typesNodeVersion], + ['5.0.4', $typescriptVersion], + ]); $collection = $this->parser->parse(self::CONTENTS); $dependencies = $collection->getDependencies(); @@ -76,9 +70,9 @@ public function test(): void $this->assertContainsOnlyInstancesOf(Dependency::class, $dependencies); $this->assertSame('@types/node', $dependencies[0]->getPackage()->getName()); - $this->assertSame($fooBarVersion, $dependencies[0]->getVersion()); + $this->assertSame($typesNodeVersion, $dependencies[0]->getVersion()); $this->assertSame($cache, $dependencies[1]->getPackage()); - $this->assertSame($barBazVersion, $dependencies[1]->getVersion()); + $this->assertSame($typescriptVersion, $dependencies[1]->getVersion()); } } diff --git a/tests/Scanner/Yarn/YarnScannerTest.php b/tests/Scanner/Yarn/YarnScannerTest.php index 2dc1712..f6e071b 100644 --- a/tests/Scanner/Yarn/YarnScannerTest.php +++ b/tests/Scanner/Yarn/YarnScannerTest.php @@ -4,30 +4,21 @@ namespace Siketyan\Loxcan\Scanner\Yarn; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Model\DependencyCollection; use Siketyan\Loxcan\Model\DependencyCollectionPair; use Siketyan\Loxcan\Model\FileDiff; class YarnScannerTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $parser; + private MockObject&YarnLockParser $parser; private YarnScanner $scanner; protected function setUp(): void { - $this->parser = $this->prophesize(YarnLockParser::class); - - $this->scanner = new YarnScanner( - $this->parser->reveal(), - ); + $this->parser = $this->createMock(YarnLockParser::class); + $this->scanner = new YarnScanner($this->parser); } public function test(): void @@ -35,17 +26,19 @@ public function test(): void $beforeFile = 'dummy_before'; $afterFile = 'dummy_after'; - $fileDiff = $this->prophesize(FileDiff::class); - $fileDiff->getBefore()->willReturn($beforeFile); - $fileDiff->getAfter()->willReturn($afterFile); + $fileDiff = $this->createStub(FileDiff::class); + $fileDiff->method('getBefore')->willReturn($beforeFile); + $fileDiff->method('getAfter')->willReturn($afterFile); - $before = $this->prophesize(DependencyCollection::class)->reveal(); - $after = $this->prophesize(DependencyCollection::class)->reveal(); + $before = $this->createStub(DependencyCollection::class); + $after = $this->createStub(DependencyCollection::class); - $this->parser->parse($beforeFile)->willReturn($before); - $this->parser->parse($afterFile)->willReturn($after); + $this->parser->method('parse')->willReturnMap([ + [$beforeFile, $before], + [$afterFile, $after], + ]); - $pair = $this->scanner->scan($fileDiff->reveal()); + $pair = $this->scanner->scan($fileDiff); $this->assertInstanceOf(DependencyCollectionPair::class, $pair); $this->assertSame($before, $pair->getBefore()); diff --git a/tests/UseCase/ScanUseCaseTest.php b/tests/UseCase/ScanUseCaseTest.php index 99e602d..b7000e2 100644 --- a/tests/UseCase/ScanUseCaseTest.php +++ b/tests/UseCase/ScanUseCaseTest.php @@ -6,10 +6,8 @@ use Eloquent\Pathogen\PathInterface; use Eloquent\Pathogen\RelativePathInterface; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Siketyan\Loxcan\Comparator\DependencyCollectionComparator; use Siketyan\Loxcan\Git\Git; use Siketyan\Loxcan\Model\DependencyCollection; @@ -22,45 +20,31 @@ class ScanUseCaseTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $git; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $scannerResolver; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $comparator; - + private Git&MockObject $git; + private MockObject&ScannerResolver $scannerResolver; + private DependencyCollectionComparator&MockObject $comparator; private ScanUseCase $useCase; protected function setUp(): void { - $this->git = $this->prophesize(Git::class); - $this->scannerResolver = $this->prophesize(ScannerResolver::class); - $this->comparator = $this->prophesize(DependencyCollectionComparator::class); + $this->git = $this->createMock(Git::class); + $this->scannerResolver = $this->createMock(ScannerResolver::class); + $this->comparator = $this->createMock(DependencyCollectionComparator::class); $this->useCase = new ScanUseCase( - $this->git->reveal(), - $this->scannerResolver->reveal(), - $this->comparator->reveal(), + $this->git, + $this->scannerResolver, + $this->comparator, ); } public function test(): void { $makeRelativePath = function (string $path): RelativePathInterface { - $prophecy = $this->prophesize(RelativePathInterface::class); - $prophecy->string()->willReturn($path); + $stub = $this->createStub(RelativePathInterface::class); + $stub->method('string')->willReturn($path); - return $prophecy->reveal(); + return $stub; }; $base = 'main'; @@ -70,46 +54,47 @@ public function test(): void $makeRelativePath('./file2.php'), ]; - $file0Path = $this->prophesize(PathInterface::class); - $file0Path->string()->willReturn(__FILE__); - $file0Path = $file0Path->reveal(); + $file0Path = $this->createStub(PathInterface::class); + $file0Path->method('string')->willReturn(__FILE__); - $file1Path = $this->prophesize(PathInterface::class)->reveal(); + $file1Path = $this->createStub(PathInterface::class); - $repositoryPath = $this->prophesize(PathInterface::class); - $repositoryPath->join($files[0])->willReturn($file0Path); - $repositoryPath->join($files[1])->willReturn($file1Path); + $repositoryPath = $this->createStub(PathInterface::class); + $repositoryPath->method('join')->willReturnMap([ + [$files[0], $file0Path], + [$files[1], $file1Path], + ]); - $repository = $this->prophesize(Repository::class); - $repository->getPath()->willReturn($repositoryPath->reveal()); - $repository = $repository->reveal(); + $repository = $this->createStub(Repository::class); + $repository->method('getPath')->willReturn($repositoryPath); - $before = $this->prophesize(DependencyCollection::class)->reveal(); - $after = $this->prophesize(DependencyCollection::class)->reveal(); - $diff = $this->prophesize(DependencyCollectionDiff::class)->reveal(); + $before = $this->createStub(DependencyCollection::class); + $after = $this->createStub(DependencyCollection::class); + $diff = $this->createStub(DependencyCollectionDiff::class); - $pair = $this->prophesize(DependencyCollectionPair::class); - $pair->getBefore()->willReturn($before); - $pair->getAfter()->willReturn($after); + $pair = $this->createStub(DependencyCollectionPair::class); + $pair->method('getBefore')->willReturn($before); + $pair->method('getAfter')->willReturn($after); - $scanner = $this->prophesize(ScannerInterface::class); + $scanner = $this->createMock(ScannerInterface::class); - /* @noinspection PhpParamsInspection */ $scanner - ->scan(Argument::that(fn (FileDiff $d): bool => $d->getBefore() === 'foo')) + ->expects($this->once()) + ->method('scan') + ->with($this->callback(static fn (FileDiff $d): bool => $d->getBefore() === 'foo')) ->willReturn($pair) - ->shouldBeCalledOnce() ; - $this->git->fetchChangedFiles($repository, $base, $head)->willReturn($files)->shouldBeCalledOnce(); - $this->git->fetchOriginalFile($repository, $base, $files[0])->willReturn('foo')->shouldBeCalledOnce(); - $this->git->fetchOriginalFile($repository, $base, $files[1])->shouldNotBeCalled(); - $this->git->checkFileExists($repository, $base, $files[0])->willReturn(true)->shouldBeCalledOnce(); + $this->git->expects($this->once())->method('fetchChangedFiles')->with($repository, $base, $head)->willReturn($files); + $this->git->expects($this->once())->method('fetchOriginalFile')->with($repository, $base, $files[0])->willReturn('foo'); + $this->git->expects($this->once())->method('checkFileExists')->with($repository, $base, $files[0])->willReturn(true); - $this->scannerResolver->resolve($file0Path)->willReturn($scanner->reveal()); - $this->scannerResolver->resolve($file1Path)->willReturn(null); + $this->scannerResolver->method('resolve')->willReturnCallback(static fn (PathInterface $p) => match ($p) { + $file0Path => $scanner, + default => null, + }); - $this->comparator->compare($before, $after)->willReturn($diff); + $this->comparator->method('compare')->with($before, $after)->willReturn($diff); $diffs = $this->useCase->scan($repository, $base, $head); diff --git a/tests/Versioning/VersionComparatorResolverTest.php b/tests/Versioning/VersionComparatorResolverTest.php index 3f75052..7107297 100644 --- a/tests/Versioning/VersionComparatorResolverTest.php +++ b/tests/Versioning/VersionComparatorResolverTest.php @@ -4,52 +4,51 @@ namespace Siketyan\Loxcan\Versioning; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; class VersionComparatorResolverTest extends TestCase { - use ProphecyTrait; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $fooComparator; - - /** - * @var ObjectProphecy - */ - private ObjectProphecy $barComparator; - + private MockObject&VersionComparatorInterface $fooComparator; + private MockObject&VersionComparatorInterface $barComparator; private VersionComparatorResolver $resolver; protected function setUp(): void { - $this->fooComparator = $this->prophesize(VersionComparatorInterface::class); - $this->barComparator = $this->prophesize(VersionComparatorInterface::class); + $this->fooComparator = $this->createMock(VersionComparatorInterface::class); + $this->barComparator = $this->createMock(VersionComparatorInterface::class); $this->resolver = new VersionComparatorResolver([ - $this->fooComparator->reveal(), - $this->barComparator->reveal(), + $this->fooComparator, + $this->barComparator, ]); } public function test(): void { - $foo = $this->prophesize(FooVersion::class)->reveal(); - $bar = $this->prophesize(BarVersion::class)->reveal(); - $baz = $this->prophesize(BazVersion::class)->reveal(); - $dummy = $this->prophesize(VersionInterface::class)->reveal(); - - $this->fooComparator->supports($foo::class, $bar::class)->willReturn(true); - $this->fooComparator->supports(Argument::type('string'), Argument::type('string'))->willReturn(false); - $this->barComparator->supports($bar::class, $baz::class)->willReturn(true); - $this->barComparator->supports(Argument::type('string'), Argument::type('string'))->willReturn(false); - - $this->assertSame($this->fooComparator->reveal(), $this->resolver->resolve($foo, $bar)); - $this->assertSame($this->barComparator->reveal(), $this->resolver->resolve($bar, $baz)); + $foo = $this->createStub(FooVersion::class); + $bar = $this->createStub(BarVersion::class); + $baz = $this->createStub(BazVersion::class); + $dummy = $this->createStub(VersionInterface::class); + + $this->fooComparator + ->method('supports') + ->willReturnCallback(static fn (string $a, string $b) => match ([$a, $b]) { + [$foo::class, $bar::class] => true, + default => false, + }) + ; + + $this->barComparator + ->method('supports') + ->willReturnCallback(static fn (string $a, string $b) => match ([$a, $b]) { + [$bar::class, $baz::class] => true, + default => false, + }) + ; + + $this->assertSame($this->fooComparator, $this->resolver->resolve($foo, $bar)); + $this->assertSame($this->barComparator, $this->resolver->resolve($bar, $baz)); $this->assertNull($this->resolver->resolve($dummy, $dummy)); } }