1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
From: =?utf-8?q?David_Pr=C3=A9vot?= <taffit@debian.org>
Date: Tue, 18 Feb 2025 01:40:18 +0100
Subject: Modernize PHPUnit syntax
---
tests/Persistence/ManagerRegistryTest.php | 6 +++---
.../Mapping/AbstractClassMetadataFactoryTest.php | 3 +++
.../Mapping/ColocatedMappingDriverTest.php | 3 ++-
tests/Persistence/Mapping/DriverChainTest.php | 12 ++++++------
tests/Persistence/Mapping/FileDriverTest.php | 22 +++++++++++-----------
.../Persistence/Mapping/SymfonyFileLocatorTest.php | 7 +++----
.../Persistence/RuntimeReflectionPropertyTest.php | 12 +++++-------
7 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/tests/Persistence/ManagerRegistryTest.php b/tests/Persistence/ManagerRegistryTest.php
index b01a48b..a066c50 100644
--- a/tests/Persistence/ManagerRegistryTest.php
+++ b/tests/Persistence/ManagerRegistryTest.php
@@ -85,7 +85,7 @@ class ManagerRegistryTest extends DoctrineTestCase
->expects(self::once())
->method('getRepository')
->with(self::equalTo(TestObject::class))
- ->will(self::returnValue($repository));
+ ->willReturn($repository);
self::assertSame($repository, $this->mr->getRepository(TestObject::class));
}
@@ -116,7 +116,7 @@ class ManagerRegistryTest extends DoctrineTestCase
->expects(self::once())
->method('getRepository')
->with(self::equalTo(TestObject::class))
- ->will(self::returnValue($repository));
+ ->willReturn($repository);
self::assertSame($repository, $this->mr->getRepository(TestObject::class, 'other'));
}
@@ -147,7 +147,7 @@ class ManagerRegistryTest extends DoctrineTestCase
->expects(self::once())
->method('getRepository')
->with(self::equalTo(OtherTestObject::class))
- ->will(self::returnValue($repository));
+ ->willReturn($repository);
self::assertSame($repository, $this->mr->getRepository(OtherTestObject::class));
}
diff --git a/tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php b/tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php
index 0393447..b31584e 100644
--- a/tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php
+++ b/tests/Persistence/Mapping/AbstractClassMetadataFactoryTest.php
@@ -9,9 +9,12 @@ use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\MappingException;
use Doctrine\Tests\DoctrineTestCase;
+use PHPUnit\Framework\Attributes\RequiresPhpunit;
+#[RequiresPhpunit('< 12')]
final class AbstractClassMetadataFactoryTest extends DoctrineTestCase
{
+ #[RequiresPhpunit('< 10')]
public function testItSkipsTransientClasses(): void
{
$cmf = $this->getMockForAbstractClass(AbstractClassMetadataFactory::class);
diff --git a/tests/Persistence/Mapping/ColocatedMappingDriverTest.php b/tests/Persistence/Mapping/ColocatedMappingDriverTest.php
index 3dd5b97..7b9eebe 100644
--- a/tests/Persistence/Mapping/ColocatedMappingDriverTest.php
+++ b/tests/Persistence/Mapping/ColocatedMappingDriverTest.php
@@ -13,6 +13,7 @@ use Doctrine\Tests\Persistence\Mapping\_files\colocated\Entity;
use Doctrine\Tests\Persistence\Mapping\_files\colocated\EntityFixture;
use Doctrine\Tests\Persistence\Mapping\_files\colocated\TestClass;
use Generator;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use function sort;
@@ -58,7 +59,7 @@ class ColocatedMappingDriverTest extends TestCase
self::assertSame('.php1', $driver->getFileExtension());
}
- /** @dataProvider directoryPathProvider */
+ #[DataProvider('directoryPathProvider')]
public function testGetAllClassNamesForDirectory(string $dirPath): void
{
$driver = $this->createDirectoryPathDriver($dirPath);
diff --git a/tests/Persistence/Mapping/DriverChainTest.php b/tests/Persistence/Mapping/DriverChainTest.php
index 3199bc7..37f5b1f 100644
--- a/tests/Persistence/Mapping/DriverChainTest.php
+++ b/tests/Persistence/Mapping/DriverChainTest.php
@@ -63,12 +63,12 @@ class DriverChainTest extends DoctrineTestCase
$driver1 = $this->createMock(MappingDriver::class);
$driver1->expects(self::once())
->method('getAllClassNames')
- ->will(self::returnValue(['Doctrine\Tests\Models\Company\Foo']));
+ ->willReturn(['Doctrine\Tests\Models\Company\Foo']);
$driver2 = $this->createMock(MappingDriver::class);
$driver2->expects(self::once())
->method('getAllClassNames')
- ->will(self::returnValue(['Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz']));
+ ->willReturn(['Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz']);
$chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
$chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
@@ -104,14 +104,14 @@ class DriverChainTest extends DoctrineTestCase
$companyDriver->expects(self::once())
->method('isTransient')
->with(self::equalTo($managerClassName))
- ->will(self::returnValue(false));
+ ->willReturn(false);
$defaultDriver->expects(self::never())
->method('loadMetadataForClass');
$defaultDriver->expects(self::once())
->method('isTransient')
->with(self::equalTo($entityClassName))
- ->will(self::returnValue(true));
+ ->willReturn(true);
self::assertNull($chain->getDefaultDriver());
@@ -134,11 +134,11 @@ class DriverChainTest extends DoctrineTestCase
$companyDriver->expects(self::once())
->method('getAllClassNames')
- ->will(self::returnValue(['Doctrine\Tests\Models\Company\Foo']));
+ ->willReturn(['Doctrine\Tests\Models\Company\Foo']);
$defaultDriver->expects(self::once())
->method('getAllClassNames')
- ->will(self::returnValue(['Other\Class']));
+ ->willReturn(['Other\Class']);
$chain->setDefaultDriver($defaultDriver);
$chain->addDriver($companyDriver, 'Doctrine\Tests\Models\Company');
diff --git a/tests/Persistence/Mapping/FileDriverTest.php b/tests/Persistence/Mapping/FileDriverTest.php
index 8954fb6..1113b1e 100644
--- a/tests/Persistence/Mapping/FileDriverTest.php
+++ b/tests/Persistence/Mapping/FileDriverTest.php
@@ -47,7 +47,7 @@ class FileDriverTest extends DoctrineTestCase
$locator->expects(self::once())
->method('findMappingFile')
->with(self::equalTo(stdClass::class))
- ->will(self::returnValue(__DIR__ . '/_files/stdClass.yml'));
+ ->willReturn(__DIR__ . '/_files/stdClass.yml');
$driver = $this->createTestFileDriver($locator);
@@ -62,7 +62,7 @@ class FileDriverTest extends DoctrineTestCase
$locator->expects(self::once())
->method('findMappingFile')
->with(self::equalTo(stdClass::class))
- ->will(self::returnValue(__DIR__ . '/_files/stdClass.yml'));
+ ->willReturn(__DIR__ . '/_files/stdClass.yml');
$driver = $this->createTestFileDriver($locator);
@@ -76,10 +76,10 @@ class FileDriverTest extends DoctrineTestCase
public function testGetAllClassNamesGlobalBasename(): void
{
$locator = $this->newLocator();
- $locator->expects(self::any())->method('getAllClassNames')->with('global')->will(self::returnValue([
+ $locator->expects(self::any())->method('getAllClassNames')->with('global')->willReturn([
GlobalClass::class,
AnotherGlobalClass::class,
- ]));
+ ]);
$driver = $this->createTestFileDriver($locator);
$driver->setGlobalBasename('global');
@@ -95,7 +95,7 @@ class FileDriverTest extends DoctrineTestCase
$locator->expects(self::any())
->method('getAllClassNames')
->with(self::equalTo(null))
- ->will(self::returnValue([stdClass::class]));
+ ->willReturn([stdClass::class]);
$driver = new TestFileDriver($locator);
$classNames = $driver->getAllClassNames();
@@ -109,7 +109,7 @@ class FileDriverTest extends DoctrineTestCase
$locator->expects(self::any())
->method('getAllClassNames')
->with(self::equalTo('global'))
- ->will(self::returnValue([stdClass::class]));
+ ->willReturn([stdClass::class]);
$driver = new TestFileDriver($locator);
$driver->setGlobalBasename('global');
@@ -128,7 +128,7 @@ class FileDriverTest extends DoctrineTestCase
$locator->expects(self::once())
->method('findMappingFile')
->with(self::equalTo(stdClass::class))
- ->will(self::returnValue(__DIR__ . '/_files/stdClass.yml'));
+ ->willReturn(__DIR__ . '/_files/stdClass.yml');
$driver = new TestFileDriver($locator);
$driver->setGlobalBasename('global');
@@ -144,7 +144,7 @@ class FileDriverTest extends DoctrineTestCase
$locator->expects(self::once())
->method('fileExists')
->with(self::equalTo(stdClass::class))
- ->will(self::returnValue(true));
+ ->willReturn(true);
$driver = $this->createTestFileDriver($locator);
$driver->setGlobalBasename('global');
@@ -160,7 +160,7 @@ class FileDriverTest extends DoctrineTestCase
$locator->expects(self::once())
->method('fileExists')
->with(self::equalTo(NotLoadedClass::class))
- ->will(self::returnValue(false));
+ ->willReturn(false);
$driver = $this->createTestFileDriver($locator);
@@ -178,8 +178,8 @@ class FileDriverTest extends DoctrineTestCase
private function newLocator(): MockObject
{
$locator = $this->createMock(FileLocator::class);
- $locator->expects(self::any())->method('getFileExtension')->will(self::returnValue('.yml'));
- $locator->expects(self::any())->method('getPaths')->will(self::returnValue([__DIR__ . '/_files']));
+ $locator->expects(self::any())->method('getFileExtension')->willReturn('.yml');
+ $locator->expects(self::any())->method('getPaths')->willReturn([__DIR__ . '/_files']);
return $locator;
}
diff --git a/tests/Persistence/Mapping/SymfonyFileLocatorTest.php b/tests/Persistence/Mapping/SymfonyFileLocatorTest.php
index 7d5e42d..632047b 100644
--- a/tests/Persistence/Mapping/SymfonyFileLocatorTest.php
+++ b/tests/Persistence/Mapping/SymfonyFileLocatorTest.php
@@ -8,6 +8,7 @@ use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator;
use Doctrine\Persistence\Mapping\MappingException;
use Doctrine\Tests\DoctrineTestCase;
use InvalidArgumentException;
+use PHPUnit\Framework\Attributes\DataProvider;
use function realpath;
use function sort;
@@ -106,9 +107,8 @@ class SymfonyFileLocatorTest extends DoctrineTestCase
* @param string $dir Path to load mapping data from
*
* @throws MappingException
- *
- * @dataProvider customNamespaceSeparatorProvider
*/
+ #[DataProvider('customNamespaceSeparatorProvider')]
public function testGetClassNamesWithCustomNsSeparator(string $separator, string $dir): void
{
$path = __DIR__ . $dir;
@@ -152,9 +152,8 @@ class SymfonyFileLocatorTest extends DoctrineTestCase
* @param string[] $files Files to lookup classnames
*
* @throws MappingException
- *
- * @dataProvider customNamespaceLookupQueryProvider
*/
+ #[DataProvider('customNamespaceLookupQueryProvider')]
public function testFindMappingFileWithCustomNsSeparator(string $separator, string $dir, array $files): void
{
$path = __DIR__ . $dir;
diff --git a/tests/Persistence/RuntimeReflectionPropertyTest.php b/tests/Persistence/RuntimeReflectionPropertyTest.php
index c44dd1f..da8c6de 100644
--- a/tests/Persistence/RuntimeReflectionPropertyTest.php
+++ b/tests/Persistence/RuntimeReflectionPropertyTest.php
@@ -7,6 +7,7 @@ namespace Doctrine\Tests\Persistence;
use Closure;
use Doctrine\Persistence\Proxy;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
+use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
class DummyMock
@@ -22,10 +23,8 @@ class DummyMock
class RuntimeReflectionPropertyTest extends TestCase
{
- /**
- * @testWith ["test", "testValue"]
- * ["privateTest", "privateTestValue"]
- */
+ #[testWith(["test", "testValue"])]
+ #[testWith(["privateTest", "privateTestValue"])]
public function testGetSetValue(string $name, string $value): void
{
$object = new RuntimeReflectionPropertyTestClass();
@@ -41,10 +40,9 @@ class RuntimeReflectionPropertyTest extends TestCase
/**
* @param class-string<RuntimeReflectionPropertyTestProxyMock> $proxyClass
- *
- * @testWith ["Doctrine\\Tests\\Persistence\\RuntimeReflectionPropertyTestProxyMock"]
- * ["\\Doctrine\\Tests\\Persistence\\RuntimeReflectionPropertyTestProxyMock"]
*/
+ #[testWith(["Doctrine\\Tests\\Persistence\\RuntimeReflectionPropertyTestProxyMock"])]
+ #[testWith(["\\Doctrine\\Tests\\Persistence\\RuntimeReflectionPropertyTestProxyMock"])]
public function testGetValueOnProxyProperty(string $proxyClass): void
{
$getCheckMock = $this->createMock(DummyMock::class);
|