Skip to content

Commit

Permalink
Use PHPUnit attributes instead of annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Oct 29, 2023
1 parent f12e48c commit 5e64564
Show file tree
Hide file tree
Showing 65 changed files with 387 additions and 571 deletions.
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -981,12 +981,12 @@ parameters:
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php

-
message: "#^Parameter \\#1 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<class@anonymous/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest\\.php\\:230\\>\\:\\:mapField\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\{fieldName\\: 'enum', enumType\\: 'Documents\\\\\\\\Card'\\} given\\.$#"
message: "#^Parameter \\#1 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<class@anonymous/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest\\.php\\:231\\>\\:\\:mapField\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\{fieldName\\: 'enum', enumType\\: 'Documents\\\\\\\\Card'\\} given\\.$#"
count: 1
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php

-
message: "#^Parameter \\#1 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<class@anonymous/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest\\.php\\:249\\>\\:\\:mapField\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\{fieldName\\: 'enum', enumType\\: 'Documents\\\\\\\\SuitNonBacked'\\} given\\.$#"
message: "#^Parameter \\#1 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<class@anonymous/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest\\.php\\:250\\>\\:\\:mapField\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\{fieldName\\: 'enum', enumType\\: 'Documents\\\\\\\\SuitNonBacked'\\} given\\.$#"
count: 1
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php

Expand Down
75 changes: 37 additions & 38 deletions tests/Doctrine/ODM/MongoDB/Tests/Aggregation/ExprTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\ODM\MongoDB\Aggregation\Expr;
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
use LogicException;
use PHPUnit\Framework\Attributes\DataProvider;

