Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Nov 13, 2024
1 parent a2ef4c4 commit d597ac9
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 24 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 16 additions & 4 deletions tests/Controller/MediaAdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,26 @@ public function testListAction(): void
$this->configureSetFormTheme($formView, ['filterTheme']);
$this->configureSetCsrfToken('sonata.batch');
$this->configureRender('templateList', 'renderResponse');
/**
* @psalm-suppress DeprecatedMethod

Check failure on line 132 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / Psalm

UnusedPsalmSuppress

tests/Controller/MediaAdminControllerTest.php:132:28: UnusedPsalmSuppress: This suppression is never used (see https://psalm.dev/207)
*/
$matcher = static::exactly(3);

/**
* @psalm-suppress DeprecatedMethod

Check failure on line 137 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / Psalm

UnusedPsalmSuppress

tests/Controller/MediaAdminControllerTest.php:137:28: UnusedPsalmSuppress: This suppression is never used (see https://psalm.dev/207)
*/
$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) {

Check failure on line 139 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / Psalm

MissingClosureParamType

tests/Controller/MediaAdminControllerTest.php:139:91: MissingClosureParamType: Parameter $parameters has no provided type (see https://psalm.dev/153)
if ($matcher->getInvocationCount() === 1) {

Check failure on line 140 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / Psalm

InternalMethod

tests/Controller/MediaAdminControllerTest.php:140:27: InternalMethod: The method PHPUnit\Framework\MockObject\Rule\InvocationOrder::getInvocationCount is internal to PHPUnit but called from Sonata\MediaBundle\Tests\Controller (see https://psalm.dev/175)
$this->assertSame('context', $parameters[0]);

Check failure on line 141 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Dynamic call to static method PHPUnit\Framework\Assert::assertSame().
$this->assertSame(null, $parameters[1]);

Check failure on line 142 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Dynamic call to static method PHPUnit\Framework\Assert::assertSame().

Check failure on line 142 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

You should use assertNull() instead of assertSame(null, $actual).
$this->assertSame('another_context', $parameters[2]);

Check failure on line 143 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Dynamic call to static method PHPUnit\Framework\Assert::assertSame().
}
if ($matcher->getInvocationCount() === 2) {

Check failure on line 145 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / Psalm

InternalMethod

tests/Controller/MediaAdminControllerTest.php:145:27: InternalMethod: The method PHPUnit\Framework\MockObject\Rule\InvocationOrder::getInvocationCount is internal to PHPUnit but called from Sonata\MediaBundle\Tests\Controller (see https://psalm.dev/175)
$this->assertSame('category', $parameters[0]);

Check failure on line 146 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Dynamic call to static method PHPUnit\Framework\Assert::assertSame().
$this->assertSame(null, $parameters[1]);

Check failure on line 147 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Dynamic call to static method PHPUnit\Framework\Assert::assertSame().

Check failure on line 147 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

You should use assertNull() instead of assertSame(null, $actual).
$this->assertSame(1, $parameters[2]);

Check failure on line 148 in tests/Controller/MediaAdminControllerTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Dynamic call to static method PHPUnit\Framework\Assert::assertSame().
}
});
$datagrid->method('getForm')->willReturn($form);
$contextManager->method('find')->with('another_context')->willReturn($context);
$categoryManager->method('getRootCategoriesForContext')->with($context)->willReturn([$category]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Entity/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Form/DataTransformer/ProviderDataTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 1 addition & 7 deletions tests/Provider/BaseProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/DailyMotionProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 12 additions & 7 deletions tests/Provider/ImageProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/VimeoProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/YouTubeProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d597ac9

Please sign in to comment.