Skip to content

Commit

Permalink
Use static data providers (#2512)
Browse files Browse the repository at this point in the history
* Use static data providers

* Update phpunit.xml.dist

Co-authored-by: Claudio Zizza <859964+SenseException@users.noreply.github.com>

---------

Co-authored-by: Claudio Zizza <859964+SenseException@users.noreply.github.com>
  • Loading branch information
IonBazan and SenseException committed Mar 16, 2023
1 parent d6911d9 commit 97cbc8f
Show file tree
Hide file tree
Showing 35 changed files with 65 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ phpunit.xml
composer.lock
vendor/
.phpcs-cache
.phpunit.cache
.phpunit.result.cache
phpcs.xml
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"phpbench/phpbench": "^1.0.0@dev",
"phpstan/phpstan": "^1.9.4",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5.5",
"phpunit/phpunit": "^9.5.5 || ^10.0.15",
"squizlabs/php_codesniffer": "^3.5",
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
"vimeo/psalm": "^5.7.7"
Expand Down
23 changes: 10 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticProperties="false"
colors="false"
failOnRisky="true"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Doctrine ODM MongoDB Test Suite">
<directory>./tests/Doctrine/</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory suffix=".php">./lib/Doctrine/ODM/MongoDB</directory>
</include>
</coverage>

<groups>
<exclude>
<group>performance</group>
</exclude>
</groups>

<php>
<ini name="error_reporting" value="-1"/>
<const name="DOCTRINE_MONGODB_SERVER" value="mongodb://localhost:27017" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testGraphLookupWithMatch(): void
);
}

