From 483c6fb7170ad8486c54055cffb6ec32b1422a73 Mon Sep 17 00:00:00 2001 From: SonataCI Date: Wed, 13 Nov 2024 10:50:44 +0000 Subject: [PATCH 1/4] DevKit updates --- rector.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rector.php b/rector.php index b6dac16fc..744632387 100644 --- a/rector.php +++ b/rector.php @@ -19,6 +19,7 @@ use Rector\Config\RectorConfig; use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector; +use Rector\PHPUnit\CodeQuality\Rector\Class_\NarrowUnusedSetUpDefinedPropertyRector; use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; @@ -40,5 +41,6 @@ $rectorConfig->skip([ ExceptionHandlerTypehintRector::class, PreferPHPUnitThisCallRector::class, + NarrowUnusedSetUpDefinedPropertyRector::class, ]); }; From 65f68ffe55fa83bbdfbac8ed1c7ca35b637eea4f Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 13 Nov 2024 15:22:22 +0100 Subject: [PATCH 2/4] Fix --- composer.json | 1 + tests/Controller/MediaAdminControllerTest.php | 20 +++++++++++++++---- tests/Entity/MediaTest.php | 4 ++-- .../ProviderDataTransformerTest.php | 2 +- tests/Provider/BaseProviderTest.php | 8 +------- tests/Provider/DailyMotionProviderTest.php | 2 +- tests/Provider/ImageProviderTest.php | 19 +++++++++++------- tests/Provider/VimeoProviderTest.php | 2 +- tests/Provider/YouTubeProviderTest.php | 2 +- 9 files changed, 36 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 89243dab9..1e55d5854 100644 --- a/composer.json +++ b/composer.json @@ -77,6 +77,7 @@ "matthiasnoback/symfony-config-test": "^4.2 || ^5.1", "matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0", "phpstan/extension-installer": "^1.0", + "phpstan/phpdoc-parser": "^1.0", "phpstan/phpstan": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-strict-rules": "^1.0", diff --git a/tests/Controller/MediaAdminControllerTest.php b/tests/Controller/MediaAdminControllerTest.php index 97078cef4..a386712e0 100644 --- a/tests/Controller/MediaAdminControllerTest.php +++ b/tests/Controller/MediaAdminControllerTest.php @@ -128,14 +128,26 @@ public function testListAction(): void $this->configureSetFormTheme($formView, ['filterTheme']); $this->configureSetCsrfToken('sonata.batch'); $this->configureRender('templateList', 'renderResponse'); + /** + * @psalm-suppress DeprecatedMethod + */ + $matcher = static::exactly(3); /** * @psalm-suppress DeprecatedMethod */ - $datagrid->expects(static::exactly(3))->method('setValue')->withConsecutive( - ['context', null, 'another_context'], - ['category', null, 1] - ); + $datagrid->expects($matcher)->method('setValue')->willReturnCallback(function (...$parameters) use ($matcher) { + if ($matcher->getInvocationCount() === 1) { + $this->assertSame('context', $parameters[0]); + $this->assertSame(null, $parameters[1]); + $this->assertSame('another_context', $parameters[2]); + } + if ($matcher->getInvocationCount() === 2) { + $this->assertSame('category', $parameters[0]); + $this->assertSame(null, $parameters[1]); + $this->assertSame(1, $parameters[2]); + } + }); $datagrid->method('getForm')->willReturn($form); $contextManager->method('find')->with('another_context')->willReturn($context); $categoryManager->method('getRootCategoriesForContext')->with($context)->willReturn([$category]); diff --git a/tests/Entity/MediaTest.php b/tests/Entity/MediaTest.php index 25a237d2b..7c1aaf71b 100644 --- a/tests/Entity/MediaTest.php +++ b/tests/Entity/MediaTest.php @@ -24,8 +24,8 @@ public function testMetadata(): void $media->setProviderMetadata(['thumbnail_url' => 'http://pasloin.com/thumb.png']); - static::assertSame($media->getMetadataValue('thumbnail_url'), 'http://pasloin.com/thumb.png', '::getMetadataValue() return the good value'); - static::assertSame($media->getMetadataValue('thumbnail_url1', 'default'), 'default', '::getMetadataValue() return the default'); + static::assertSame('http://pasloin.com/thumb.png', $media->getMetadataValue('thumbnail_url'), '::getMetadataValue() return the good value'); + static::assertSame('default', $media->getMetadataValue('thumbnail_url1', 'default'), '::getMetadataValue() return the default'); static::assertNull($media->getMetadataValue('thumbnail_url1'), '::getMetadataValue() return the null value'); } diff --git a/tests/Form/DataTransformer/ProviderDataTransformerTest.php b/tests/Form/DataTransformer/ProviderDataTransformerTest.php index a61135a79..2ae64748b 100644 --- a/tests/Form/DataTransformer/ProviderDataTransformerTest.php +++ b/tests/Form/DataTransformer/ProviderDataTransformerTest.php @@ -129,7 +129,7 @@ public function testReverseTransformWithThrowingProviderThrowTransformationFaile $this->expectException(TransformationFailedException::class); $provider = $this->createMock(MediaProviderInterface::class); - $provider->expects(static::once())->method('transform')->will(static::throwException(new \Exception())); + $provider->expects(static::once())->method('transform')->willThrowException(new \Exception()); $pool = new Pool('default'); $pool->addProvider('default', $provider); diff --git a/tests/Provider/BaseProviderTest.php b/tests/Provider/BaseProviderTest.php index 3f3431410..dcfe521cb 100644 --- a/tests/Provider/BaseProviderTest.php +++ b/tests/Provider/BaseProviderTest.php @@ -44,13 +44,7 @@ public function getProvider(): MediaProviderInterface $cdn = $this->createStub(CDNInterface::class); $cdn->method('flushPaths')->willReturn((string) random_int(0, mt_getrandmax())); - $cdn->method('getFlushStatus') - ->will(static::onConsecutiveCalls( - CDNInterface::STATUS_OK, - CDNInterface::STATUS_TO_FLUSH, - CDNInterface::STATUS_WAITING, - CDNInterface::STATUS_OK - )); + $cdn->method('getFlushStatus')->willReturnOnConsecutiveCalls(CDNInterface::STATUS_OK, CDNInterface::STATUS_TO_FLUSH, CDNInterface::STATUS_WAITING, CDNInterface::STATUS_OK); $cdn->method('getPath')->willReturnCallback(static fn (string $path, bool $isFlushable): string => '/uploads/media/'.$path); $generator = new IdGenerator(); diff --git a/tests/Provider/DailyMotionProviderTest.php b/tests/Provider/DailyMotionProviderTest.php index 70f4456b7..63a67c153 100644 --- a/tests/Provider/DailyMotionProviderTest.php +++ b/tests/Provider/DailyMotionProviderTest.php @@ -230,7 +230,7 @@ public function testGetMetadataException(): void $this->expectExceptionCode(12); $client = $this->createMock(ClientInterface::class); - $client->expects(static::once())->method('sendRequest')->will(static::throwException(new \RuntimeException('First error on get', 12))); + $client->expects(static::once())->method('sendRequest')->willThrowException(new \RuntimeException('First error on get', 12)); $provider = $this->getProvider($client); diff --git a/tests/Provider/ImageProviderTest.php b/tests/Provider/ImageProviderTest.php index 4fbe01c6f..014e876ff 100644 --- a/tests/Provider/ImageProviderTest.php +++ b/tests/Provider/ImageProviderTest.php @@ -46,21 +46,26 @@ public function getProvider(array $allowedExtensions = [], array $allowedMimeTyp $mediumBox = new Box(500, 250); $largeBox = new Box(1000, 500); - $resizer->method('getBox')->will(static::onConsecutiveCalls( - $largeBox, // first properties call + $resizer->method('getBox')->willReturnOnConsecutiveCalls( + $largeBox, + // first properties call $mediumBox, $largeBox, - $mediumBox, // second call $mediumBox, + // second call + $mediumBox, + $largeBox, + $adminBox, + // Third call $largeBox, - $adminBox, // Third call - $largeBox, // Fourth call + // Fourth call $mediumBox, $largeBox, - $largeBox, // Fifth call + $largeBox, + // Fifth call $mediumBox, $largeBox - )); + ); $filesystem = new Filesystem(new Local(sys_get_temp_dir().'/sonata-media-bundle/var/', true)); $cdn = new Server('/uploads/media'); diff --git a/tests/Provider/VimeoProviderTest.php b/tests/Provider/VimeoProviderTest.php index 27cef9938..e77fe0c79 100644 --- a/tests/Provider/VimeoProviderTest.php +++ b/tests/Provider/VimeoProviderTest.php @@ -234,7 +234,7 @@ public function testGetMetadataException(): void $this->expectExceptionCode(12); $client = $this->createMock(ClientInterface::class); - $client->expects(static::once())->method('sendRequest')->will(static::throwException(new \RuntimeException('First error on get', 12))); + $client->expects(static::once())->method('sendRequest')->willThrowException(new \RuntimeException('First error on get', 12)); $provider = $this->getProvider($client); diff --git a/tests/Provider/YouTubeProviderTest.php b/tests/Provider/YouTubeProviderTest.php index a98e94f07..b52a2d201 100644 --- a/tests/Provider/YouTubeProviderTest.php +++ b/tests/Provider/YouTubeProviderTest.php @@ -239,7 +239,7 @@ public function testGetMetadataException(): void $this->expectExceptionCode(12); $client = $this->createMock(ClientInterface::class); - $client->expects(static::once())->method('sendRequest')->will(static::throwException(new \RuntimeException('First error on get', 12))); + $client->expects(static::once())->method('sendRequest')->willThrowException(new \RuntimeException('First error on get', 12)); $provider = $this->getProvider($client); From 0451918376265b09e353583b5ab88ee403a93cfb Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 13 Nov 2024 15:28:01 +0100 Subject: [PATCH 3/4] Fix --- tests/Controller/MediaAdminControllerTest.php | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/Controller/MediaAdminControllerTest.php b/tests/Controller/MediaAdminControllerTest.php index a386712e0..341e84b78 100644 --- a/tests/Controller/MediaAdminControllerTest.php +++ b/tests/Controller/MediaAdminControllerTest.php @@ -128,24 +128,27 @@ public function testListAction(): void $this->configureSetFormTheme($formView, ['filterTheme']); $this->configureSetCsrfToken('sonata.batch'); $this->configureRender('templateList', 'renderResponse'); - /** - * @psalm-suppress DeprecatedMethod - */ - $matcher = static::exactly(3); + $matcher = static::exactly(3); /** - * @psalm-suppress DeprecatedMethod + * @psalm-suppress MissingClosureParamType */ $datagrid->expects($matcher)->method('setValue')->willReturnCallback(function (...$parameters) use ($matcher) { - if ($matcher->getInvocationCount() === 1) { - $this->assertSame('context', $parameters[0]); - $this->assertSame(null, $parameters[1]); - $this->assertSame('another_context', $parameters[2]); + /** + * @psalm-suppress InternalMethod + */ + if (1 === $matcher->getInvocationCount()) { + self::assertSame('context', $parameters[0]); + self::assertNull($parameters[1]); + self::assertSame('another_context', $parameters[2]); } - if ($matcher->getInvocationCount() === 2) { - $this->assertSame('category', $parameters[0]); - $this->assertSame(null, $parameters[1]); - $this->assertSame(1, $parameters[2]); + /** + * @psalm-suppress InternalMethod + */ + if (2 === $matcher->getInvocationCount()) { + self::assertSame('category', $parameters[0]); + self::assertNull($parameters[1]); + self::assertSame(1, $parameters[2]); } }); $datagrid->method('getForm')->willReturn($form); From 9a2711976b3ed7ca338915b0414a416162fe9376 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 13 Nov 2024 15:30:56 +0100 Subject: [PATCH 4/4] Cs --- tests/Controller/MediaAdminControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Controller/MediaAdminControllerTest.php b/tests/Controller/MediaAdminControllerTest.php index 341e84b78..831a3f846 100644 --- a/tests/Controller/MediaAdminControllerTest.php +++ b/tests/Controller/MediaAdminControllerTest.php @@ -133,7 +133,7 @@ public function testListAction(): void /** * @psalm-suppress MissingClosureParamType */ - $datagrid->expects($matcher)->method('setValue')->willReturnCallback(function (...$parameters) use ($matcher) { + $datagrid->expects($matcher)->method('setValue')->willReturnCallback(static function (...$parameters) use ($matcher) { /** * @psalm-suppress InternalMethod */