Skip to content

Commit

Permalink
Improve doctrine annotations to attributes (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Mar 20, 2023
1 parent cea96d6 commit 8eb99a2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 50 deletions.
9 changes: 4 additions & 5 deletions composer.json
Expand Up @@ -25,10 +25,9 @@
"php": "^8.0"
},
"require-dev": {
"doctrine/annotations": "^1.13 || ^2.0",
"doctrine/dbal": "^3.1",
"doctrine/mongodb-odm": "^2.0",
"doctrine/orm": "^2.9",
"doctrine/mongodb-odm": "^2.3",
"doctrine/orm": "^2.14",
"friendsofphp/php-cs-fixer": "^3.4",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
Expand All @@ -52,8 +51,8 @@
"vimeo/psalm": "^4.9.2"
},
"conflict": {
"doctrine/mongodb-odm": "<2.0",
"doctrine/orm": "<2.8",
"doctrine/mongodb-odm": "<2.3",
"doctrine/orm": "<2.14",
"phpoffice/phpspreadsheet": "<1.23",
"symfony/config": "<5.4"
},
Expand Down
3 changes: 2 additions & 1 deletion tests/Source/DoctrineODMQuerySourceIteratorTest.php
Expand Up @@ -15,6 +15,7 @@

use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
use PHPUnit\Framework\TestCase;
use Sonata\Exporter\Source\DoctrineODMQuerySourceIterator;
use Sonata\Exporter\Tests\Source\Fixtures\Document;
Expand Down Expand Up @@ -94,7 +95,7 @@ private function createConfiguration(): Configuration
$config->setHydratorNamespace('Hydrators');
$config->setPersistentCollectionDir($directory);
$config->setPersistentCollectionNamespace('PersistentCollections');
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
$config->setMetadataDriverImpl(new AttributeDriver());

return $config;
}
Expand Down
29 changes: 5 additions & 24 deletions tests/Source/DoctrineORMQuerySourceIteratorTest.php
Expand Up @@ -13,14 +13,11 @@

namespace Sonata\Exporter\Tests\Source;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use PHPUnit\Framework\TestCase;
use Sonata\Exporter\Source\DoctrineORMQuerySourceIterator;
use Sonata\Exporter\Tests\Source\Fixtures\Entity;
Expand All @@ -35,8 +32,10 @@ protected function setUp(): void
static::markTestSkipped('The sqlite extension is not available.');
}

/** @psalm-suppress DeprecatedMethod */
$this->em = EntityManager::create($this->createConnection(), $this->createConfiguration());
$this->em = new EntityManager(
$this->createConnection(),
ORMSetup::createAttributeMetadataConfiguration([], true),
);

$schemaTool = new SchemaTool($this->em);
$schemaTool->dropDatabase();
Expand Down Expand Up @@ -83,22 +82,4 @@ private function createConnection(): Connection
{
return new Connection([], new Driver\PDO\SQLite\Driver());
}

private function createConfiguration(): Configuration
{
$config = new Configuration();

$directory = sys_get_temp_dir().'/sqlite';

$config->setProxyDir($directory);
$config->setProxyNamespace('Proxies');
$config->setMetadataDriverImpl($this->createMetadataDriverImplementation());

return $config;
}

private function createMetadataDriverImplementation(): MappingDriver
{
return new AnnotationDriver(new AnnotationReader());
}
}
12 changes: 3 additions & 9 deletions tests/Source/Fixtures/Document.php
Expand Up @@ -15,15 +15,9 @@

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

/**
* @ODM\Document
*/
#[ODM\Document]
class Document
{
/**
* @ODM\Id
*
* @var string|null
*/
public $id;
#[ODM\Id]
public ?string $id = null;
}
17 changes: 6 additions & 11 deletions tests/Source/Fixtures/Entity.php
Expand Up @@ -13,19 +13,14 @@

namespace Sonata\Exporter\Tests\Source\Fixtures;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
#[ORM\Entity]
class Entity
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @var int|null
*/
public $id;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
public ?int $id = null;
}

0 comments on commit 8eb99a2

Please sign in to comment.