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 #833

Merged
merged 3 commits into from
Oct 3, 2023
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
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 @@ -55,7 +55,7 @@
"phpunit/phpunit": "^9.6",
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^5.0",
"rector/rector": "^0.17",
"rector/rector": "^0.18",
"sonata-project/block-bundle": "^4.2",
"symfony/browser-kit": "^5.4 || ^6.2",
"symfony/css-selector": "^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,
]);
};
20 changes: 9 additions & 11 deletions tests/Builder/DatagridBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function setUp(): void
/**
* @phpstan-param class-string $pager
*
* @dataProvider getBaseDatagridData
* @dataProvider provideGetBaseDatagridCases
*/
public function testGetBaseDatagrid(string $pagerType, string $pager): void
{
Expand All @@ -102,17 +102,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
30 changes: 14 additions & 16 deletions tests/DependencyInjection/Compiler/AddGuesserCompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

final class AddGuesserCompilerPassTest extends AbstractCompilerPassTestCase
{
/** @dataProvider getBuilders */
/** @dataProvider provideAddsGuessersCases */
public function testAddsGuessers(string $builderServiceId, string $guesserTag): void
{
$builderService = new Definition(null, [[]]);
Expand All @@ -43,23 +43,21 @@ public function testAddsGuessers(string $builderServiceId, string $guesserTag):
}

/**
* @phpstan-return array<array{string, string}>
* @phpstan-return iterable<array{string, string}>
*/
public function getBuilders(): array
public function provideAddsGuessersCases(): iterable
{
return [
'list_builder' => [
'sonata.admin.guesser.doctrine_mongodb_list_chain',
'sonata.admin.guesser.doctrine_mongodb_list',
],
'datagrid_builder' => [
'sonata.admin.guesser.doctrine_mongodb_datagrid_chain',
'sonata.admin.guesser.doctrine_mongodb_datagrid',
],
'show_builder' => [
'sonata.admin.guesser.doctrine_mongodb_show_chain',
'sonata.admin.guesser.doctrine_mongodb_show',
],
yield 'list_builder' => [
'sonata.admin.guesser.doctrine_mongodb_list_chain',
'sonata.admin.guesser.doctrine_mongodb_list',
];
yield 'datagrid_builder' => [
'sonata.admin.guesser.doctrine_mongodb_datagrid_chain',
'sonata.admin.guesser.doctrine_mongodb_datagrid',
];
yield 'show_builder' => [
'sonata.admin.guesser.doctrine_mongodb_show_chain',
'sonata.admin.guesser.doctrine_mongodb_show',
];
}

Expand Down
94 changes: 46 additions & 48 deletions tests/FieldDescription/FilterTypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testGuessTypeWithAssociation(): void
}

/**
* @dataProvider noAssociationData
* @dataProvider provideGuessTypeNoAssociationCases
*/
public function testGuessTypeNoAssociation(string $type, string $resultType, int $confidence, ?string $fieldType = null): void
{
Expand Down Expand Up @@ -131,54 +131,52 @@ public function testGuessTypeNoAssociation(string $type, string $resultType, int
*
* @phpstan-return iterable<array{0: string, 1: string, 2: int, 3?: string}>
*/
public function noAssociationData(): iterable
public function provideGuessTypeNoAssociationCases(): iterable
{
return [
// TODO: Remove it when dropping support of doctrine/mongodb-odm < 3.0
Type::BOOLEAN => [
'boolean',
BooleanFilter::class,
Guess::HIGH_CONFIDENCE,
BooleanType::class,
],
Type::TIMESTAMP => [
'timestamp',
DateTimeFilter::class,
Guess::HIGH_CONFIDENCE,
],
Type::DATE => [
'date',
DateFilter::class,
Guess::HIGH_CONFIDENCE,
],
Type::FLOAT => [
'float',
NumberFilter::class,
Guess::MEDIUM_CONFIDENCE,
NumberType::class,
],
Type::INT => [
'int',
NumberFilter::class,
Guess::MEDIUM_CONFIDENCE,
NumberType::class,
],
Type::STRING => [
'string',
StringFilter::class,
Guess::MEDIUM_CONFIDENCE,
TextType::class,
],
Type::ID => [
Type::ID,
IdFilter::class,
Guess::MEDIUM_CONFIDENCE,
],
'somefake' => [
'somefake',
StringFilter::class,
Guess::LOW_CONFIDENCE,
],
// TODO: Remove it when dropping support of doctrine/mongodb-odm < 3.0
yield Type::BOOLEAN => [
'boolean',
BooleanFilter::class,
Guess::HIGH_CONFIDENCE,
BooleanType::class,
];
yield Type::TIMESTAMP => [
'timestamp',
DateTimeFilter::class,
Guess::HIGH_CONFIDENCE,
];
yield Type::DATE => [
'date',
DateFilter::class,
Guess::HIGH_CONFIDENCE,
];
yield Type::FLOAT => [
'float',
NumberFilter::class,
Guess::MEDIUM_CONFIDENCE,
NumberType::class,
];
yield Type::INT => [
'int',
NumberFilter::class,
Guess::MEDIUM_CONFIDENCE,
NumberType::class,
];
yield Type::STRING => [
'string',
StringFilter::class,
Guess::MEDIUM_CONFIDENCE,
TextType::class,
];
yield Type::ID => [
Type::ID,
IdFilter::class,
Guess::MEDIUM_CONFIDENCE,
];
yield 'somefake' => [
'somefake',
StringFilter::class,
Guess::LOW_CONFIDENCE,
];
}
}
128 changes: 62 additions & 66 deletions tests/FieldDescription/TypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function setUp(): void
}

/**
* @dataProvider associationData
* @dataProvider provideGuessTypeWithAssociationCases
*/
public function testGuessTypeWithAssociation(string $mappingType, string $type): void
{
Expand All @@ -59,24 +59,22 @@ public function testGuessTypeWithAssociation(string $mappingType, string $type):
}

/**
* @phpstan-return array<array{string, string}>
* @phpstan-return iterable<array{string, string}>
*/
public function associationData(): array
public function provideGuessTypeWithAssociationCases(): iterable
{
return [
'many-to-one' => [
ClassMetadata::ONE,
FieldDescriptionInterface::TYPE_MANY_TO_ONE,
],
'one-to-many' => [
ClassMetadata::MANY,
FieldDescriptionInterface::TYPE_MANY_TO_MANY,
],
yield 'many-to-one' => [
ClassMetadata::ONE,
FieldDescriptionInterface::TYPE_MANY_TO_ONE,
];
yield 'one-to-many' => [
ClassMetadata::MANY,
FieldDescriptionInterface::TYPE_MANY_TO_MANY,
];
}

/**
* @dataProvider noAssociationData
* @dataProvider provideGuessTypeNoAssociationCases
*/
public function testGuessTypeNoAssociation(string $type, string $resultType, int $confidence): void
{
Expand All @@ -100,61 +98,59 @@ public function testGuessTypeNoAssociation(string $type, string $resultType, int
}

/**
* @phpstan-return array<array{string, string, int}>
* @phpstan-return iterable<array{string, string, int}>
*/
public function noAssociationData(): array
public function provideGuessTypeNoAssociationCases(): iterable
{
return [
'collection' => [
Type::COLLECTION,
FieldDescriptionInterface::TYPE_ARRAY,
Guess::HIGH_CONFIDENCE,
],
'hash' => [
Type::HASH,
FieldDescriptionInterface::TYPE_ARRAY,
Guess::HIGH_CONFIDENCE,
],
'bool' => [
Type::BOOL,
FieldDescriptionInterface::TYPE_BOOLEAN,
Guess::HIGH_CONFIDENCE,
],
'timestamp' => [
Type::TIMESTAMP,
FieldDescriptionInterface::TYPE_DATETIME,
Guess::HIGH_CONFIDENCE,
],
'date' => [
Type::DATE,
FieldDescriptionInterface::TYPE_DATE,
Guess::HIGH_CONFIDENCE,
],
'date_immutable' => [
Type::DATE_IMMUTABLE,
FieldDescriptionInterface::TYPE_DATE,
Guess::HIGH_CONFIDENCE,
],
'float' => [
Type::FLOAT,
FieldDescriptionInterface::TYPE_FLOAT,
Guess::MEDIUM_CONFIDENCE,
],
'integer' => [
Type::INT,
FieldDescriptionInterface::TYPE_INTEGER,
Guess::MEDIUM_CONFIDENCE,
],
'string' => [
Type::STRING,
FieldDescriptionInterface::TYPE_STRING,
Guess::MEDIUM_CONFIDENCE,
],
'somefake' => [
'somefake',
FieldDescriptionInterface::TYPE_STRING,
Guess::LOW_CONFIDENCE,
],
yield 'collection' => [
Type::COLLECTION,
FieldDescriptionInterface::TYPE_ARRAY,
Guess::HIGH_CONFIDENCE,
];
yield 'hash' => [
Type::HASH,
FieldDescriptionInterface::TYPE_ARRAY,
Guess::HIGH_CONFIDENCE,
];
yield 'bool' => [
Type::BOOL,
FieldDescriptionInterface::TYPE_BOOLEAN,
Guess::HIGH_CONFIDENCE,
];
yield 'timestamp' => [
Type::TIMESTAMP,
FieldDescriptionInterface::TYPE_DATETIME,
Guess::HIGH_CONFIDENCE,
];
yield 'date' => [
Type::DATE,
FieldDescriptionInterface::TYPE_DATE,
Guess::HIGH_CONFIDENCE,
];
yield 'date_immutable' => [
Type::DATE_IMMUTABLE,
FieldDescriptionInterface::TYPE_DATE,
Guess::HIGH_CONFIDENCE,
];
yield 'float' => [
Type::FLOAT,
FieldDescriptionInterface::TYPE_FLOAT,
Guess::MEDIUM_CONFIDENCE,
];
yield 'integer' => [
Type::INT,
FieldDescriptionInterface::TYPE_INTEGER,
Guess::MEDIUM_CONFIDENCE,
];
yield 'string' => [
Type::STRING,
FieldDescriptionInterface::TYPE_STRING,
Guess::MEDIUM_CONFIDENCE,
];
yield 'somefake' => [
'somefake',
FieldDescriptionInterface::TYPE_STRING,
Guess::LOW_CONFIDENCE,
];
}
}
Loading