Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevKit updates for 4.x branch #2467

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,5 +41,6 @@
$rectorConfig->skip([
ExceptionHandlerTypehintRector::class,
PreferPHPUnitThisCallRector::class,
NarrowUnusedSetUpDefinedPropertyRector::class,
]);
};
25 changes: 20 additions & 5 deletions tests/Controller/MediaAdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,28 @@ public function testListAction(): void
$this->configureSetCsrfToken('sonata.batch');
$this->configureRender('templateList', 'renderResponse');

$matcher = static::exactly(3);
/**
* @psalm-suppress DeprecatedMethod
* @psalm-suppress MissingClosureParamType
*/
$datagrid->expects(static::exactly(3))->method('setValue')->withConsecutive(
['context', null, 'another_context'],
['category', null, 1]
);
$datagrid->expects($matcher)->method('setValue')->willReturnCallback(static function (...$parameters) use ($matcher) {
/**
* @psalm-suppress InternalMethod
*/
if (1 === $matcher->getInvocationCount()) {
self::assertSame('context', $parameters[0]);
self::assertNull($parameters[1]);
self::assertSame('another_context', $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);
$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
Loading