diff --git a/.phpstan-baseline.neon b/.phpstan-baseline.neon index 8794a9167fd..d31591dd048 100644 --- a/.phpstan-baseline.neon +++ b/.phpstan-baseline.neon @@ -40675,46 +40675,6 @@ parameters: count: 1 path: tests/Unit/Components/DependencyInjection/Compiler/TagReplaceTraitTest.php - - - message: "#^Call to an undefined method Enlight_Event_EventArgs\\:\\:getSubject\\(\\)\\.$#" - count: 3 - path: tests/Unit/Components/DependencyInjection/ContainerTest.php - - - - message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:notify\\(\\)\\.$#" - count: 7 - path: tests/Unit/Components/DependencyInjection/ContainerTest.php - - - - message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:notifyUntil\\(\\)\\.$#" - count: 4 - path: tests/Unit/Components/DependencyInjection/ContainerTest.php - - - - message: "#^Service \"alias\" is not registered in the container\\.$#" - count: 1 - path: tests/Unit/Components/DependencyInjection/ContainerTest.php - - - - message: "#^Service \"bar\" is not registered in the container\\.$#" - count: 3 - path: tests/Unit/Components/DependencyInjection/ContainerTest.php - - - - message: "#^Service \"foo\" is not registered in the container\\.$#" - count: 5 - path: tests/Unit/Components/DependencyInjection/ContainerTest.php - - - - message: "#^Service \"parent\" is not registered in the container\\.$#" - count: 3 - path: tests/Unit/Components/DependencyInjection/ContainerTest.php - - - - message: "#^Service \"someKey\" is not registered in the container\\.$#" - count: 1 - path: tests/Unit/Components/DependencyInjection/ContainerTest.php - - message: "#^Property Shopware\\\\Tests\\\\Unit\\\\Components\\\\DependencyInjection\\\\ProjectServiceContainer\\:\\:\\$__bar has no type specified\\.$#" count: 1 diff --git a/.phpstan.neon b/.phpstan.neon index bdaa52e9e03..d8ce644c921 100644 --- a/.phpstan.neon +++ b/.phpstan.neon @@ -199,3 +199,7 @@ parameters: message: '#Parameter \#1 \$calculationType of method Shopware\\Bundle\\OrderBundle\\Service\\ShippingCostService::getShippingCostMultiplier\(\) expects 0\|1\|2\|3, 99 given#' count: 1 path: tests/Unit/Bundle/OrderBundle/ShippingConstServiceTest.php + + - # Test services are not recognized correctly by PHPStan in this container test class + message: '#Service ".*" is not registered in the container#' + path: tests/Unit/Components/DependencyInjection/ContainerTest.php diff --git a/UPGRADE-5.7.md b/UPGRADE-5.7.md index bc3bd587f6f..d54ee1138cc 100644 --- a/UPGRADE-5.7.md +++ b/UPGRADE-5.7.md @@ -33,6 +33,9 @@ This changelog references changes done in Shopware 5.7 patch versions. * Updated npm dependencies in `themes/package.json` * Updated npm dependencies in `themes/Frontend/Responsive/package.json` +### Removals + +* Removed development dependency `phpspec/prophecy-phpunit` as it is no longer used due to a refactoring of a PHPUnit test ## 5.7.19 diff --git a/composer.json b/composer.json index 52a70ac0fec..24c08f0b716 100644 --- a/composer.json +++ b/composer.json @@ -111,7 +111,6 @@ "behat/mink-selenium2-driver": "1.6.0", "friends-of-behat/mink-extension": "2.7.4", "php-parallel-lint/php-var-dump-check": "^0.5", - "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "1.3.1", "phpstan/phpstan": "1.10.41", "phpstan/phpstan-doctrine": "1.3.45", diff --git a/composer.lock b/composer.lock index 76cf84f14c6..67cbd5a519e 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": "684f2df29dc52cbfeeb671ca0c9a6e18", + "content-hash": "9ef53ecdf5e729d35bd9b0f804ee9af6", "packages": [ { "name": "aws/aws-crt-php", @@ -8264,294 +8264,6 @@ }, "time": "2020-08-17T12:12:52+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/extension-installer", "version": "1.3.1", @@ -8596,53 +8308,6 @@ }, "time": "2023-05-24T08:59:17+00:00" }, - { - "name": "phpstan/phpdoc-parser", - "version": "1.24.2", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "bcad8d995980440892759db0c32acae7c8e79442" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442", - "reference": "bcad8d995980440892759db0c32acae7c8e79442", - "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.2" - }, - "time": "2023-09-26T12:28:12+00:00" - }, { "name": "phpstan/phpstan", "version": "1.10.41", @@ -10855,64 +10520,6 @@ } ], "time": "2021-07-28T10:34:58+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/Unit/Components/DependencyInjection/ContainerTest.php b/tests/Unit/Components/DependencyInjection/ContainerTest.php index 66cec512284..0e01da8867a 100644 --- a/tests/Unit/Components/DependencyInjection/ContainerTest.php +++ b/tests/Unit/Components/DependencyInjection/ContainerTest.php @@ -27,8 +27,6 @@ use Enlight_Event_EventManager; use Exception; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Shopware\Components\ContainerAwareEventManager; use Shopware\Components\DependencyInjection\Container; use stdClass; @@ -37,12 +35,7 @@ class ContainerTest extends TestCase { - use ProphecyTrait; - - /** - * @var Container - */ - private $container; + private Container $container; protected function setUp(): void { @@ -97,46 +90,61 @@ public function testGetOnNonExistentWithIgnoreBehaviour(): void public function testEventsAreEmittedDuringServiceInitialisation(): void { - $service = $this->prophesize(Enlight_Event_EventManager::class); - - $service->notify('Enlight_Bootstrap_AfterRegisterResource_events', Argument::any())->shouldBeCalled(); - $service->notifyUntil('Enlight_Bootstrap_InitResource_bar', Argument::any())->shouldBeCalled(); - $service->notify('Enlight_Bootstrap_AfterInitResource_bar', Argument::any())->shouldBeCalled(); + $eventManager = $this->createMock(Enlight_Event_EventManager::class); + $eventManager->expects(static::exactly(2)) + ->method('notify') + ->with(static::logicalOr( + 'Enlight_Bootstrap_AfterRegisterResource_events', + 'Enlight_Bootstrap_AfterInitResource_bar' + )); + $eventManager->expects(static::once()) + ->method('notifyUntil') + ->with('Enlight_Bootstrap_InitResource_bar'); - $service = $service->reveal(); - $this->container->set('events', $service); + $this->container->set('events', $eventManager); static::assertInstanceOf('stdClass', $this->container->get('bar')); } public function testEventsAreEmitedDuringServiceInitialisationWhenUsingAlias(): void { - $service = $this->prophesize(Enlight_Event_EventManager::class); - - $service->notify('Enlight_Bootstrap_AfterRegisterResource_events', Argument::any())->shouldBeCalled(); - $service->notifyUntil('Enlight_Bootstrap_InitResource_bar', Argument::any())->shouldBeCalled(); - $service->notifyUntil('Enlight_Bootstrap_InitResource_alias', Argument::any())->shouldBeCalled(); - $service->notify('Enlight_Bootstrap_AfterInitResource_bar', Argument::any())->shouldBeCalled(); - $service->notify('Enlight_Bootstrap_AfterInitResource_alias', Argument::any())->shouldBeCalled(); + $eventManager = $this->createMock(Enlight_Event_EventManager::class); + $eventManager->expects(static::exactly(3)) + ->method('notify') + ->with(static::logicalOr( + 'Enlight_Bootstrap_AfterRegisterResource_events', + 'Enlight_Bootstrap_AfterInitResource_bar', + 'Enlight_Bootstrap_AfterInitResource_alias' + )); + $eventManager->expects(static::exactly(2)) + ->method('notifyUntil') + ->with(static::logicalOr( + 'Enlight_Bootstrap_InitResource_bar', + 'Enlight_Bootstrap_InitResource_alias' + )); - $service = $service->reveal(); - $this->container->set('events', $service); + $this->container->set('events', $eventManager); static::assertInstanceOf('stdClass', $this->container->get('alias')); } public function testEventsAreEmitedDuringServiceInitialisationWhenUsingUnknownServices(): void { - $service = $this->prophesize(Enlight_Event_EventManager::class); - - $service->notify('Enlight_Bootstrap_AfterRegisterResource_events', Argument::any())->shouldBeCalled(); - $service->notifyUntil('Enlight_Bootstrap_InitResource_foo', Argument::any())->shouldBeCalled(); - $service->notify('Enlight_Bootstrap_AfterInitResource_foo', Argument::any())->shouldBeCalled(); + $eventManager = $this->createMock(Enlight_Event_EventManager::class); + $eventManager->expects(static::exactly(2)) + ->method('notify') + ->with(static::logicalOr( + 'Enlight_Bootstrap_AfterRegisterResource_events', + 'Enlight_Bootstrap_AfterInitResource_foo' + )); + $eventManager->expects(static::once()) + ->method('notifyUntil') + ->with('Enlight_Bootstrap_InitResource_foo'); - $service = $service->reveal(); - $this->container->set('events', $service); + $this->container->set('events', $eventManager); $this->expectException(Exception::class); + $this->expectExceptionMessage('You have requested a non-existent service "foo".'); $this->container->get('foo'); } @@ -153,8 +161,9 @@ public function testAfterInitEventDecorator(): void $this->container->get('events')->addListener( 'Enlight_Bootstrap_AfterInitResource_bar', function (Enlight_Event_EventArgs $e) use ($class) { - /** @var ProjectServiceContainer $container */ - $container = $e->getSubject(); + $container = $e->get('subject'); + self::assertInstanceOf(ProjectServiceContainer::class, $container); + $container->set('bar', $class); } ); @@ -190,8 +199,8 @@ public function testServiceCircularReferenceExceptionException(): void $this->container->get('events')->addListener( 'Enlight_Bootstrap_InitResource_child', function (Enlight_Event_EventArgs $e) { - /** @var ProjectServiceContainer $container */ - $container = $e->getSubject(); + $container = $e->get('subject'); + self::assertInstanceOf(ProjectServiceContainer::class, $container); // Cause circular reference $container->get('parent'); @@ -201,8 +210,8 @@ function (Enlight_Event_EventArgs $e) { $this->container->get('events')->addListener( 'Enlight_Bootstrap_AfterInitResource_parent', function (Enlight_Event_EventArgs $e) { - /** @var ProjectServiceContainer $container */ - $container = $e->getSubject(); + $container = $e->get('subject'); + self::assertInstanceOf(ProjectServiceContainer::class, $container); $coreParent = $container->get('parent');