diff --git a/.gitattributes b/.gitattributes index f05c45e..4968ba0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,7 @@ -.editorconfig export-ignore -.gitattributes export-ignore -/.github/ export-ignore -.gitignore export-ignore -/.php_cs export-ignore -/phpunit.xml.dist export-ignore -/tests/ export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +/.github/ export-ignore +.gitignore export-ignore +/.php-cs-fixer.php export-ignore +/phpunit.xml.dist export-ignore +/tests/ export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06e80e5..afb4c74 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,11 +8,11 @@ jobs: strategy: max-parallel: 10 matrix: - php: [ '7.2', '7.3', '7.4', '8.0'] - sf_version: [ '4.4.*', '5.3.*' ] + php: [ '8.0', '8.1'] + sf_version: [ '5.4.*', '6.0.*'] include: - - php: 8.0 - sf_version: '6.0.*' + - php: 7.2 + sf_version: '5.4.*' steps: - name: Set up PHP diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 7d8b221..521f6ce 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -13,9 +13,9 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 coverage: none - tools: phpstan:0.12.92, cs2pr + tools: phpstan:1.5.3, cs2pr - name: Download dependencies uses: ramsey/composer-install@v1 @@ -34,9 +34,9 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 coverage: none - tools: php-cs-fixer:2.19.0, cs2pr + tools: php-cs-fixer:3.8.0, cs2pr - name: PHP-CS-Fixer run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr @@ -51,9 +51,9 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 coverage: none - tools: vimeo/psalm:4.8.1 + tools: vimeo/psalm:4.22.0 - name: Download dependencies uses: ramsey/composer-install@v1 diff --git a/.gitignore b/.gitignore index a398fd9..d7d3a9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/.php_cs.cache +/.php-cs-fixer.cache /.phpunit.result.cache /composer.lock /phpunit.xml diff --git a/.php_cs b/.php-cs-fixer.php similarity index 65% rename from .php_cs rename to .php-cs-fixer.php index 222d320..90d5d60 100644 --- a/.php_cs +++ b/.php-cs-fixer.php @@ -1,11 +1,11 @@ in(__DIR__.'/src') ->in(__DIR__.'/tests') ; -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setRules([ '@Symfony' => true, ]) diff --git a/composer.json b/composer.json index 59e3ff6..4093a23 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,13 @@ { "name": "happyr/service-mocking", - "type": "symfony-bundle", "description": "Make it easy to mock services in a built container", + "license": "MIT", + "type": "symfony-bundle", "keywords": [ "Symfony", "testing", "mock" ], - "license": "MIT", "authors": [ { "name": "Tobias Nyholm", @@ -17,14 +17,16 @@ "require": { "php": ">=7.2", "friendsofphp/proxy-manager-lts": "^1.0", - "symfony/config": "^4.4 || ^5.1 || ^6.0", - "symfony/dependency-injection": "^4.4 || ^5.1 || ^6.0", - "symfony/http-kernel": "^4.4 || ^5.1 || ^6.0" + "symfony/config": "^5.4 || ^6.0", + "symfony/dependency-injection": "^5.4 || ^6.0", + "symfony/http-kernel": "^5.4 || ^6.0" }, "require-dev": { - "nyholm/symfony-bundle-test": "^1.6", - "symfony/phpunit-bridge": "^5.3" + "nyholm/symfony-bundle-test": "dev-clear-cache", + "symfony/phpunit-bridge": "^6.0" }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "Happyr\\ServiceMocking\\": "src/" @@ -34,7 +36,5 @@ "psr-4": { "Happyr\\ServiceMocking\\Tests\\": "tests/" } - }, - "minimum-stability": "dev", - "prefer-stable": true + } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7d6b4cc..171b24e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,6 +5,11 @@ parameters: count: 1 path: src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php + - + message: "#^Parameter \\#1 \\$class of method Symfony\\\\Component\\\\DependencyInjection\\\\Definition\\:\\:setClass\\(\\) expects string\\|null, false given\\.$#" + count: 1 + path: src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php + - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" count: 1 diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 65c19ff..ce443d5 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -1,5 +1,5 @@ - + getWrappedValueHolderValue @@ -15,8 +15,23 @@ fn + + + , + , + => + fn + + + + + $item1 + ) + fn + + - + $left $type $type @@ -30,12 +45,17 @@ , fn fn + fn + fn - + + $type $type ) + ) + fn fn diff --git a/src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php b/src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php index c69439c..dfb05b4 100644 --- a/src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php +++ b/src/DependencyInjection/CompilerPass/ProxyServiceWithMockPass.php @@ -13,6 +13,7 @@ class ProxyServiceWithMockPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { + /** @var array $serviceIds */ $serviceIds = $container->getParameter('happyr_service_mock.services'); foreach ($container->findTaggedServiceIds('happyr_service_mock') as $id => $tags) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index d2bbf49..4215f41 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -10,7 +10,7 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('happyr_service_mocking'); diff --git a/src/Generator/LazyLoadingValueHolderGenerator.php b/src/Generator/LazyLoadingValueHolderGenerator.php index bfa081a..34b05ae 100644 --- a/src/Generator/LazyLoadingValueHolderGenerator.php +++ b/src/Generator/LazyLoadingValueHolderGenerator.php @@ -64,7 +64,7 @@ class LazyLoadingValueHolderGenerator implements ProxyGeneratorInterface * * @psalm-param array{skipDestructor?: bool, fluentSafe?: bool} $proxyOptions */ - public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator/*, array $proxyOptions = []*/) + public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator/* , array $proxyOptions = [] */) { /** @psalm-var array{skipDestructor?: bool, fluentSafe?: bool} $proxyOptions */ $proxyOptions = func_num_args() >= 3 ? func_get_arg(2) : []; diff --git a/src/ServiceMock.php b/src/ServiceMock.php index fd9a12f..5a2f1e4 100644 --- a/src/ServiceMock.php +++ b/src/ServiceMock.php @@ -55,7 +55,7 @@ public static function all($proxy, string $methodName, callable $func): void */ public static function resetAll(): void { - foreach (static::$definitions as $definition) { + foreach (self::$definitions as $definition) { $definition->clear(); } } diff --git a/tests/Functional/BundleInitializationTest.php b/tests/Functional/BundleInitializationTest.php index 3b9d5cd..4b03dba 100644 --- a/tests/Functional/BundleInitializationTest.php +++ b/tests/Functional/BundleInitializationTest.php @@ -7,28 +7,43 @@ use Happyr\ServiceMocking\HappyrServiceMockingBundle; use Happyr\ServiceMocking\ServiceMock; use Happyr\ServiceMocking\Tests\Resource\ExampleService; +use Happyr\ServiceMocking\Tests\Resource\Kernel; use Happyr\ServiceMocking\Tests\Resource\ServiceWithFactory; use Happyr\ServiceMocking\Tests\Resource\StatefulService; -use Nyholm\BundleTest\BaseBundleTestCase; use ProxyManager\Proxy\VirtualProxyInterface; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\HttpKernel\KernelInterface; -class BundleInitializationTest extends BaseBundleTestCase +class BundleInitializationTest extends KernelTestCase { - protected function getBundleClass() + protected static function getKernelClass(): string { - return HappyrServiceMockingBundle::class; + return Kernel::class; } - public function testInitBundle() + protected static function createKernel(array $options = []): KernelInterface { - $kernel = $this->createKernel(); - $kernel->addConfigFile(__DIR__.'/config.yml'); - - // Boot the kernel. - $this->bootKernel(); + if (null !== static::$kernel) { + return static::$kernel; + } + /** + * @var Kernel $kernel + */ + $kernel = parent::createKernel($options); + $kernel->addTestBundle(HappyrServiceMockingBundle::class); + $configFile = $options['config_file'] ?? 'config.yml'; + $kernel->addTestConfig(__DIR__.'/'.$configFile); + unset($options['config_file']); + + $kernel->handleOptions($options); + + return $kernel; + } - // Get the container - $container = $this->getContainer(); + public function testInitBundle() + { + $kernel = self::bootKernel(); + $container = $kernel->getContainer(); $this->assertTrue($container->has(ExampleService::class)); $service = $container->get(ExampleService::class); @@ -74,11 +89,8 @@ public function testInitBundle() public function testRebootBundle() { - $kernel = $this->createKernel(); - $kernel->addConfigFile(__DIR__.'/config.yml'); - - $this->bootKernel(); - $container = $this->getContainer(); + $kernel = self::bootKernel(); + $container = $kernel->getContainer(); $this->assertTrue($container->has(StatefulService::class)); $service = $container->get(StatefulService::class); @@ -98,11 +110,8 @@ public function testRebootBundle() public function testReloadRealObjectOnRebootBundle() { - $kernel = $this->createKernel(); - $kernel->addConfigFile(__DIR__.'/config.yml'); - - $this->bootKernel(); - $container = $this->getContainer(); + $kernel = self::bootKernel(); + $container = $kernel->getContainer(); $this->assertTrue($container->has(StatefulService::class)); $service = $container->get(StatefulService::class); @@ -117,14 +126,8 @@ public function testReloadRealObjectOnRebootBundle() public function testInitEmptyBundle() { - $kernel = $this->createKernel(); - $kernel->addConfigFile(__DIR__.'/empty.yml'); - - // Boot the kernel. - $this->bootKernel(); - - // Get the container - $container = $this->getContainer(); + $kernel = self::bootKernel(['config_file' => 'empty.yml']); + $container = $kernel->getContainer(); $this->assertTrue($container->has(ExampleService::class)); $service = $container->get(ExampleService::class); diff --git a/tests/Resource/Kernel.php b/tests/Resource/Kernel.php new file mode 100644 index 0000000..0a79312 --- /dev/null +++ b/tests/Resource/Kernel.php @@ -0,0 +1,13 @@ +