public function provideEmployeeAggregations(): array
public static function provideEmployeeAggregations(): array
{
return [
'owningSide' => [
Expand Down Expand Up @@ -185,7 +185,7 @@ public function testGraphLookupWithEmployees(Closure $addGraphLookupStage, array
}
}

public function provideTravellerAggregations(): array
public static function provideTravellerAggregations(): array
{
return [
'owningSide' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function setExpr(Expr $expr): void
self::assertSame($stage, $stage->$method(...$args));
}

public function provideProxiedExprMethods(): array
public static function provideProxiedExprMethods(): array
{
return [
'addToSet()' => ['addToSet', ['$field']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setQuery(Expr $query): void
self::assertSame($stage, $stage->$method(...$args));
}

public function provideProxiedExprMethods(): array
public static function provideProxiedExprMethods(): array
{
return [
'field()' => ['field', ['fieldName']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testAccumulatorsWithMultipleArguments(string $operator): void
self::assertSame(['$project' => ['something' => ['$' . $operator => ['$expression1', '$expression2']]]], $projectStage->getExpression());
}

public function provideAccumulators(): array
public static function provideAccumulators(): array
{
$operators = ['avg', 'max', 'min', 'stdDevPop', 'stdDevSamp', 'sum'];

Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testDocumentManagerIsClosedAccessor(): void
self::assertFalse($this->dm->isOpen());
}

public function dataMethodsAffectedByNoObjectArguments(): array
public static function dataMethodsAffectedByNoObjectArguments(): array
{
return [
['persist'],
Expand All @@ -138,7 +138,7 @@ public function testThrowsExceptionOnNonObjectValues(string $methodName): void
$this->dm->$methodName(null);
}

public function dataAffectedByErrorIfClosedException(): array
public static function dataAffectedByErrorIfClosedException(): array
{
return [
['flush'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testAtomicCollectionUnset($clearWith): void
self::assertEmpty($user->phonenumbers);
}

public function provideAtomicCollectionUnset(): array
public static function provideAtomicCollectionUnset(): array
{
return [
[null],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testBinData(string $field, string $data, int $type): void
self::assertEquals($data, $check[$field]->getData());
}

public function provideData(): array
public static function provideData(): array
{
return [
['bin', 'test', Binary::TYPE_GENERIC],
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testDateInstanceChangeDoesNotCauseUpdateIfValueIsTheSame($oldVal
self::assertEmpty($changeset);
}

public function provideEquivalentDates(): array
public static function provideEquivalentDates(): array
{
return [
[new DateTime('1985-09-01 00:00:00'), new DateTime('1985-09-01 00:00:00')],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function testPrepareFieldName(string $fieldName, string $expected): void
self::assertEquals($expected, $this->documentPersister->prepareFieldName($fieldName));
}

public function getTestPrepareFieldNameData(): array
public static function getTestPrepareFieldNameData(): array
{
return [
['name', 'dbName'],
Expand Down Expand Up @@ -256,7 +256,7 @@ public function testPrepareQueryOrNewObjWithReferenceToDocumentWithCustomTypedId
);
}

public function provideHashIdentifiers(): array
public static function provideHashIdentifiers(): array
{
return [
[['key' => 'value']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function tearDown(): void
bcscale($this->initialScale);
}

public function provideUpsertObjects(): array
public static function provideUpsertObjects(): array
{
return [
[UserUpsert::class, new ObjectId('4f18f593acee41d724000005'), 'user'],
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/IdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function testEqualButNotIdenticalIds(string $user1Id, $user2Id): void
self::assertSame($user2->id, $user2Id);
}

public function provideEqualButNotIdenticalIds(): array
public static function provideEqualButNotIdenticalIds(): array
{
/* MongoDB allows comparisons between different numeric types, so we
* cannot test integer and floating point values (e.g. 123 and 123.0).
Expand Down Expand Up @@ -251,7 +251,7 @@ public function testIdTypesAndStrategies(string $type, string $strategy, $id = n
self::assertEquals('changed', $object->test);
}

public function getTestIdTypesAndStrategiesData(): array
public static function getTestIdTypesAndStrategiesData(): array
{
$identifier = new ObjectId();

Expand Down Expand Up @@ -326,7 +326,7 @@ public function testBinIds(string $type, int $expectedMongoBinDataType, string $
self::assertEquals($expectedMongoBinDataType, $check['_id']->getType());
}

public function getTestBinIdsData(): array
public static function getTestBinIdsData(): array
{
return [
['bin', 0, 'test-data'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testStrategy(string $field): void
self::assertEquals('10203040', $publicBook->getPhonenumbers()->get(0)->getPhonenumber());
}

public function provideStrategy(): array
public static function provideStrategy(): array
{
return [
[ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testRawType($value): void
self::assertEquals($value, $result['raw']);
}

public function getTestRawTypeData(): array
public static function getTestRawTypeData(): array
{
return [
['test'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testHintIsSetOnQuery(int $readPreference, array $tags = []): voi
$this->assertReadPreferenceHint($readPreference, $groups->getHints()[Query::HINT_READ_PREFERENCE], $tags);
}

public function provideReadPreferenceHints(): array
public static function provideReadPreferenceHints(): array
{
return [
[ReadPreference::RP_PRIMARY, []],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testParentAssociationsLeftover(callable $f, int $leftover): void
$this->expectCount('embeddedDocumentsRegistry', $leftover);
}

public function provideParentAssociationsIsCleared(): array
public static function provideParentAssociationsIsCleared(): array
{
return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testBuildingReferenceCreatesCorrectStructure(array $expectedRefe
self::assertArraySubset($expectedReference, $data['parentDocument']);
}

public function getValidReferenceData(): array
public static function getValidReferenceData(): array
{
return [
'discriminatedDocument' => [
Expand Down Expand Up @@ -73,7 +73,7 @@ public function testBuildingReferenceForUnlistedClassCausesException(string $exp
$this->dm->getUnitOfWork()->getPersistenceBuilder()->prepareInsertData($document);
}

public function getInvalidReferenceData(): array
public static function getInvalidReferenceData(): array
{
return [
'referenceWithPartialDiscriminatorMapUnlistedDocument' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testUpdateListenersAreCalled($id): void
self::assertEquals($called, $listener->called);
}

public function provideDocumentIds(): array
public static function provideDocumentIds(): array
{
return [
[123456],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testA(Closure $idGenerator): void
self::assertCount(4, $docs);
}

public function provideIdGenerators(): array
public static function provideIdGenerators(): array
{
$binDataType = Binary::TYPE_GENERIC;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function testClassCanBeMappedByOneAbstractDocument(object $wrong, string
$annotationDriver->loadMetadataForClass(get_class($wrong), $cm);
}

public function provideClassCanBeMappedByOneAbstractDocument(): ?Generator
public static function provideClassCanBeMappedByOneAbstractDocument(): ?Generator
{
yield [
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ public function testRepositoryMethodCanNotBeCombinedWithSkipLimitAndSort(string
]);
}

public function provideRepositoryMethodCanNotBeCombinedWithSkipLimitAndSort(): Generator
public static function provideRepositoryMethodCanNotBeCombinedWithSkipLimitAndSort(): Generator
{
yield ['skip', 5];
yield ['limit', 5];
Expand Down Expand Up @@ -763,7 +763,7 @@ public function testOwningAndInversedRefsNeedTargetDocument(array $config): void
$cm->mapField($config);
}

public function provideOwningAndInversedRefsNeedTargetDocument(): array
public static function provideOwningAndInversedRefsNeedTargetDocument(): array
{
return [
[['type' => 'one', 'mappedBy' => 'post']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function testPrepareInsertData(object $document, array $expectedData): vo
*
* @return array
*/
public function getDocumentsAndExpectedData(): array
public static function getDocumentsAndExpectedData(): array
{
return [
[new ConfigurableProduct('Test Product'), ['name' => 'Test Product']],
Expand Down
18 changes: 9 additions & 9 deletions tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function testArrayUpdateOperatorsOnReferenceMany(string $class, string $f
self::assertEquals($expected, $q1['newObj']['$addToSet'][$field]);
}

public function provideArrayUpdateOperatorsOnReferenceMany(): Generator
public static function provideArrayUpdateOperatorsOnReferenceMany(): Generator
{
yield [ChildA::class, 'featureFullMany'];
yield [ChildB::class, 'featureSimpleMany'];
Expand All @@ -232,7 +232,7 @@ public function testArrayUpdateOperatorsOnReferenceOne(string $class, string $fi
self::assertEquals($expected, $q1['newObj']['$set'][$field]);
}

public function provideArrayUpdateOperatorsOnReferenceOne(): Generator
public static function provideArrayUpdateOperatorsOnReferenceOne(): Generator
{
yield [ChildA::class, 'featureFull'];
yield [ChildB::class, 'featureSimple'];
Expand Down Expand Up @@ -490,7 +490,7 @@ public function testProxiedExprMethods(string $method, array $args = []): void
self::assertSame($qb, $qb->$method(...$args));
}

public function provideProxiedExprMethods(): array
public static function provideProxiedExprMethods(): array
{
return [
'field()' => ['field', ['fieldName']],
Expand Down Expand Up @@ -577,9 +577,9 @@ public function testSelect(array $args, array $expected): void
self::assertEquals($expected, $qb->debug('select'));
}

public function provideSelectProjections(): array
public static function provideSelectProjections(): array
{
return $this->provideProjections(true);
return self::provideProjections(true);
}

/**
Expand All @@ -595,9 +595,9 @@ public function testExclude(array $args, array $expected): void
self::assertEquals($expected, $qb->debug('select'));
}

public function provideExcludeProjections(): array
public static function provideExcludeProjections(): array
{
return $this->provideProjections(false);
return self::provideProjections(false);
}

/**
Expand All @@ -607,7 +607,7 @@ public function provideExcludeProjections(): array
*
* @return array
*/
private function provideProjections(bool $include): array
private static function provideProjections(bool $include): array
{
$project = $include ? 1 : 0;

Expand Down Expand Up @@ -713,7 +713,7 @@ public function testSortWithFieldNameAndOrder($order, int $expectedOrder): void
self::assertEquals(['foo' => $expectedOrder], $qb->debug('sort'));
}

public function provideSortOrders(): array
public static function provideSortOrders(): array
{
return [
[1, 1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testMerge(array $args, array $merged): void
self::assertSame($merged, call_user_func_array([new CriteriaMerger(), 'merge'], $args));
}

public function provideMerge(): array
public static function provideMerge(): array
{
return [
'no args' => [
Expand Down

0 comments on commit 97cbc8f

Please sign in to comment.