Skip to content

Commit d26a003

Browse files
authored
Merge pull request #442 from greg0ire/maintenance
Maintenance
2 parents 2b09914 + 9fe195d commit d26a003

11 files changed

+167
-83
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"phpstan/phpstan-phpunit": "^2",
3030
"phpstan/phpstan-strict-rules": "^2",
3131
"doctrine/coding-standard": "^14",
32-
"phpunit/phpunit": "^9.6",
32+
"phpunit/phpunit": "^10.5.58 || ^12",
3333
"symfony/cache": "^4.4 || ^5.4 || ^6.0 || ^7.0",
3434
"symfony/finder": "^4.4 || ^5.4 || ^6.0 || ^7.0"
3535
},

phpunit.xml.dist

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
colors="true"
55
beStrictAboutOutputDuringTests="true"
6-
beStrictAboutTodoAnnotatedTests="true"
6+
displayDetailsOnPhpunitDeprecations="true"
7+
displayDetailsOnTestsThatTriggerDeprecations="true"
78
>
89
<testsuites>
910
<testsuite name="Doctrine Persistence Test Suite">
1011
<directory>tests</directory>
1112
</testsuite>
1213
</testsuites>
1314

14-
<filter>
15-
<whitelist>
15+
<php>
16+
<server name="DOCTRINE_DEPRECATIONS" value="trigger"/>
17+
</php>
18+
19+
<source ignoreSuppressionOfDeprecations="true">
20+
<include>
1621
<directory>src</directory>
17-
</whitelist>
18-
</filter>
22+
</include>
23+
</source>
1924
</phpunit>

tests/Persistence/ManagerRegistryTest.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@
1313
use Doctrine\Persistence\Proxy;
1414
use Doctrine\Tests\DoctrineTestCase;
1515
use Doctrine\Tests\Persistence\Mapping\TestClassMetadataFactory;
16+
use PHPUnit\Framework\Attributes\Group;
1617
use PHPUnit\Framework\MockObject\MockObject;
1718

1819
use function assert;
1920
use function call_user_func;
2021

21-
/**
22-
* @uses Doctrine\Tests\Persistence\TestObject
23-
*
24-
* @groups DCOM-270
25-
*/
22+
#[Group('DCOM-270')]
2623
class ManagerRegistryTest extends DoctrineTestCase
2724
{
2825
private TestManagerRegistry $mr;
@@ -85,7 +82,7 @@ public function testGetRepository(): void
8582
->expects(self::once())
8683
->method('getRepository')
8784
->with(self::equalTo(TestObject::class))
88-
->will(self::returnValue($repository));
85+
->willReturn($repository);
8986

9087
self::assertSame($repository, $this->mr->getRepository(TestObject::class));
9188
}
@@ -116,7 +113,7 @@ public function testGetRepositoryWithSpecificManagerName(): void
116113
->expects(self::once())
117114
->method('getRepository')
118115
->with(self::equalTo(TestObject::class))
119-
->will(self::returnValue($repository));
116+
->willReturn($repository);
120117

121118
self::assertSame($repository, $this->mr->getRepository(TestObject::class, 'other'));
122119
}
@@ -147,7 +144,7 @@ public function testGetRepositoryWithManagerDetection(): void
147144
->expects(self::once())
148145
->method('getRepository')
149146
->with(self::equalTo(OtherTestObject::class))
150-
->will(self::returnValue($repository));
147+
->willReturn($repository);
151148

152149
self::assertSame($repository, $this->mr->getRepository(OtherTestObject::class));
153150
}
@@ -161,7 +158,6 @@ private function getManagerFactory(): Closure
161158
$metadata = $this->createMock(ClassMetadata::class);
162159

163160
$metadata
164-
->expects(self::any())
165161
->method('getName')
166162
->willReturn($name === 'other_manager' ? OtherTestObject::class : TestObject::class);
167163

tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php

Lines changed: 111 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,76 +8,103 @@
88
use Doctrine\Persistence\Mapping\ClassMetadata;
99
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
1010
use Doctrine\Persistence\Mapping\MappingException;
11+
use Doctrine\Persistence\Mapping\ReflectionService;
1112
use Doctrine\Tests\DoctrineTestCase;
13+
use RuntimeException;
1214

