Skip to content

Commit

Permalink
Remove usage of Doctrine annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Mar 8, 2024
1 parent e01cf5e commit 750e0d3
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 137 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
"require-dev": {
"ext-sqlite3": "*",
"doctrine/annotations": "^1.12 || ^2",
"doctrine/coding-standard": "^12",
"doctrine/dbal": "^3.5 || ^4",
"doctrine/mongodb-odm": "^1.3.0 || ^2.0.0",
Expand Down
10 changes: 2 additions & 8 deletions tests/Common/DataFixtures/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

use function method_exists;

use const PHP_VERSION_ID;

/**
* Base test class
*/
Expand All @@ -26,12 +24,8 @@ abstract class BaseTestCase extends TestCase
protected function getMockSqliteEntityManager(string $fixtureSet = 'TestEntity'): EntityManager
{
$dbParams = ['driver' => 'sqlite3', 'memory' => true];
if (PHP_VERSION_ID >= 80100) {
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/' . $fixtureSet], true);
$config->setLazyGhostObjectEnabled(true);
} else {
$config = ORMSetup::createAnnotationMetadataConfiguration([__DIR__ . '/' . $fixtureSet], true);
}
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/' . $fixtureSet], true);
$config->setLazyGhostObjectEnabled(true);

$connection = DriverManager::getConnection($dbParams, $config);
$platform = $connection->getDatabasePlatform();
Expand Down
11 changes: 5 additions & 6 deletions tests/Common/DataFixtures/Purger/MongoDBPurgerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
use Doctrine\Tests\Common\DataFixtures\BaseTestCase;
use Doctrine\Tests\Common\DataFixtures\TestDocument\Role;
use MongoCollection;
Expand All @@ -24,18 +24,18 @@ class MongoDBPurgerTest extends BaseTestCase

private function getDocumentManager(): DocumentManager
{
if (! class_exists('Doctrine\ODM\MongoDB\DocumentManager')) {
if (! class_exists(DocumentManager::class)) {
$this->markTestSkipped('Missing doctrine/mongodb-odm');
}

$root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
$root = dirname(__DIR__, 5);

$config = new Configuration();
$config->setProxyDir($root . '/generate/proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir($root . '/generate/hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setMetadataDriverImpl(AnnotationDriver::create(dirname(__DIR__) . '/TestDocument'));
$config->setMetadataDriverImpl(AttributeDriver::create(dirname(__DIR__) . '/TestDocument'));

$dm = DocumentManager::create(null, $config);

Expand Down Expand Up @@ -71,8 +71,7 @@ public function testPurgeKeepsIndices(): void
$this->assertIndexCount(2, $collection);
}

/** @param Collection|MongoCollection $collection */
private function assertIndexCount(int $expectedCount, object $collection): void
private function assertIndexCount(int $expectedCount, Collection|MongoCollection $collection): void
{
if ($collection instanceof Collection) {
$indexes = $collection->listIndexes();
Expand Down
10 changes: 4 additions & 6 deletions tests/Common/DataFixtures/TestDocument/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/** @ODM\Document */
#[ODM\Document]
class Role
{
/** @ODM\Id */
#[ODM\Id]
private string|null $id = null;

/**
* @ODM\Field(type="string")
* @ODM\Index
*/
#[ODM\Field(type: 'string')]
#[ODM\Index]
private string|null $name = null;

public function getId(): string|null
Expand Down
9 changes: 0 additions & 9 deletions tests/Common/DataFixtures/TestEntity/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@

use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity() */
#[ORM\Entity]
class Group
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
*/
#[ORM\Column]
#[ORM\Id]
private int|null $id = null;

/**
* @ORM\Column(length=32)
* @ORM\Id
*/
#[ORM\Column(length: 32)]
#[ORM\Id]
private string|null $code = null;
Expand Down
12 changes: 0 additions & 12 deletions tests/Common/DataFixtures/TestEntity/GroupWithSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity()
* @ORM\Table(name="group",schema="test_schema")
*/
#[ORM\Entity]
#[ORM\Table(name: 'group', schema: 'test_schema')]
class GroupWithSchema
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
*/
#[ORM\Column]
#[ORM\Id]
private int|null $id = null;

/**
* @ORM\Column(length=32)
* @ORM\Id
*/
#[ORM\Column(length: 32)]
#[ORM\Id]
private string|null $code = null;
Expand Down
6 changes: 0 additions & 6 deletions tests/Common/DataFixtures/TestEntity/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\Common\DataFixtures\TestValueObjects\Uuid;

/** @ORM\Entity */
#[ORM\Entity]
class Link
{
/**
* @ORM\Id
* @ORM\Column(type="uuid")
*/
#[ORM\Id]
#[ORM\Column(type: 'uuid')]
private Uuid $id;

/** @ORM\Column(length=150) */
#[ORM\Column(length: 150)]
private string|null $url = null;

Expand Down
17 changes: 0 additions & 17 deletions tests/Common/DataFixtures/TestEntity/Quoted.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,18 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table("`SELECT`")
*/
#[ORM\Entity]
#[ORM\Table(name: '`SELECT`')]
class Quoted
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Column]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private int|null $id = null;

/** @ORM\Column(length=50, name="select") */
#[ORM\Column(length: 50, name: '`SELECT`')]
private string|null $select = null;

/**
* @ORM\ManyToMany(targetEntity=Quoted::class)
* @ORM\JoinTable(name="`INSERT`",
* joinColumns={@ORM\JoinColumn(name="`SELECT`", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="`UPDATE`", referencedColumnName="id")}
* )
*/
#[ORM\ManyToMany(targetEntity: self::class)]
#[ORM\JoinTable(name: '`INSERT`')]
#[ORM\JoinColumn(name: '`SELECT`', referencedColumnName: 'id')]
Expand Down
7 changes: 0 additions & 7 deletions tests/Common/DataFixtures/TestEntity/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@

use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
#[ORM\Entity]
class Role
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Column]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private int|null $id = null;

/** @ORM\Column(length=50) */
#[ORM\Column(length: 50)]
private string|null $name = null;

Expand Down
28 changes: 2 additions & 26 deletions tests/Common/DataFixtures/TestEntity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,34 @@

use function md5;

/** @ORM\Entity */
#[ORM\Entity]
class User
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
*/
#[ORM\Column]
#[ORM\Id]
private int|null $id = null;

/**
* @ORM\Column(length=32)
* @ORM\Id
*/
#[ORM\Column(length: 32)]
#[ORM\Id]
private string|null $code = null;

/** @ORM\Column(length=32) */
#[ORM\Column(length: 32)]
private string|null $password = null;

/** @ORM\Column(length=255) */
#[ORM\Column(length: 255)]
private string|null $email = null;

/** @ORM\ManyToOne(targetEntity=Role::class, cascade={"persist"}) */
#[ORM\ManyToOne(cascade: ['persist'])]
private Role|null $role = null;

/**
* @ORM\ManyToMany(targetEntity=User::class, inversedBy="authors")
* @ORM\JoinTable(name="author_reader", schema="readers",
* joinColumns={@ORM\JoinColumn(name="author_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="reader_id", referencedColumnName="id")}
* )
*
* @var Collection<int, User>
*/
/** @var Collection<int, User> */
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'authors')]
#[ORM\JoinTable(name: 'author_reader', schema: 'readers')]
#[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'reader_id', referencedColumnName: 'id')]
private Collection $readers;

/**
* @ORM\ManyToMany(targetEntity=User::class, mappedBy="readers")
*
* @var Collection<int, User>
*/
/** @var Collection<int, User> */
#[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'readers')]
private Collection $authors;

Expand Down
31 changes: 2 additions & 29 deletions tests/Common/DataFixtures/TestEntity/UserWithSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,35 @@

use function md5;

/**
* @ORM\Entity
* @ORM\Table(name="user",schema="test_schema")
*/
#[ORM\Entity]
#[ORM\Table(name: 'user', schema: 'test_schema')]
class UserWithSchema
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
*/
#[ORM\Column]
#[ORM\Id]
private int|null $id = null;

/**
* @ORM\Column(length=32)
* @ORM\Id
*/
#[ORM\Column(length: 32)]
#[ORM\Id]
private string|null $code = null;

/** @ORM\Column(length=32) */
#[ORM\Column(length: 32)]
private string|null $password = null;

/** @ORM\Column(length=255) */
#[ORM\Column(length: 255)]
private string|null $email = null;

/** @ORM\ManyToOne(targetEntity=Role::class, cascade={"persist"}) */
#[ORM\ManyToOne(cascade: ['persist'])]
private Role|null $role = null;

/**
* @ORM\ManyToMany(targetEntity=UserWithSchema::class, inversedBy="authors")
* @ORM\JoinTable(name="author_reader", schema="readers",
* joinColumns={@ORM\JoinColumn(name="author_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="reader_id", referencedColumnName="id")}
* )
*
* @var Collection<int, self>
*/
/** @var Collection<int, self> */
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'authors')]
#[ORM\JoinTable(name: 'author_reader', schema: 'readers')]
#[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'reader_id', referencedColumnName: 'id')]
private Collection $readers;

/**
* @ORM\ManyToMany(targetEntity=UserWithSchema::class, mappedBy="readers")
*
* @var Collection<int, self>
*/
/** @var Collection<int, self> */
#[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'readers')]
private Collection $authors;

Expand Down
5 changes: 0 additions & 5 deletions tests/Common/DataFixtures/TestPurgeEntity/ExcludedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@

use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
#[ORM\Entity]
class ExcludedEntity
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
*/
#[ORM\Column]
#[ORM\Id]
private int|null $id = null;
Expand Down
5 changes: 0 additions & 5 deletions tests/Common/DataFixtures/TestPurgeEntity/IncludedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@

use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
#[ORM\Entity]
class IncludedEntity
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
*/
#[ORM\Column]
#[ORM\Id]
private int|null $id = null;
Expand Down

0 comments on commit 750e0d3

Please sign in to comment.