Skip to content

Commit

Permalink
Make all data providers static (doctrine#10493)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Feb 4, 2023
1 parent d50ba2e commit 3843d7e
Show file tree
Hide file tree
Showing 33 changed files with 74 additions and 76 deletions.
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/AbstractQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testCallingSettersWithoutArgumentsIsDeprecated(string $setter):
}

/** @return array<string, array{string}> */
public function provideSettersWithDeprecatedDefault(): array
public static function provideSettersWithDeprecatedDefault(): array
{
return [
'setHydrationCacheProfile' => ['setHydrationCacheProfile'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function setUp(): void
}

/** @psalm-return Generator<string, mixed[]> */
public function getMethodParameters(): Generator
public static function getMethodParameters(): Generator
{
$class = new ReflectionClass(EntityManagerInterface::class);

Expand All @@ -55,12 +55,12 @@ public function getMethodParameters(): Generator
continue;
}

yield $method->getName() => $this->getParameters($method);
yield $method->getName() => self::getParameters($method);
}
}

/** @return mixed[] */
private function getParameters(ReflectionMethod $method): array
private static function getParameters(ReflectionMethod $method): array
{
/** Special case EntityManager::createNativeQuery() */
if ($method->getName() === 'createNativeQuery') {
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/EntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function testAffectedByErrorIfClosedException(string $methodName): void
}

/** @return Generator<array{mixed}> */
public function dataToBeReturnedByWrapInTransaction(): Generator
public static function dataToBeReturnedByWrapInTransaction(): Generator
{
yield [[]];
yield [[1]];
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function testEnumWithNonMatchingDatabaseValueThrowsException(string $card
}

/** @return array<string, array{class-string}> */
public function provideCardClasses(): array
public static function provideCardClasses(): array
{
return [
Card::class => [Card::class],
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
}

/** @psalm-return list<array{int}> */
public function provideDataForHydrationMode(): array
public static function provideDataForHydrationMode(): array
{
return [
[Query::HYDRATE_ARRAY],
Expand Down
10 changes: 5 additions & 5 deletions tests/Doctrine/Tests/ORM/Functional/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,17 @@ public function populate(): void
$this->_em->flush();
}

/** @psalm-return list<array{bool, bool}> */
public function useOutputWalkers(): array
/** @psalm-return list<array{bool}> */
public static function useOutputWalkers(): array
{
return [
[true],
[false],
];
}

/** @psalm-return list<array{bool, bool}> */
public function fetchJoinCollection(): array
/** @psalm-return list<array{bool}> */
public static function fetchJoinCollection(): array
{
return [
[true],
Expand All @@ -755,7 +755,7 @@ public function fetchJoinCollection(): array
}

/** @psalm-return list<array{bool, bool}> */
public function useOutputWalkersAndFetchJoinCollection(): array
public static function useOutputWalkersAndFetchJoinCollection(): array
{
return [
[true, false],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function testDateSub(string $unit, int $amount, int $delta = 0): void
);
}

public function dateAddSubProvider(): array
public static function dateAddSubProvider(): array
{
$secondsInDay = 86400;

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testPersistenceOfEntityWithSchemaMapping(string $className): voi
*
* @return string[][]
*/
public function getTestedClasses(): array
public static function getTestedClasses(): array
{
return [
[ExplicitSchemaAndTable::class, 'explicit_schema', 'explicit_table'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH10387Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testSchemaToolCreatesColumnForFieldInTheMiddleClass(array $class
self::assertNotNull($schema->getTable('root')->getColumn('leaf_class_field'));
}

public function classHierachies(): Generator
public static function classHierachies(): Generator
{
yield 'hierarchy with Entity classes only' => [[GH10387EntitiesOnlyRoot::class, GH10387EntitiesOnlyMiddle::class, GH10387EntitiesOnlyLeaf::class]];
yield 'MappedSuperclass in the middle of the hierarchy' => [[GH10387MappedSuperclassRoot::class, GH10387MappedSuperclassMiddle::class, GH10387MappedSuperclassLeaf::class]];
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH7875Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testUpdateSchemaSql(): void
}

/** @return array<array<string|callable|null>> */
public function provideUpdateSchemaSqlWithSchemaAssetFilter(): array
public static function provideUpdateSchemaSqlWithSchemaAssetFilter(): array
{
return [
['/^(?!my_enti)/', null],
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testLoadFieldsFromAllClassesInHierarchy(string $queryClass): voi
self::assertSame('leaf', $loadedEntity->leaf);
}

public function queryClasses(): array
public static function queryClasses(): array
{
return [
'query via root entity' => [GH8127Root::class],
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH9230Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function tearDown(): void
/**
* This does not work before the fix in PR#9663, but is does work after the fix is applied
*/
public function failingValuesBeforeFix(): array
public static function failingValuesBeforeFix(): array
{
return [
'string=""' => ['name', '', 'test name'],
Expand Down Expand Up @@ -66,7 +66,7 @@ public function failingValuesBeforeFix(): array
/**
* This already works before the fix in PR#9663 is applied because none of these are falsy values in php
*/
public function succeedingValuesBeforeFix(): array
public static function succeedingValuesBeforeFix(): array
{
return [
'string="test"' => ['name', 'test', 'test2'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function testThrowsExceptionOnInfiniteEmbeddableNesting(
}

/** @psalm-return list<array{string, string}> */
public function getInfiniteEmbeddableNestingData(): array
public static function getInfiniteEmbeddableNestingData(): array
{
return [
['DDCInfiniteNestingEmbeddable', 'DDCInfiniteNestingEmbeddable'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class ArrayHydratorTest extends HydrationTestCase
{
/** @psalm-return list<array{mixed}> */
public function provideDataForUserEntityResult(): array
public static function provideDataForUserEntityResult(): array
{
return [
[0],
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ObjectHydratorTest extends HydrationTestCase
use MockBuilderCompatibilityTools;

/** @psalm-return list<array{mixed}> */
public function provideDataForUserEntityResult(): array
public static function provideDataForUserEntityResult(): array
{
return [
[0],
Expand All @@ -44,7 +44,7 @@ public function provideDataForUserEntityResult(): array
}

/** @psalm-return list<array{mixed, mixed}> */
public function provideDataForMultipleRootEntityResult(): array
public static function provideDataForMultipleRootEntityResult(): array
{
return [
[0, 0],
Expand All @@ -55,7 +55,7 @@ public function provideDataForMultipleRootEntityResult(): array
}

/** @psalm-return list<array{mixed}> */
public function provideDataForProductEntityResult(): array
public static function provideDataForProductEntityResult(): array
{
return [
[0],
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testThrowsExceptionIfIdNotAssigned($entity): void
$this->assignedGen->generateId($this->entityManager, $entity);
}

public function entitiesWithoutId(): array
public static function entitiesWithoutId(): array
{
return [
'single' => [new AssignedSingleIdEntity()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function testSkipsDeferredPostLoadOfMetadataWithNoInvokedListeners(): voi
}

/** @psalm-return list<array{int}> */
public function invocationFlagProvider(): array
public static function invocationFlagProvider(): array
{
return [
[ListenersInvoker::INVOKE_LISTENERS],
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function testLengthForDiscriminatorColumn(string $class, int $expectedLen
self::assertSame($expectedLength, $metadata->discriminatorColumn['length']);
}

public function provideDiscriminatorColumnTestcases(): Generator
public static function provideDiscriminatorColumnTestcases(): Generator
{
yield [DiscriminatorColumnWithNullLength::class, 255];
yield [DiscriminatorColumnWithNoLength::class, 255];
Expand Down
30 changes: 14 additions & 16 deletions tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,47 @@ public function testWillSkipReadingPropertiesFromNullEmbeddable(
}

/**
* Data provider
*
* @return ReflectionProperty[][]|string[][]
*/
public function getTestedReflectionProperties(): array
public static function getTestedReflectionProperties(): array
{
return [
[
$this->getReflectionProperty(BooleanModel::class, 'id'),
$this->getReflectionProperty(BooleanModel::class, 'id'),
self::getReflectionProperty(BooleanModel::class, 'id'),
self::getReflectionProperty(BooleanModel::class, 'id'),
BooleanModel::class,
],
// reflection on embeddables that have properties defined in abstract ancestors:
[
$this->getReflectionProperty(BooleanModel::class, 'id'),
$this->getReflectionProperty(AbstractEmbeddable::class, 'propertyInAbstractClass'),
self::getReflectionProperty(BooleanModel::class, 'id'),
self::getReflectionProperty(AbstractEmbeddable::class, 'propertyInAbstractClass'),
ConcreteEmbeddable::class,
],
[
$this->getReflectionProperty(BooleanModel::class, 'id'),
$this->getReflectionProperty(ConcreteEmbeddable::class, 'propertyInConcreteClass'),
self::getReflectionProperty(BooleanModel::class, 'id'),
self::getReflectionProperty(ConcreteEmbeddable::class, 'propertyInConcreteClass'),
ConcreteEmbeddable::class,
],
// reflection on classes extending internal PHP classes:
[
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'privateProperty'),
self::getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
self::getReflectionProperty(ArrayObjectExtendingClass::class, 'privateProperty'),
ArrayObjectExtendingClass::class,
],
[
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'protectedProperty'),
self::getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
self::getReflectionProperty(ArrayObjectExtendingClass::class, 'protectedProperty'),
ArrayObjectExtendingClass::class,
],
[
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
self::getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
self::getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
ArrayObjectExtendingClass::class,
],
];
}

private function getReflectionProperty(string $className, string $propertyName): ReflectionProperty
private static function getReflectionProperty(string $className, string $propertyName): ReflectionProperty
{
$reflectionProperty = new ReflectionProperty($className, $propertyName);

Expand Down
28 changes: 14 additions & 14 deletions tests/Doctrine/Tests/ORM/ORMInvalidArgumentExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
use Doctrine\ORM\ORMInvalidArgumentException;
use PHPUnit\Framework\TestCase;
use stdClass;
use Stringable;

use function spl_object_id;
use function uniqid;

/** @covers \Doctrine\ORM\ORMInvalidArgumentException */
class ORMInvalidArgumentExceptionTest extends TestCase
Expand All @@ -29,7 +27,7 @@ public function testInvalidEntityName($value, string $expectedMessage): void
}

/** @psalm-return list<array{mixed, string}> */
public function invalidEntityNames(): array
public static function invalidEntityNames(): array
{
return [
[null, 'Entity name must be a string, null given'],
Expand All @@ -49,30 +47,32 @@ public function testNewEntitiesFoundThroughRelationships(array $newEntities, str
self::assertSame($expectedMessage, $exception->getMessage());
}

public function newEntitiesFoundThroughRelationshipsErrorMessages(): array
public static function newEntitiesFoundThroughRelationshipsErrorMessages(): array
{
$stringEntity3 = uniqid('entity3', true);
$entity1 = new stdClass();
$entity2 = new stdClass();
$entity3 = $this->createMock(Stringable::class);
$association1 = [
$entity1 = new stdClass();
$entity2 = new stdClass();
$entity3 = new class {
public function __toString(): string
{
return 'ThisIsAStringRepresentationOfEntity3';
}
};
$association1 = [
'sourceEntity' => 'foo1',
'fieldName' => 'bar1',
'targetEntity' => 'baz1',
];
$association2 = [
$association2 = [
'sourceEntity' => 'foo2',
'fieldName' => 'bar2',
'targetEntity' => 'baz2',
];
$association3 = [
$association3 = [
'sourceEntity' => 'foo3',
'fieldName' => 'bar3',
'targetEntity' => 'baz3',
];

$entity3->method('__toString')->willReturn($stringEntity3);

return [
'one entity found' => [
[
Expand Down Expand Up @@ -121,7 +121,7 @@ public function newEntitiesFoundThroughRelationshipsErrorMessages(): array
],
],
'A new entity was found through the relationship \'foo3#bar3\' that was not configured to cascade '
. 'persist operations for entity: ' . $stringEntity3
. 'persist operations for entity: ThisIsAStringRepresentationOfEntity3'
. '. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity '
. 'or configure cascade persist this association in the mapping for example '
. '@ManyToOne(..,cascade={"persist"}).',
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/Query/ExprTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function testIsMemberOfExpr(): void
self::assertEquals(':groupId MEMBER OF u.groups', (string) $this->expr->isMemberOf(':groupId', 'u.groups'));
}

public function provideIterableValue(): Generator
public static function provideIterableValue(): Generator
{
$gen = static function () {
yield from [1, 2, 3];
Expand All @@ -288,7 +288,7 @@ public function provideIterableValue(): Generator
yield 'generator' => [$gen()];
}

public function provideLiteralIterableValue(): Generator
public static function provideLiteralIterableValue(): Generator
{
$gen = static function () {
yield from ['foo', 'bar'];
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testRejectsInvalidDQL(string $dql): void
}

/** @psalm-return list<array{string}> */
public function invalidDQL(): array
public static function invalidDQL(): array
{
return [

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Query/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function testScannerTokenizesASimpleQueryCorrectly(): void
}

/** @psalm-return list<array{int, string}> */
public function provideTokens(): array
public static function provideTokens(): array
{
return [
[Lexer::T_IDENTIFIER, 'u'], // one char
Expand Down
Loading

0 comments on commit 3843d7e

Please sign in to comment.