1315
final class AbstractClassMetadataFactoryTest extends DoctrineTestCase
1416
{
17+
/** @param ClassMetadata<object>|null $metadata */
18+
private function createTestFactory(
19+
MappingDriver|null $driver = null,
20+
ClassMetadata|null $metadata = null,
21+
): TestAbstractClassMetadataFactory {
22+
return new TestAbstractClassMetadataFactory($driver, $metadata);
23+
}
24+
1525
public function testItSkipsTransientClasses(): void
1626
{
17-
$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
18-
$cmf
19-
->method('newClassMetadataInstance')
20-
->withConsecutive([SomeGrandParentEntity::class], [SomeEntity::class])
21-
->willReturnOnConsecutiveCalls(
22-
$this->createMock(ClassMetadata::class),
23-
$this->createMock(ClassMetadata::class),
24-
);
2527
$driver = $this->createMock(MappingDriver::class);
26-
$cmf->method('getDriver')
27-
->willReturn($driver);
28+
$cmf = $this->createTestFactory($driver);
29+
30+
$metadataCallCount = 0;
31+
$cmf->newClassMetadataInstanceCallback = function ($className) use (&$metadataCallCount) {
32+
$metadataCallCount++;
33+
if ($metadataCallCount === 1) {
34+
self::assertEquals(SomeGrandParentEntity::class, $className);
35+
} elseif ($metadataCallCount === 2) {
36+
self::assertEquals(SomeEntity::class, $className);
37+
}
2838

39+
return $this->createMock(ClassMetadata::class);
40+
};
41+
42+
$driverCallCount = 0;
2943
$driver->expects(self::exactly(2))
3044
->method('isTransient')
31-
->withConsecutive(
32-
[SomeGrandParentEntity::class],
33-
[SomeParentEntity::class],
34-
)
35-
->willReturnOnConsecutiveCalls(false, true);
45+
->willReturnCallback(static function ($className) use (&$driverCallCount) {
46+
$driverCallCount++;
47+
if ($driverCallCount === 1) {
48+
self::assertEquals(SomeGrandParentEntity::class, $className);
49+
50+
return false;
51+
}
52+
53+
if ($driverCallCount === 2) {
54+
self::assertEquals(SomeParentEntity::class, $className);
55+
56+
return true;
57+
}
58+
});
3659

3760
$cmf->getMetadataFor(SomeEntity::class);
3861
}
3962

4063
public function testItThrowsWhenAttemptingToGetMetadataForAnonymousClass(): void
4164
{
42-
$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
65+
$cmf = $this->createTestFactory();
4366
$this->expectException(MappingException::class);
4467
$cmf->getMetadataFor((new class {
4568
})::class);
4669
}
4770

4871
public function testAnonymousClassIsNotMistakenForShortAlias(): void
4972
{
50-
$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
73+
$driver = $this->createMock(MappingDriver::class);
74+
$driver->method('isTransient')->willReturn(false);
75+
$cmf = $this->createTestFactory($driver);
5176

5277
self::assertFalse($cmf->isTransient((new class () {
5378
})::class));
5479
}
5580

5681
public function testItThrowsWhenAttemptingToGetMetadataForShortAlias(): void
5782
{
58-
$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
83+
$cmf = $this->createTestFactory();
5984
$this->expectException(MappingException::class);
6085
// @phpstan-ignore-next-line
6186
$cmf->getMetadataFor('App:Test');
6287
}
6388

6489
public function testItThrowsWhenAttemptingToCheckTransientForShortAlias(): void
6590
{
66-
$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
91+
$cmf = $this->createTestFactory();
6792
$this->expectException(MappingException::class);
6893
// @phpstan-ignore-next-line
6994
$cmf->isTransient('App:Test');
7095
}
7196

7297
public function testItGetsTheSameMetadataForBackslashedClassName(): void
7398
{
74-
$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
75-
$cmf
76-
->method('newClassMetadataInstance')
77-
->with(SomeOtherEntity::class)
78-
->willReturn(
79-
self::createStub(ClassMetadata::class),
80-
);
99+
$driver = $this->createMock(MappingDriver::class);
100+
$cmf = $this->createTestFactory($driver);
101+
102+
$metadata = self::createStub(ClassMetadata::class);
103+
$cmf->newClassMetadataInstanceCallback = static function ($className) use ($metadata) {
104+
self::assertEquals(SomeOtherEntity::class, $className);
105+
106+
return $metadata;
107+
};
81108

82109
self::assertSame($cmf->getMetadataFor(SomeOtherEntity::class), $cmf->getMetadataFor('\\' . SomeOtherEntity::class));
83110
}
@@ -98,3 +125,61 @@ final class SomeEntity extends SomeParentEntity
98125
final class SomeOtherEntity
99126
{
100127
}
128+
129+
/** @template-extends AbstractClassMetadataFactory<ClassMetadata<object>> */
130+
class TestAbstractClassMetadataFactory extends AbstractClassMetadataFactory
131+
{
132+
/** @var callable|null */
133+
public $newClassMetadataInstanceCallback;
134+
135+
/** @param ClassMetadata<object>|null $defaultMetadata */
136+
public function __construct(
137+
private MappingDriver|null $driver = null,
138+
private ClassMetadata|null $defaultMetadata = null,
139+
) {
140+
}
141+
142+
protected function initialize(): void
143+
{
144+
$this->initialized = true;
145+
}
146+
147+
protected function getDriver(): MappingDriver
148+
{
149+
return $this->driver ?? throw new RuntimeException('Driver not set');
150+
}
151+
152+
protected function wakeupReflection(ClassMetadata $class, ReflectionService $reflService): void
153+
{
154+
// No-op for tests
155+
}
156+
157+
protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService): void
158+
{
159+
// No-op for tests
160+
}
161+
162+
protected function isEntity(ClassMetadata $class): bool
163+
{
164+
return true;
165+
}
166+
167+
/** @param list<class-string> $nonSuperclassParents */
168+
protected function doLoadMetadata(
169+
ClassMetadata $class,
170+
ClassMetadata|null $parent,
171+
bool $rootEntityFound,
172+
array $nonSuperclassParents,
173+
): void {
174+
// No-op for tests - metadata loading is handled by driver
175+
}
176+
177+
protected function newClassMetadataInstance(string $className): ClassMetadata
178+
{
179+
if ($this->newClassMetadataInstanceCallback !== null) {
180+
return ($this->newClassMetadataInstanceCallback)($className);
181+
}
182+
183+
return $this->defaultMetadata ?? throw new RuntimeException('Default metadata not set');
184+
}
185+
}