class ExprTest extends BaseTestCase
{
Expand All @@ -17,26 +18,25 @@ class ExprTest extends BaseTestCase
/**
* @param array<string, string> $expected
* @param Closure(Expr): mixed[]|mixed[] $args
*
* @dataProvider provideAccumulatorExpressionOperators
* @dataProvider provideArithmeticExpressionOperators
* @dataProvider provideArrayExpressionOperators
* @dataProvider provideBooleanExpressionOperators
* @dataProvider provideComparisonExpressionOperators
* @dataProvider provideConditionalExpressionOperators
* @dataProvider provideCustomExpressionOperators
* @dataProvider provideDataSizeExpressionOperators
* @dataProvider provideDateExpressionOperators
* @dataProvider provideGroupAccumulatorExpressionOperators
* @dataProvider provideMiscExpressionOperators
* @dataProvider provideObjectExpressionOperators
* @dataProvider provideSetExpressionOperators
* @dataProvider provideStringExpressionOperators
* @dataProvider provideTimestampExpressionOperators
* @dataProvider provideTrigonometryExpressionOperators
* @dataProvider provideTypeExpressionOperators
* @dataProvider provideWindowExpressionOperators
*/
#[DataProvider('provideAccumulatorExpressionOperators')]
#[DataProvider('provideArithmeticExpressionOperators')]
#[DataProvider('provideArrayExpressionOperators')]
#[DataProvider('provideBooleanExpressionOperators')]
#[DataProvider('provideComparisonExpressionOperators')]
#[DataProvider('provideConditionalExpressionOperators')]
#[DataProvider('provideCustomExpressionOperators')]
#[DataProvider('provideDataSizeExpressionOperators')]
#[DataProvider('provideDateExpressionOperators')]
#[DataProvider('provideGroupAccumulatorExpressionOperators')]
#[DataProvider('provideMiscExpressionOperators')]
#[DataProvider('provideObjectExpressionOperators')]
#[DataProvider('provideSetExpressionOperators')]
#[DataProvider('provideStringExpressionOperators')]
#[DataProvider('provideTimestampExpressionOperators')]
#[DataProvider('provideTrigonometryExpressionOperators')]
#[DataProvider('provideTypeExpressionOperators')]
#[DataProvider('provideWindowExpressionOperators')]
public function testGenericOperator(array $expected, string $operator, $args): void
{
$expr = $this->createExpr();
Expand All @@ -49,26 +49,25 @@ public function testGenericOperator(array $expected, string $operator, $args): v
/**
* @param array<string, string> $expected
* @param Closure(Expr): mixed[]|mixed[] $args
*
* @dataProvider provideAccumulatorExpressionOperators
* @dataProvider provideArithmeticExpressionOperators
* @dataProvider provideArrayExpressionOperators
* @dataProvider provideBooleanExpressionOperators
* @dataProvider provideComparisonExpressionOperators
* @dataProvider provideConditionalExpressionOperators
* @dataProvider provideCustomExpressionOperators
* @dataProvider provideDataSizeExpressionOperators
* @dataProvider provideDateExpressionOperators
* @dataProvider provideGroupAccumulatorExpressionOperators
* @dataProvider provideMiscExpressionOperators
* @dataProvider provideObjectExpressionOperators
* @dataProvider provideSetExpressionOperators
* @dataProvider provideStringExpressionOperators
* @dataProvider provideTimestampExpressionOperators
* @dataProvider provideTrigonometryExpressionOperators
* @dataProvider provideTypeExpressionOperators
* @dataProvider provideWindowExpressionOperators
*/
#[DataProvider('provideAccumulatorExpressionOperators')]
#[DataProvider('provideArithmeticExpressionOperators')]
#[DataProvider('provideArrayExpressionOperators')]
#[DataProvider('provideBooleanExpressionOperators')]
#[DataProvider('provideComparisonExpressionOperators')]
#[DataProvider('provideConditionalExpressionOperators')]
#[DataProvider('provideCustomExpressionOperators')]
#[DataProvider('provideDataSizeExpressionOperators')]
#[DataProvider('provideDateExpressionOperators')]
#[DataProvider('provideGroupAccumulatorExpressionOperators')]
#[DataProvider('provideMiscExpressionOperators')]
#[DataProvider('provideObjectExpressionOperators')]
#[DataProvider('provideSetExpressionOperators')]
#[DataProvider('provideStringExpressionOperators')]
#[DataProvider('provideTimestampExpressionOperators')]
#[DataProvider('provideTrigonometryExpressionOperators')]
#[DataProvider('provideTypeExpressionOperators')]
#[DataProvider('provideWindowExpressionOperators')]
public function testGenericOperatorWithField(array $expected, string $operator, $args): void
{
$expr = $this->createExpr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
use Documents\CmsComment;
use Documents\User;
use PHPUnit\Framework\Attributes\DataProvider;

class BucketAutoTest extends BaseTestCase
{
Expand All @@ -22,9 +23,8 @@ class BucketAutoTest extends BaseTestCase
/**
* @param array<string, string> $expected
* @param mixed[]|Closure(Expr): mixed[] $args
*
* @dataProvider provideGroupAccumulatorExpressionOperators
*/
#[DataProvider('provideGroupAccumulatorExpressionOperators')]
public function testGroupAccumulators(array $expected, string $operator, $args): void
{
$args = $this->resolveArgs($args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
use Documents\CmsComment;
use Documents\User;
use PHPUnit\Framework\Attributes\DataProvider;

class BucketTest extends BaseTestCase
{
Expand All @@ -22,9 +23,8 @@ class BucketTest extends BaseTestCase
/**
* @param array<string, string> $expected
* @param mixed[]|Closure(Expr): mixed[] $args
*
* @dataProvider provideGroupAccumulatorExpressionOperators
*/
#[DataProvider('provideGroupAccumulatorExpressionOperators')]
public function testGroupAccumulators(array $expected, string $operator, $args): void
{
$args = $this->resolveArgs($args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\ODM\MongoDB\Aggregation\Stage\GeoNear;
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationTestTrait;
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class GeoNearTest extends BaseTestCase
{
Expand Down Expand Up @@ -37,11 +38,8 @@ public function testFromBuilder(): void
self::assertSame([['$geoNear' => $stage]], $builder->getPipeline());
}

/**
* @param mixed $value
*
* @dataProvider provideOptionalSettings
*/
/** @param mixed $value */
#[DataProvider('provideOptionalSettings')]
public function testOptionalSettings(string $field, $value): void
{
$geoNearStage = new GeoNear($this->getTestAggregationBuilder(), 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Documents\GraphLookup\ReportingHierarchy;
use Documents\GraphLookup\Traveller;
use Documents\User;
use PHPUnit\Framework\Attributes\DataProvider;

use function array_merge;
use function count;
Expand Down Expand Up @@ -149,9 +150,8 @@ public static function provideEmployeeAggregations(): array
/**
* @param Closure(Builder): GraphLookup $addGraphLookupStage
* @param array<string, string> $expectedFields
*
* @dataProvider provideEmployeeAggregations
*/
#[DataProvider('provideEmployeeAggregations')]
public function testWithEmployees(Closure $addGraphLookupStage, array $expectedFields): void
{
$this->insertEmployeeTestData();
Expand Down Expand Up @@ -222,9 +222,8 @@ public static function provideTravellerAggregations(): array
/**
* @param Closure(Builder): GraphLookup $addGraphLookupStage
* @param array<string, string> $expectedFields
*
* @dataProvider provideTravellerAggregations
*/
#[DataProvider('provideTravellerAggregations')]
public function testWithTraveller(Closure $addGraphLookupStage, array $expectedFields): void
{
$this->insertTravellerTestData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationOperatorsProviderTrait;
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationTestTrait;
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class GroupTest extends BaseTestCase
{
Expand All @@ -19,9 +20,8 @@ class GroupTest extends BaseTestCase
/**
* @param array<string, string> $expected
* @param mixed[]|Closure(Expr): mixed[] $args
*
* @dataProvider provideGroupAccumulatorExpressionOperators
*/
#[DataProvider('provideGroupAccumulatorExpressionOperators')]
public function testGroupAccumulators(array $expected, string $operator, $args): void
{
$groupStage = new Group($this->getTestAggregationBuilder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Documents\User;
use Generator;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\DataProvider;

use function is_callable;

Expand Down Expand Up @@ -80,11 +81,8 @@ public static function providePipeline(): Generator
];
}

/**
* @param array<array<string, mixed>>|callable $pipeline
*
* @dataProvider providePipeline
*/
/** @param array<array<string, mixed>>|callable $pipeline */
#[DataProvider('providePipeline')]
public function testStageWithPipeline($pipeline): void
{
if (is_callable($pipeline)) {
Expand Down
32 changes: 16 additions & 16 deletions tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/OperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationOperatorsProviderTrait;
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationTestTrait;
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class OperatorTest extends BaseTestCase
{
Expand All @@ -20,23 +21,22 @@ class OperatorTest extends BaseTestCase
/**
* @param array<string, mixed> $expected
* @param mixed[]|Closure(Expr): mixed[] $args
*
* @dataProvider provideAccumulatorExpressionOperators
* @dataProvider provideArithmeticExpressionOperators
* @dataProvider provideArrayExpressionOperators
* @dataProvider provideBooleanExpressionOperators
* @dataProvider provideComparisonExpressionOperators
* @dataProvider provideConditionalExpressionOperators
* @dataProvider provideDataSizeExpressionOperators
* @dataProvider provideDateExpressionOperators
* @dataProvider provideMiscExpressionOperators
* @dataProvider provideObjectExpressionOperators
* @dataProvider provideSetExpressionOperators
* @dataProvider provideStringExpressionOperators
* @dataProvider provideTimestampExpressionOperators
* @dataProvider provideTrigonometryExpressionOperators
* @dataProvider provideTypeExpressionOperators
*/
#[DataProvider('provideAccumulatorExpressionOperators')]
#[DataProvider('provideArithmeticExpressionOperators')]
#[DataProvider('provideArrayExpressionOperators')]
#[DataProvider('provideBooleanExpressionOperators')]
#[DataProvider('provideComparisonExpressionOperators')]
#[DataProvider('provideConditionalExpressionOperators')]
#[DataProvider('provideDataSizeExpressionOperators')]
#[DataProvider('provideDateExpressionOperators')]
#[DataProvider('provideMiscExpressionOperators')]
#[DataProvider('provideObjectExpressionOperators')]
#[DataProvider('provideSetExpressionOperators')]
#[DataProvider('provideStringExpressionOperators')]
#[DataProvider('provideTimestampExpressionOperators')]
#[DataProvider('provideTrigonometryExpressionOperators')]
#[DataProvider('provideTypeExpressionOperators')]
public function testProxiedExpressionOperators(array $expected, string $operator, $args): void
{
$stage = $this->getStubStage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationOperatorsProviderTrait;
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationTestTrait;
use Doctrine\ODM\MongoDB\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class ProjectTest extends BaseTestCase
{
Expand Down Expand Up @@ -39,7 +40,7 @@ public function testFromBuilder(): void
self::assertSame([['$project' => ['_id' => false, '$field' => true, '$otherField' => true, 'product' => ['$multiply' => ['$field', 5]]]]], $builder->getPipeline());
}

/** @dataProvider provideAccumulatorExpressionOperators */
#[DataProvider('provideAccumulatorExpressionOperators')]
public function testAccumulatorsWithMultipleArguments(array $expected, string $operator, $args): void
{
$projectStage = new Project($this->getTestAggregationBuilder());
Expand Down
Loading

0 comments on commit 5e64564

Please sign in to comment.