mirror of
https://github.com/doctrine/data-fixtures.git
synced 2026-03-23 22:32:13 +01:00
@@ -10,17 +10,23 @@
|
||||
"slug": "latest",
|
||||
"upcoming": true
|
||||
},
|
||||
{
|
||||
"name": "2.2",
|
||||
"branchName": "2.2.x",
|
||||
"slug": "2.2",
|
||||
"upcoming": true
|
||||
},
|
||||
{
|
||||
"name": "2.1",
|
||||
"branchName": "2.1.x",
|
||||
"slug": "2.1",
|
||||
"upcoming": true
|
||||
"current": true
|
||||
},
|
||||
{
|
||||
"name": "2.0",
|
||||
"branchName": "2.0.x",
|
||||
"slug": "2.0",
|
||||
"current": true
|
||||
"maintained": false
|
||||
},
|
||||
{
|
||||
"name": "1.8",
|
||||
|
||||
2
.github/workflows/coding-standards.yml
vendored
2
.github/workflows/coding-standards.yml
vendored
@@ -11,4 +11,4 @@ on:
|
||||
jobs:
|
||||
coding-standards:
|
||||
name: "Coding Standards"
|
||||
uses: "doctrine/.github/.github/workflows/coding-standards.yml@7.3.0"
|
||||
uses: "doctrine/.github/.github/workflows/coding-standards.yml@10.1.0"
|
||||
|
||||
2
.github/workflows/documentation.yml
vendored
2
.github/workflows/documentation.yml
vendored
@@ -17,4 +17,4 @@ on:
|
||||
jobs:
|
||||
documentation:
|
||||
name: "Documentation"
|
||||
uses: "doctrine/.github/.github/workflows/documentation.yml@7.3.0"
|
||||
uses: "doctrine/.github/.github/workflows/documentation.yml@10.1.0"
|
||||
|
||||
@@ -8,7 +8,7 @@ on:
|
||||
jobs:
|
||||
release:
|
||||
name: "Git tag, release & create merge-up PR"
|
||||
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@7.3.0"
|
||||
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@10.1.0"
|
||||
secrets:
|
||||
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
|
||||
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
|
||||
|
||||
2
.github/workflows/static-analysis.yml
vendored
2
.github/workflows/static-analysis.yml
vendored
@@ -11,4 +11,4 @@ on:
|
||||
jobs:
|
||||
static-analysis:
|
||||
name: "Static Analysis"
|
||||
uses: "doctrine/.github/.github/workflows/phpstan.yml@7.3.0"
|
||||
uses: "doctrine/.github/.github/workflows/phpstan.yml@10.1.0"
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-sqlite3": "*",
|
||||
"doctrine/coding-standard": "^13",
|
||||
"doctrine/coding-standard": "^14",
|
||||
"doctrine/dbal": "^3.5 || ^4",
|
||||
"doctrine/mongodb-odm": "^1.3.0 || ^2.0.0",
|
||||
"doctrine/orm": "^2.14 || ^3",
|
||||
"fig/log-test": "^1",
|
||||
"phpstan/phpstan": "2.1.22",
|
||||
"phpunit/phpunit": "10.5.45",
|
||||
"phpstan/phpstan": "2.1.31",
|
||||
"phpunit/phpunit": "10.5.45 || 12.4.0",
|
||||
"symfony/cache": "^6.4 || ^7",
|
||||
"symfony/var-exporter": "^6.4 || ^7"
|
||||
},
|
||||
|
||||
@@ -270,6 +270,12 @@ parameters:
|
||||
count: 1
|
||||
path: src/Sorter/Vertex.php
|
||||
|
||||
-
|
||||
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\ORMSetup'' and ''createAttributeMeta…'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 1
|
||||
path: tests/Common/DataFixtures/BaseTestCase.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\Tests\\Common\\DataFixtures\\FixtureWithUnexistentDependency\:\:getDependencies\(\) should return array\<class\-string\<Doctrine\\Common\\DataFixtures\\FixtureInterface\>\> but returns array\<int, string\>\.$#'
|
||||
identifier: return.type
|
||||
@@ -277,19 +283,7 @@ parameters:
|
||||
path: tests/Common/DataFixtures/DependentFixtureTest.php
|
||||
|
||||
-
|
||||
message: '#^Call to method expects\(\) on an unknown class Doctrine\\ODM\\PHPCR\\DocumentManager\.$#'
|
||||
identifier: class.notFound
|
||||
count: 5
|
||||
path: tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php
|
||||
|
||||
-
|
||||
message: '#^Method Doctrine\\Tests\\Common\\DataFixtures\\Executor\\PHPCRExecutorTest\:\:getDocumentManager\(\) has invalid return type Doctrine\\ODM\\PHPCR\\DocumentManager\.$#'
|
||||
identifier: class.notFound
|
||||
count: 1
|
||||
path: tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$dm of class Doctrine\\Common\\DataFixtures\\Executor\\PHPCRExecutor constructor expects Doctrine\\ODM\\PHPCR\\DocumentManagerInterface, Doctrine\\ODM\\PHPCR\\DocumentManager&PHPUnit\\Framework\\MockObject\\MockObject given\.$#'
|
||||
message: '#^Parameter \#1 \$dm of class Doctrine\\Common\\DataFixtures\\Executor\\PHPCRExecutor constructor expects Doctrine\\ODM\\PHPCR\\DocumentManagerInterface, Doctrine\\Tests\\Mock\\PHPCRDocumentManager&PHPUnit\\Framework\\MockObject\\MockObject given\.$#'
|
||||
identifier: argument.type
|
||||
count: 5
|
||||
path: tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php
|
||||
@@ -300,6 +294,12 @@ parameters:
|
||||
count: 3
|
||||
path: tests/Common/DataFixtures/Executor/PHPCRExecutorTest.php
|
||||
|
||||
-
|
||||
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\ORMSetup'' and ''createAttributeMeta…'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 2
|
||||
path: tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php
|
||||
|
||||
-
|
||||
message: '#^Call to an undefined method Doctrine\\ODM\\MongoDB\\DocumentManager\:\:getConnection\(\)\.$#'
|
||||
identifier: method.notFound
|
||||
@@ -312,6 +312,12 @@ parameters:
|
||||
count: 1
|
||||
path: tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php
|
||||
|
||||
-
|
||||
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\ORMSetup'' and ''createAttributeMeta…'' will always evaluate to true\.$#'
|
||||
identifier: function.alreadyNarrowedType
|
||||
count: 2
|
||||
path: tests/Common/DataFixtures/ReferenceRepositoryTest.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$name of class Doctrine\\ORM\\Mapping\\ClassMetadata constructor expects class\-string\<1\>, string given\.$#'
|
||||
identifier: argument.type
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
parameters:
|
||||
phpVersion: 80200
|
||||
phpVersion: 80400
|
||||
level: 7
|
||||
paths:
|
||||
- src
|
||||
- tests
|
||||
excludePaths:
|
||||
- tests/Mock/ForwardCompatibleEntityManager.php
|
||||
- tests/Mock/PHPCRDocumentManager.php
|
||||
|
||||
includes:
|
||||
- phpstan-baseline.neon
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||
colors="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
beStrictAboutTodoAnnotatedTests="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
displayDetailsOnTestsThatTriggerDeprecations="true"
|
||||
failOnDeprecation="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine Data Fixtures Test Suite">
|
||||
@@ -12,9 +12,13 @@
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<coverage>
|
||||
<php>
|
||||
<env name="DOCTRINE_DEPRECATIONS" value="trigger"/>
|
||||
</php>
|
||||
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<include>
|
||||
<directory>./src</directory>
|
||||
<directory>./src/</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
</source>
|
||||
</phpunit>
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Doctrine\Common\DataFixtures\Purger;
|
||||
|
||||
use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Schema\AbstractNamedObject;
|
||||
use Doctrine\DBAL\Schema\Identifier;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
@@ -13,6 +14,7 @@ use Doctrine\ORM\Mapping\ManyToManyOwningSideMapping;
|
||||
|
||||
use function array_map;
|
||||
use function array_reverse;
|
||||
use function class_exists;
|
||||
use function count;
|
||||
use function in_array;
|
||||
|
||||
@@ -253,6 +255,12 @@ final class ORMPurger implements ORMPurgerInterface
|
||||
{
|
||||
$tableIdentifier = new Identifier($tableName);
|
||||
|
||||
return 'DELETE FROM ' . $tableIdentifier->getQuotedName($platform);
|
||||
if (class_exists(AbstractNamedObject::class)) {
|
||||
$identifier = $tableIdentifier->getObjectName()->toSQL($platform);
|
||||
} else {
|
||||
$identifier = $tableIdentifier->getQuotedName($platform);
|
||||
}
|
||||
|
||||
return 'DELETE FROM ' . $identifier;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ class ReferenceRepository
|
||||
* not be set yet
|
||||
*
|
||||
* Notice: in case if identifier is generated after
|
||||
* the record is inserted, be sure tu use this method
|
||||
* the record is inserted, be sure to use this method
|
||||
* after $object is flushed
|
||||
*
|
||||
* @param object $object - managed object
|
||||
|
||||
@@ -11,9 +11,8 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function method_exists;
|
||||
|
||||
/**
|
||||
* Base test class
|
||||
*/
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
abstract class BaseTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
@@ -24,8 +23,13 @@ abstract class BaseTestCase extends TestCase
|
||||
protected function getMockSqliteEntityManager(string $fixtureSet = 'TestEntity'): EntityManager
|
||||
{
|
||||
$dbParams = ['driver' => 'sqlite3', 'memory' => true];
|
||||
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/' . $fixtureSet], true);
|
||||
$config->setLazyGhostObjectEnabled(true);
|
||||
if (PHP_VERSION_ID >= 80400 && method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) {
|
||||
$config = ORMSetup::createAttributeMetadataConfig([__DIR__ . '/' . $fixtureSet], true);
|
||||
$config->enableNativeLazyObjects(true);
|
||||
} else {
|
||||
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/' . $fixtureSet], true);
|
||||
$config->setLazyGhostObjectEnabled(true);
|
||||
}
|
||||
|
||||
$connection = DriverManager::getConnection($dbParams, $config);
|
||||
$platform = $connection->getDatabasePlatform();
|
||||
|
||||
@@ -10,6 +10,7 @@ use Doctrine\Common\DataFixtures\SharedFixtureInterface;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Doctrine\Tests\Common\DataFixtures\TestEntity\Role;
|
||||
use Doctrine\Tests\Common\DataFixtures\TestEntity\User;
|
||||
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,7 @@ class ORMExecutorSharedFixtureTest extends BaseTestCase
|
||||
public const TEST_ENTITY_ROLE = Role::class;
|
||||
public const TEST_ENTITY_USER = User::class;
|
||||
|
||||
#[IgnoreDeprecations]
|
||||
public function testFixtureExecution(): void
|
||||
{
|
||||
$em = $this->getMockSqliteEntityManager();
|
||||
@@ -39,6 +41,7 @@ class ORMExecutorSharedFixtureTest extends BaseTestCase
|
||||
$executor->execute([$fixture], true);
|
||||
}
|
||||
|
||||
#[IgnoreDeprecations]
|
||||
public function testSharedFixtures(): void
|
||||
{
|
||||
$em = $this->getMockSqliteEntityManager();
|
||||
|
||||
@@ -9,17 +9,15 @@ use Doctrine\Common\DataFixtures\FixtureInterface;
|
||||
use Doctrine\Common\DataFixtures\Purger\PHPCRPurgerInterface;
|
||||
use Doctrine\ODM\PHPCR\DocumentManager;
|
||||
use Doctrine\Tests\Common\DataFixtures\BaseTestCase;
|
||||
use Doctrine\Tests\Mock\PHPCRDocumentManager;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Throwable;
|
||||
|
||||
use function class_exists;
|
||||
|
||||
/**
|
||||
* Tests for {@see \Doctrine\Common\DataFixtures\Executor\PHPCRExecutor}
|
||||
*
|
||||
* @covers \Doctrine\Common\DataFixtures\Executor\PHPCRExecutor
|
||||
*/
|
||||
#[CoversClass(PHPCRExecutor::class)]
|
||||
class PHPCRExecutorTest extends BaseTestCase
|
||||
{
|
||||
public function testExecuteSingleFixtureWithNoPurge(): void
|
||||
@@ -33,9 +31,9 @@ class PHPCRExecutorTest extends BaseTestCase
|
||||
->expects($this->once())
|
||||
->method('transactional')
|
||||
->with($this->isType('callable'))
|
||||
->will($this->returnCallback(static function ($callback) use ($dm) {
|
||||
->willReturnCallback(static function ($callback) use ($dm) {
|
||||
return $callback($dm);
|
||||
}));
|
||||
});
|
||||
|
||||
$executor->execute([$fixture], true);
|
||||
}
|
||||
@@ -53,9 +51,9 @@ class PHPCRExecutorTest extends BaseTestCase
|
||||
->expects($this->once())
|
||||
->method('transactional')
|
||||
->with($this->isType('callable'))
|
||||
->will($this->returnCallback(static function ($callback) use ($dm) {
|
||||
->willReturnCallback(static function ($callback) use ($dm) {
|
||||
return $callback($dm);
|
||||
}));
|
||||
});
|
||||
|
||||
$executor->execute([$fixture1, $fixture2], true);
|
||||
}
|
||||
@@ -72,9 +70,9 @@ class PHPCRExecutorTest extends BaseTestCase
|
||||
->expects($this->once())
|
||||
->method('transactional')
|
||||
->with($this->isType('callable'))
|
||||
->will($this->returnCallback(static function ($callback) use ($dm) {
|
||||
->willReturnCallback(static function ($callback) use ($dm) {
|
||||
return $callback($dm);
|
||||
}));
|
||||
});
|
||||
$purger->expects($this->once())->method('purge');
|
||||
|
||||
$executor->execute([$fixture], false);
|
||||
@@ -92,9 +90,9 @@ class PHPCRExecutorTest extends BaseTestCase
|
||||
->expects($this->once())
|
||||
->method('transactional')
|
||||
->with($this->isType('callable'))
|
||||
->will($this->returnCallback(static function ($callback) use ($dm) {
|
||||
->willReturnCallback(static function ($callback) use ($dm) {
|
||||
return $callback($dm);
|
||||
}));
|
||||
});
|
||||
$purger->expects($this->never())->method('purge');
|
||||
|
||||
$executor->execute([$fixture], true);
|
||||
@@ -124,19 +122,14 @@ class PHPCRExecutorTest extends BaseTestCase
|
||||
return $this->createMock(PHPCRPurgerInterface::class);
|
||||
}
|
||||
|
||||
private function getDocumentManager(): DocumentManager&MockObject
|
||||
private function getDocumentManager(): PHPCRDocumentManager&MockObject
|
||||
{
|
||||
if (! class_exists(DocumentManager::class)) {
|
||||
$this->markTestSkipped('Missing doctrine/phpcr-odm');
|
||||
}
|
||||
|
||||
return $this
|
||||
->getMockBuilder(DocumentManager::class)
|
||||
->addMethods([
|
||||
'transactional',
|
||||
'flush',
|
||||
'clear',
|
||||
])
|
||||
->getMockBuilder(PHPCRDocumentManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
@@ -7,16 +7,20 @@ namespace Doctrine\Tests\Common\DataFixtures;
|
||||
use Doctrine\Common\DataFixtures\Event\Listener\ORMReferenceListener;
|
||||
use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\ORM\ORMSetup;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Doctrine\Persistence\Proxy;
|
||||
use Doctrine\Tests\Common\DataFixtures\TestEntity\Link;
|
||||
use Doctrine\Tests\Common\DataFixtures\TestEntity\Role;
|
||||
use Doctrine\Tests\Common\DataFixtures\TestTypes\UuidType;
|
||||
use Doctrine\Tests\Common\DataFixtures\TestValueObjects\Uuid;
|
||||
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
|
||||
use ReflectionClass;
|
||||
|
||||
use function method_exists;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
/**
|
||||
* Test ProxyReferenceRepository.
|
||||
*/
|
||||
class ProxyReferenceRepositoryTest extends BaseTestCase
|
||||
{
|
||||
public const TEST_ENTITY_ROLE = Role::class;
|
||||
@@ -33,12 +37,15 @@ class ProxyReferenceRepositoryTest extends BaseTestCase
|
||||
Type::addType('uuid', UuidType::class);
|
||||
}
|
||||
|
||||
#[IgnoreDeprecations]
|
||||
public function testReferenceEntry(): void
|
||||
{
|
||||
$em = $this->getMockSqliteEntityManager();
|
||||
$role = new TestEntity\Role();
|
||||
$role->setName('admin');
|
||||
$meta = $em->getClassMetadata(self::TEST_ENTITY_ROLE);
|
||||
|
||||
// getPropertyAccessor() is not available with ORM < 3.4
|
||||
$meta->getReflectionProperty('id')->setValue($role, 1);
|
||||
|
||||
$referenceRepo = new ProxyReferenceRepository($em);
|
||||
@@ -72,7 +79,7 @@ class ProxyReferenceRepositoryTest extends BaseTestCase
|
||||
|
||||
$referenceRepository->expects($this->once())
|
||||
->method('getReferenceNames')
|
||||
->will($this->returnValue(['admin-role']));
|
||||
->willReturn(['admin-role']);
|
||||
|
||||
$referenceRepository->expects($this->once())
|
||||
->method('setReferenceIdentity')
|
||||
@@ -100,7 +107,7 @@ class ProxyReferenceRepositoryTest extends BaseTestCase
|
||||
// first test against managed state
|
||||
$ref = $referenceRepository->getReference('admin-role', Role::class);
|
||||
|
||||
$this->assertNotInstanceOf(Proxy::class, $ref);
|
||||
$this->assertNotProxy($ref);
|
||||
|
||||
// test reference reconstruction from serialized data (was managed)
|
||||
$serializedData = $referenceRepository->serialize();
|
||||
@@ -111,14 +118,14 @@ class ProxyReferenceRepositoryTest extends BaseTestCase
|
||||
$ref = $proxyReferenceRepository->getReference('admin-role', Role::class);
|
||||
|
||||
// before clearing, the reference is not yet a proxy
|
||||
$this->assertNotInstanceOf(Proxy::class, $ref);
|
||||
$this->assertNotProxy($ref);
|
||||
$this->assertInstanceOf(self::TEST_ENTITY_ROLE, $ref);
|
||||
|
||||
// now test reference reconstruction from identity
|
||||
$em->clear();
|
||||
$ref = $referenceRepository->getReference('admin-role', Role::class);
|
||||
|
||||
$this->assertInstanceOf(Proxy::class, $ref);
|
||||
$this->assertProxy($ref);
|
||||
|
||||
// test reference reconstruction from serialized data (was identity)
|
||||
$serializedData = $referenceRepository->serialize();
|
||||
@@ -128,9 +135,10 @@ class ProxyReferenceRepositoryTest extends BaseTestCase
|
||||
|
||||
$ref = $proxyReferenceRepository->getReference('admin-role', Role::class);
|
||||
|
||||
$this->assertInstanceOf(Proxy::class, $ref);
|
||||
$this->assertProxy($ref);
|
||||
}
|
||||
|
||||
#[IgnoreDeprecations]
|
||||
public function testReconstructionOfCustomTypedId(): void
|
||||
{
|
||||
$em = $this->getMockSqliteEntityManager();
|
||||
@@ -177,7 +185,31 @@ class ProxyReferenceRepositoryTest extends BaseTestCase
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
|
||||
$this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('admin', Role::class));
|
||||
$this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('duplicate', Role::class));
|
||||
$this->assertProxy($referenceRepository->getReference('admin', Role::class));
|
||||
$this->assertProxy($referenceRepository->getReference('duplicate', Role::class));
|
||||
}
|
||||
|
||||
private function assertProxy(object $object): void
|
||||
{
|
||||
if (PHP_VERSION_ID < 80400 || ! method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) {
|
||||
$this->assertInstanceOf(Proxy::class, $object);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$reflector = new ReflectionClass($object);
|
||||
$this->assertTrue($reflector->isUninitializedLazyObject($object));
|
||||
}
|
||||
|
||||
private function assertNotProxy(object $object): void
|
||||
{
|
||||
if (PHP_VERSION_ID < 80400 || ! method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) {
|
||||
$this->assertNotInstanceOf(Proxy::class, $object);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$reflector = new ReflectionClass($object);
|
||||
$this->assertFalse($reflector->isUninitializedLazyObject($object));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,11 @@ declare(strict_types=1);
|
||||
namespace Doctrine\Tests\Common\DataFixtures;
|
||||
|
||||
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
|
||||
use Doctrine\DBAL\Schema\AbstractNamedObject;
|
||||
use ReflectionClass;
|
||||
|
||||
use function class_exists;
|
||||
|
||||
/**
|
||||
* Doctrine\Tests\Common\DataFixtures\ORMPurgerTest
|
||||
*/
|
||||
@@ -86,6 +89,11 @@ class ORMPurgerTest extends BaseTestCase
|
||||
$method = $class->getMethod('getDeleteFromTableSQL');
|
||||
$method->setAccessible(true);
|
||||
$sql = $method->invokeArgs($purger, [$tableName, $platform]);
|
||||
$this->assertEquals('DELETE FROM test_schema."group"', $sql);
|
||||
|
||||
if (class_exists(AbstractNamedObject::class)) {
|
||||
$this->assertEquals('DELETE FROM "test_schema"."group"', $sql);
|
||||
} else {
|
||||
$this->assertEquals('DELETE FROM test_schema."group"', $sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use BadMethodCallException;
|
||||
use Doctrine\Common\DataFixtures\Event\Listener\ORMReferenceListener;
|
||||
use Doctrine\Common\DataFixtures\ReferenceRepository;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\ORMSetup;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
use Doctrine\Persistence\Proxy;
|
||||
@@ -15,11 +16,17 @@ use Doctrine\Tests\Common\DataFixtures\TestEntity\Role;
|
||||
use Doctrine\Tests\Common\DataFixtures\TestEntity\User;
|
||||
use Doctrine\Tests\Mock\ForwardCompatibleEntityManager;
|
||||
use OutOfBoundsException;
|
||||
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
|
||||
use ReflectionClass;
|
||||
|
||||
use function method_exists;
|
||||
use function sprintf;
|
||||
|
||||
use const PHP_VERSION_ID;
|
||||
|
||||
class ReferenceRepositoryTest extends BaseTestCase
|
||||
{
|
||||
#[IgnoreDeprecations]
|
||||
public function testReferenceEntry(): void
|
||||
{
|
||||
$em = $this->getMockSqliteEntityManager();
|
||||
@@ -91,13 +98,13 @@ class ReferenceRepositoryTest extends BaseTestCase
|
||||
// first test against managed state
|
||||
$ref = $referenceRepository->getReference('admin-role', Role::class);
|
||||
|
||||
$this->assertNotInstanceOf(Proxy::class, $ref);
|
||||
$this->assertNotProxy($ref);
|
||||
|
||||
// now test reference reconstruction from identity
|
||||
$em->clear();
|
||||
$ref = $referenceRepository->getReference('admin-role', Role::class);
|
||||
|
||||
$this->assertInstanceOf(Proxy::class, $ref);
|
||||
$this->assertProxy($ref);
|
||||
}
|
||||
|
||||
public function testReferenceMultipleEntries(): void
|
||||
@@ -117,8 +124,8 @@ class ReferenceRepositoryTest extends BaseTestCase
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
|
||||
$this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('admin', Role::class));
|
||||
$this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('duplicate', Role::class));
|
||||
$this->assertProxy($referenceRepository->getReference('admin', Role::class));
|
||||
$this->assertProxy($referenceRepository->getReference('duplicate', Role::class));
|
||||
}
|
||||
|
||||
public function testUndefinedReference(): void
|
||||
@@ -131,7 +138,7 @@ class ReferenceRepositoryTest extends BaseTestCase
|
||||
$referenceRepository->getReference('foo', Role::class);
|
||||
}
|
||||
|
||||
/** @group legacy */
|
||||
#[IgnoreDeprecations]
|
||||
public function testLegacyUndefinedReference(): void
|
||||
{
|
||||
$referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager());
|
||||
@@ -263,4 +270,28 @@ class ReferenceRepositoryTest extends BaseTestCase
|
||||
$this->assertCount(1, $names);
|
||||
$this->assertSame('1', $names[0]);
|
||||
}
|
||||
|
||||
private function assertProxy(object $object): void
|
||||
{
|
||||
if (PHP_VERSION_ID < 80400 || ! method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) {
|
||||
$this->assertInstanceOf(Proxy::class, $object);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$reflector = new ReflectionClass($object);
|
||||
$this->assertTrue($reflector->isUninitializedLazyObject($object));
|
||||
}
|
||||
|
||||
private function assertNotProxy(object $object): void
|
||||
{
|
||||
if (PHP_VERSION_ID < 80400 || ! method_exists(ORMSetup::class, 'createAttributeMetadataConfig')) {
|
||||
$this->assertNotInstanceOf(Proxy::class, $object);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$reflector = new ReflectionClass($object);
|
||||
$this->assertFalse($reflector->isUninitializedLazyObject($object));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Doctrine\Common\DataFixtures\Exception\CircularReferenceException;
|
||||
use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\Tests\Common\DataFixtures\BaseTestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
@@ -16,9 +17,8 @@ use RuntimeException;
|
||||
* Note: When writing tests here consider that a lot of graph
|
||||
* constellations can have many valid orderings, so you may want to
|
||||
* build a graph that has only 1 valid order to simplify your tests
|
||||
*
|
||||
* @covers \Doctrine\Common\DataFixtures\Sorter\TopologicalSorter
|
||||
*/
|
||||
#[CoversClass(TopologicalSorter::class)]
|
||||
class TopologicalSorterTest extends BaseTestCase
|
||||
{
|
||||
public function testSuccessSortLinearDependency(): void
|
||||
|
||||
@@ -7,8 +7,9 @@ namespace Doctrine\Test\DataFixtures\Sorter;
|
||||
use Doctrine\Common\DataFixtures\Sorter\Vertex;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\Tests\Common\DataFixtures\BaseTestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
|
||||
/** @covers \Doctrine\Common\DataFixtures\Sorter\Vertex */
|
||||
#[CoversClass(Vertex::class)]
|
||||
class VertexTest extends BaseTestCase
|
||||
{
|
||||
public function testNode(): void
|
||||
|
||||
13
tests/Mock/PHPCRDocumentManager.php
Normal file
13
tests/Mock/PHPCRDocumentManager.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\Mock;
|
||||
|
||||
use Closure;
|
||||
use Doctrine\ODM\PHPCR\DocumentManager;
|
||||
|
||||
abstract class PHPCRDocumentManager extends DocumentManager
|
||||
{
|
||||
abstract public function transactional(Closure $func): void;
|
||||
}
|
||||
Reference in New Issue
Block a user