tests/Persistence/Mapping/ClassMetadataFactoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
use Doctrine\Persistence\Mapping\MappingException;
1111
use Doctrine\Tests\DoctrineTestCase;
1212
use Foo;
13+
use PHPUnit\Framework\Attributes\CoversClass;
14+
use PHPUnit\Framework\Attributes\Group;
1315
use Psr\Cache\CacheItemInterface;
1416
use Psr\Cache\CacheItemPoolInterface;
1517
use ReflectionMethod;
1618
use stdClass;
1719
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1820

19-
/** @covers \Doctrine\Persistence\Mapping\AbstractClassMetadataFactory */
21+
#[CoversClass(AbstractClassMetadataFactory::class)]
2022
class ClassMetadataFactoryTest extends DoctrineTestCase
2123
{
2224
/** @phpstan-var TestClassMetadataFactory<ClassMetadata<object>> */
@@ -105,7 +107,7 @@ public function testWillFailOnFallbackFailureWithNotLoadedMetadata(): void
105107
$this->cmf->getMetadataFor(Foo::class);
106108
}
107109

108-
/** @group 717 */
110+
#[Group('717')]
109111
public function testWillIgnoreCacheEntriesThatAreNotMetadataInstances(): void
110112
{
111113
$key = $this->cmf->getCacheKey(RootEntity::class);

tests/Persistence/Mapping/ColocatedMappingDriverTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Doctrine\Tests\Persistence\Mapping\_files\colocated\EntityFixture;
1414
use Doctrine\Tests\Persistence\Mapping\_files\colocated\TestClass;
1515
use Generator;
16+
use PHPUnit\Framework\Attributes\DataProvider;
1617
use PHPUnit\Framework\TestCase;
1718

1819
use function sort;
@@ -58,7 +59,7 @@ public function testGetSetFileExtension(): void
5859
self::assertSame('.php1', $driver->getFileExtension());
5960
}
6061

