Skip to content

Commit

Permalink
DevKit updates for 4.x branch (#1765)
Browse files Browse the repository at this point in the history
Co-authored-by: Vincent Langlet <vincentlanglet@hotmail.fr>
  • Loading branch information
SonataCI and VincentLanglet committed Sep 28, 2023
1 parent 258ba41 commit 4628cba
Show file tree
Hide file tree
Showing 25 changed files with 180 additions and 200 deletions.
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
]],
'php_unit_strict' => true,
'php_unit_test_case_static_method_calls' => true,
'php_unit_data_provider_name' => true,
'php_unit_data_provider_return_type' => true,
'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress', 'phpstan-var']],
'single_line_throw' => false,
'static_lambda' => true,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^5.0",
"rector/rector": "^0.17",
"rector/rector": "^0.18",
"sonata-project/block-bundle": "^4.2",
"sonata-project/entity-audit-bundle": "^1.1",
"symfony/browser-kit": "^5.4 || ^6.2",
Expand Down
8 changes: 8 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
Expand All @@ -30,12 +34,16 @@

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
PHPUnitLevelSetList::UP_TO_PHPUNIT_90,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
]);

$rectorConfig->importNames();
$rectorConfig->importShortClasses(false);
$rectorConfig->skip([
CountOnNullRector::class,
ExceptionHandlerTypehintRector::class,
AddSeeTestAnnotationRector::class,
PreferPHPUnitThisCallRector::class,
]);
};
1 change: 1 addition & 0 deletions src/Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function getDoctrineQuery(): Query
$existingOrders = [];
foreach ($queryBuilder->getDQLPart('orderBy') as $order) {
foreach ($order->getParts() as $part) {
\assert(\is_string($part));
$existingOrders[] = trim(str_replace([Criteria::DESC, Criteria::ASC], '', $part));
}
}
Expand Down
20 changes: 9 additions & 11 deletions tests/Builder/DatagridBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function setUp(): void
/**
* @phpstan-param class-string $pager
*
* @dataProvider getBaseDatagridData
* @dataProvider provideGetBaseDatagridCases
*/
public function testGetBaseDatagrid(string $pagerType, string $pager): void
{
Expand All @@ -103,17 +103,15 @@ public function testGetBaseDatagrid(string $pagerType, string $pager): void
/**
* @phpstan-return iterable<array-key, array{string, class-string}>
*/
public function getBaseDatagridData(): iterable
public function provideGetBaseDatagridCases(): iterable
{
return [
'simple' => [
Pager::TYPE_SIMPLE,
SimplePager::class,
],
'default' => [
Pager::TYPE_DEFAULT,
Pager::class,
],
yield 'simple' => [
Pager::TYPE_SIMPLE,
SimplePager::class,
];
yield 'default' => [
Pager::TYPE_DEFAULT,
Pager::class,
];
}

Expand Down
36 changes: 17 additions & 19 deletions tests/Builder/ListBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testCorrectFixedActionsFieldType(): void
}

/**
* @dataProvider fixFieldDescriptionData
* @dataProvider provideFixFieldDescriptionCases
*/
public function testFixFieldDescription(int $type, string $template): void
{
Expand All @@ -119,25 +119,23 @@ public function testFixFieldDescription(int $type, string $template): void
/**
* @phpstan-return iterable<array-key, array{int, string}>
*/
public function fixFieldDescriptionData(): iterable
public function provideFixFieldDescriptionCases(): iterable
{
return [
'one-to-one' => [
ClassMetadata::ONE_TO_ONE,
'@SonataAdmin/CRUD/Association/list_one_to_one.html.twig',
],
'many-to-one' => [
ClassMetadata::MANY_TO_ONE,
'@SonataAdmin/CRUD/Association/list_many_to_one.html.twig',
],
'one-to-many' => [
ClassMetadata::ONE_TO_MANY,
'@SonataAdmin/CRUD/Association/list_one_to_many.html.twig',
],
'many-to-many' => [
ClassMetadata::MANY_TO_MANY,
'@SonataAdmin/CRUD/Association/list_many_to_many.html.twig',
],
yield 'one-to-one' => [
ClassMetadata::ONE_TO_ONE,
'@SonataAdmin/CRUD/Association/list_one_to_one.html.twig',
];
yield 'many-to-one' => [
ClassMetadata::MANY_TO_ONE,
'@SonataAdmin/CRUD/Association/list_many_to_one.html.twig',
];
yield 'one-to-many' => [
ClassMetadata::ONE_TO_MANY,
'@SonataAdmin/CRUD/Association/list_one_to_many.html.twig',
];
yield 'many-to-many' => [
ClassMetadata::MANY_TO_MANY,
'@SonataAdmin/CRUD/Association/list_many_to_many.html.twig',
];
}

Expand Down
44 changes: 21 additions & 23 deletions tests/Builder/ShowBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testAddFieldWithType(): void
}

/**
* @dataProvider fixFieldDescriptionData
* @dataProvider provideFixFieldDescriptionCases
*/
public function testFixFieldDescription(string $type, int $mappingType, string $template): void
{
Expand All @@ -121,29 +121,27 @@ public function testFixFieldDescription(string $type, int $mappingType, string $
/**
* @phpstan-return iterable<array-key, array{string, int, string}>
*/
public function fixFieldDescriptionData(): iterable
public function provideFixFieldDescriptionCases(): iterable
{
return [
'one-to-one' => [
FieldDescriptionInterface::TYPE_ONE_TO_ONE,
ClassMetadata::ONE_TO_ONE,
'@SonataAdmin/CRUD/Association/show_one_to_one.html.twig',
],
'many-to-one' => [
FieldDescriptionInterface::TYPE_MANY_TO_ONE,
ClassMetadata::MANY_TO_ONE,
'@SonataAdmin/CRUD/Association/show_many_to_one.html.twig',
],
'one-to-many' => [
FieldDescriptionInterface::TYPE_ONE_TO_MANY,
ClassMetadata::ONE_TO_MANY,
'@SonataAdmin/CRUD/Association/show_one_to_many.html.twig',
],
'many-to-many' => [
FieldDescriptionInterface::TYPE_MANY_TO_MANY,
ClassMetadata::MANY_TO_MANY,
'@SonataAdmin/CRUD/Association/show_many_to_many.html.twig',
],
yield 'one-to-one' => [
FieldDescriptionInterface::TYPE_ONE_TO_ONE,
ClassMetadata::ONE_TO_ONE,
'@SonataAdmin/CRUD/Association/show_one_to_one.html.twig',
];
yield 'many-to-one' => [
FieldDescriptionInterface::TYPE_MANY_TO_ONE,
ClassMetadata::MANY_TO_ONE,
'@SonataAdmin/CRUD/Association/show_many_to_one.html.twig',
];
yield 'one-to-many' => [
FieldDescriptionInterface::TYPE_ONE_TO_MANY,
ClassMetadata::ONE_TO_MANY,
'@SonataAdmin/CRUD/Association/show_one_to_many.html.twig',
];
yield 'many-to-many' => [
FieldDescriptionInterface::TYPE_MANY_TO_MANY,
ClassMetadata::MANY_TO_MANY,
'@SonataAdmin/CRUD/Association/show_many_to_many.html.twig',
];
}

Expand Down
11 changes: 5 additions & 6 deletions tests/Datagrid/PagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@ public function testGetCurrentPageResults(): void
/**
* @phpstan-return iterable<array-key, array{class-string}>
*/
public function entityClassDataProvider(): iterable
public function provideCountResultsCases(): iterable
{
return [
[User::class], // single identifier
[UserBrowser::class], // composite identifier
];
yield [User::class];
// single identifier
yield [UserBrowser::class];
}

/**
* @phpstan-param class-string $className
*
* @dataProvider entityClassDataProvider
* @dataProvider provideCountResultsCases
*/
public function testCountResults(string $className): void
{
Expand Down
18 changes: 8 additions & 10 deletions tests/Datagrid/ProxyQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,18 @@ public function testSortOrderValidatesItsInput(): void
/**
* @phpstan-return iterable<array-key, array{string}>
*/
public function validSortOrders(): iterable
public function provideItAllowsSortOrdersWithStrangeCaseCases(): iterable
{
return [
['ASC'],
['DESC'],
['asc'],
['desc'],
['AsC'],
['deSc'],
];
yield ['ASC'];
yield ['DESC'];
yield ['asc'];
yield ['desc'];
yield ['AsC'];
yield ['deSc'];
}

/**
* @dataProvider validSortOrders
* @dataProvider provideItAllowsSortOrdersWithStrangeCaseCases
*/
public function testItAllowsSortOrdersWithStrangeCase(string $validValue): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,32 @@ final class AddAuditEntityCompilerPassTest extends AbstractCompilerPassTestCase
/**
* @phpstan-return iterable<array-key, array{bool, array<string, array{audit?: bool|null, class: class-string}>, class-string[]}>
*/
public function processDataProvider(): iterable
public function provideProcessCases(): iterable
{
return [
yield [
true,
[
true,
[
'admin1' => ['audit' => null, 'class' => Product::class],
'admin2' => ['audit' => true, 'class' => SimpleEntity::class],
'admin3' => ['audit' => false, 'class' => UuidEntity::class],
'admin4' => ['class' => VersionedEntity::class],
],
[
Product::class,
SimpleEntity::class,
VersionedEntity::class,
],
'admin1' => ['audit' => null, 'class' => Product::class],
'admin2' => ['audit' => true, 'class' => SimpleEntity::class],
'admin3' => ['audit' => false, 'class' => UuidEntity::class],
'admin4' => ['class' => VersionedEntity::class],
],
[
false,
[
'admin1' => ['audit' => null, 'class' => Product::class],
'admin2' => ['audit' => true, 'class' => SimpleEntity::class],
'admin3' => ['audit' => false, 'class' => UuidEntity::class],
'admin4' => ['class' => VersionedEntity::class],
],
[
SimpleEntity::class,
],
Product::class,
SimpleEntity::class,
VersionedEntity::class,
],
];
yield [
false,
[
'admin1' => ['audit' => null, 'class' => Product::class],
'admin2' => ['audit' => true, 'class' => SimpleEntity::class],
'admin3' => ['audit' => false, 'class' => UuidEntity::class],
'admin4' => ['class' => VersionedEntity::class],
],
[
SimpleEntity::class,
],
];
}
Expand All @@ -63,7 +61,7 @@ public function processDataProvider(): iterable
* @phpstan-param array<string, array{audit?: bool|null, class: class-string}> $services
* @phpstan-param class-string[] $expectedAuditedEntities
*
* @dataProvider processDataProvider
* @dataProvider provideProcessCases
*/
public function testProcess(bool $force, array $services, array $expectedAuditedEntities): void
{
Expand Down
8 changes: 4 additions & 4 deletions tests/FieldDescription/FieldDescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function testGetValueForMultiLevelEmbeddedObject(): void
}

/**
* @dataProvider getDescribesSingleValuedAssociationProvider
* @dataProvider provideDescribesSingleValuedAssociationCases
*/
public function testDescribesSingleValuedAssociation(string|int $mappingType, bool $expected): void
{
Expand All @@ -266,7 +266,7 @@ public function testDescribesSingleValuedAssociation(string|int $mappingType, bo
/**
* @phpstan-return iterable<array-key, array{0: string|int, 1: bool}>
*/
public function getDescribesSingleValuedAssociationProvider(): iterable
public function provideDescribesSingleValuedAssociationCases(): iterable
{
yield 'one to one' => [ClassMetadata::ONE_TO_ONE, true];
yield 'many to one' => [ClassMetadata::MANY_TO_ONE, true];
Expand All @@ -276,7 +276,7 @@ public function getDescribesSingleValuedAssociationProvider(): iterable
}

/**
* @dataProvider getDescribesCollectionValuedAssociationProvider
* @dataProvider provideDescribesCollectionValuedAssociationCases
*/
public function testDescribesCollectionValuedAssociation(string|int $mappingType, bool $expected): void
{
Expand All @@ -290,7 +290,7 @@ public function testDescribesCollectionValuedAssociation(string|int $mappingType
/**
* @phpstan-return iterable<array-key, array{0: string|int, 1: bool}>
*/
public function getDescribesCollectionValuedAssociationProvider(): iterable
public function provideDescribesCollectionValuedAssociationCases(): iterable
{
yield 'one to one' => [ClassMetadata::ONE_TO_ONE, false];
yield 'many to one' => [ClassMetadata::MANY_TO_ONE, false];
Expand Down
4 changes: 2 additions & 2 deletions tests/FieldDescription/FilterTypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setUp(): void
/**
* @param array<string, mixed> $expectedOptions
*
* @dataProvider guessDataProvider
* @dataProvider provideGuessCases
*
* @phpstan-param class-string $expectedType
*/
Expand All @@ -67,7 +67,7 @@ public function testGuess(
/**
* @phpstan-return iterable<array-key, array{int|string|null, class-string, array<string, mixed>, int}>
*/
public function guessDataProvider(): iterable
public function provideGuessCases(): iterable
{
yield [
null,
Expand Down
4 changes: 2 additions & 2 deletions tests/FieldDescription/TypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp(): void
/**
* @param array<string, mixed> $expectedOptions
*
* @dataProvider guessDataProvider
* @dataProvider provideGuessCases
*/
public function testGuess(
int|string|null $mappingType,
Expand All @@ -56,7 +56,7 @@ public function testGuess(
/**
* @phpstan-return iterable<array-key, array{int|string|null, string, array<string, mixed>, int}>
*/
public function guessDataProvider(): iterable
public function provideGuessCases(): iterable
{
yield [
null,
Expand Down

0 comments on commit 4628cba

Please sign in to comment.