61-
/** @dataProvider directoryPathProvider */
62+
#[DataProvider('directoryPathProvider')]
6263
public function testGetAllClassNamesForDirectory(string $dirPath): void
6364
{
6465
$driver = $this->createDirectoryPathDriver($dirPath);

tests/Persistence/Mapping/DriverChainTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Doctrine\Tests\DoctrineTestCase;
1212
use Doctrine\Tests\Persistence\Mapping\Fixtures\Manager\Manager;
1313
use Doctrine\Tests\Persistence\Mapping\Fixtures\Model;
14+
use PHPUnit\Framework\Attributes\Group;
1415
use stdClass;
1516

1617
class DriverChainTest extends DoctrineTestCase
@@ -63,12 +64,12 @@ public function testGatherAllClassNames(): void
6364
$driver1 = $this->createMock(MappingDriver::class);
6465
$driver1->expects(self::once())
6566
->method('getAllClassNames')
66-
->will(self::returnValue(['Doctrine\Tests\Models\Company\Foo']));
67+
->willReturn(['Doctrine\Tests\Models\Company\Foo']);
6768

6869
$driver2 = $this->createMock(MappingDriver::class);
6970
$driver2->expects(self::once())
7071
->method('getAllClassNames')
71-
->will(self::returnValue(['Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz']));
72+
->willReturn(['Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz']);
7273

7374
$chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
7475
$chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
@@ -80,7 +81,7 @@ public function testGatherAllClassNames(): void
8081
], $chain->getAllClassNames());
8182
}
8283

83-
/** @group DDC-706 */
84+
#[Group('DDC-706')]
8485
public function testIsTransient(): void
8586
{
8687
$driver1 = $this->createMock(MappingDriver::class);
@@ -90,7 +91,7 @@ public function testIsTransient(): void
9091
self::assertTrue($chain->isTransient(stdClass::class), 'stdClass isTransient');
9192
}
9293

93-
/** @group DDC-1412 */
94+
#[Group('DDC-1412')]
9495
public function testDefaultDriver(): void
9596
{
9697
$companyDriver = $this->createMock(MappingDriver::class);
@@ -104,14 +105,14 @@ public function testDefaultDriver(): void
104105
$companyDriver->expects(self::once())
105106
->method('isTransient')
106107
->with(self::equalTo($managerClassName))
107-
->will(self::returnValue(false));
108+
->willReturn(false);
108109

109110
$defaultDriver->expects(self::never())
110111
->method('loadMetadataForClass');
111112
$defaultDriver->expects(self::once())
112113
->method('isTransient')
113114
->with(self::equalTo($entityClassName))
114-
->will(self::returnValue(true));
115+
->willReturn(true);
115116

116117
self::assertNull($chain->getDefaultDriver());
117118

@@ -134,11 +135,11 @@ public function testDefaultDriverGetAllClassNames(): void
134135

135136
$companyDriver->expects(self::once())
136137
->method('getAllClassNames')
137-
->will(self::returnValue(['Doctrine\Tests\Models\Company\Foo']));
138+
->willReturn(['Doctrine\Tests\Models\Company\Foo']);
138139

139140
$defaultDriver->expects(self::once())
140141
->method('getAllClassNames')
141-
->will(self::returnValue(['Other\Class']));
142+
->willReturn(['Other\Class']);
142143

143144
$chain->setDefaultDriver($defaultDriver);
144145
$chain->addDriver($companyDriver, 'Doctrine\Tests\Models\Company');

0 commit comments

Comments
 (0)