Skip to content

Commit

Permalink
Run tests with Doctrine Annotations 2
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Feb 5, 2024
1 parent 31702be commit 7951d81
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 61 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"doctrine/orm": "^2.15"
},
"require-dev": {
"doctrine/annotations": "^1.14",
"doctrine/annotations": "^1.14 || ^2",
"doctrine/cache": "^1.11",
"doctrine/coding-standard": "^9.0.2 || ^12.0",
"nesbot/carbon": "*",
Expand Down
10 changes: 6 additions & 4 deletions tests/Entities/Blank.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace DoctrineExtensions\Tests\Entities;

/** @Entity */
use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class Blank
{
/**
* @Id
* @Column(type="string")
* @GeneratedValue
* @ORM\Id
* @ORM\Column(type="string")
* @ORM\GeneratedValue
*/
public $id;
}
16 changes: 9 additions & 7 deletions tests/Entities/BlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

namespace DoctrineExtensions\Tests\Entities;

/** @Entity */
use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class BlogPost
{
/**
* @Id
* @Column(type="string")
* @GeneratedValue
* @ORM\Id
* @ORM\Column(type="string")
* @ORM\GeneratedValue
*/
public $id;

/** @Column(type="DateTime") */
/** @ORM\Column(type="DateTime") */
public $created;

/** @Column(type="decimal", precision=12, scale=8) */
/** @ORM\Column(type="decimal", precision=12, scale=8) */
public $longitude;

/** @Column(type="decimal", precision=12, scale=8) */
/** @ORM\Column(type="decimal", precision=12, scale=8) */
public $latitude;
}
27 changes: 13 additions & 14 deletions tests/Entities/CarbonDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,38 @@

namespace DoctrineExtensions\Tests\Entities;

/**
* @Entity
* @Table
*/
use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class CarbonDate
{
/**
* @Id
* @Column(type="integer")
* @ORM\Id
* @ORM\Column(type="integer")
*/
public $id;

/** @Column(type="CarbonDate", nullable=true) */
/** @ORM\Column(type="CarbonDate", nullable=true) */
public $date;

/** @Column(type="CarbonDateTime", nullable=true) */
/** @ORM\Column(type="CarbonDateTime", nullable=true) */
public $datetime;

/** @Column(type="CarbonDateTimeTz", nullable=true) */
/** @ORM\Column(type="CarbonDateTimeTz", nullable=true) */
public $datetimeTz;

/** @Column(type="CarbonTime", nullable=true) */
/** @ORM\Column(type="CarbonTime", nullable=true) */
public $time;

/** @Column(type="CarbonImmutableDate", nullable=true) */
/** @ORM\Column(type="CarbonImmutableDate", nullable=true) */
public $dateImmutable;

/** @Column(type="CarbonImmutableDateTime", nullable=true) */
/** @ORM\Column(type="CarbonImmutableDateTime", nullable=true) */
public $datetimeImmutable;

/** @Column(type="CarbonImmutableDateTimeTz", nullable=true) */
/** @ORM\Column(type="CarbonImmutableDateTimeTz", nullable=true) */
public $datetimeTzImmutable;

/** @Column(type="CarbonImmutableTime", nullable=true) */
/** @ORM\Column(type="CarbonImmutableTime", nullable=true) */
public $timeImmutable;
}
12 changes: 7 additions & 5 deletions tests/Entities/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

namespace DoctrineExtensions\Tests\Entities;

/** @Entity */
use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class Date
{
/**
* @Id
* @Column(type="string")
* @GeneratedValue
* @ORM\Id
* @ORM\Column(type="string")
* @ORM\GeneratedValue
*/
public $id;

/** @Column(type="datetime") */
/** @ORM\Column(type="datetime") */
public $created;
}
18 changes: 10 additions & 8 deletions tests/Entities/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@

namespace DoctrineExtensions\Tests\Entities;

/** @Entity */
use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class Product
{
/**
* @Id
* @Column(type="string")
* @GeneratedValue
* @ORM\Id
* @ORM\Column(type="string")
* @ORM\GeneratedValue
*/
public $id;

/** @Column(type="string") */
/** @ORM\Column(type="string") */
public $name;

/** @Column(type="DateTime") */
/** @ORM\Column(type="DateTime") */
public $created;

/** @Column(type="decimal", precision=10, scale=2) */
/** @ORM\Column(type="decimal", precision=10, scale=2) */
public $price;

/** @Column(type="decimal", precision=5, scale=2) */
/** @ORM\Column(type="decimal", precision=5, scale=2) */
public $weight;
}
12 changes: 7 additions & 5 deletions tests/Entities/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

namespace DoctrineExtensions\Tests\Entities;

/** @Entity */
use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class Set
{
/**
* @Id
* @Column(type="string")
* @GeneratedValue
* @ORM\Id
* @ORM\Column(type="string")
* @ORM\GeneratedValue
*/
public $id;

/** @Column(type="String") */
/** @ORM\Column(type="String") */
public $set;
}
13 changes: 6 additions & 7 deletions tests/Entities/ZendDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

namespace DoctrineExtensions\Tests\Entities;

/**
* @Entity
* @Table
*/
use Doctrine\ORM\Mapping as ORM;

/** @ORM\Entity */
class ZendDate
{
/**
* @Id
* @Column(type="integer")
* @ORM\Id
* @ORM\Column(type="integer")
*/
public $id;

/** @Column(type="ZendDate") */
/** @ORM\Column(type="ZendDate") */
public $date;

public function __construct($id, $date)
Expand Down
9 changes: 7 additions & 2 deletions tests/Query/DbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace DoctrineExtensions\Tests\Query;

use Doctrine\Common\Cache\ArrayCache;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
use PHPUnit\Framework\TestCase;

class DbTestCase extends TestCase
Expand All @@ -23,8 +25,11 @@ public function setUp(): void
$this->configuration->setProxyDir(__DIR__ . '/Proxies');
$this->configuration->setProxyNamespace('DoctrineExtensions\Tests\Proxies');
$this->configuration->setAutoGenerateProxyClasses(true);
$this->configuration->setMetadataDriverImpl($this->configuration->newDefaultAnnotationDriver(__DIR__ . '/../Entities'));
$this->entityManager = EntityManager::create(['driver' => 'pdo_sqlite', 'memory' => true], $this->configuration);
$this->configuration->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver([__DIR__ . '/../Entities']));
$this->entityManager = new EntityManager(
DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true], $this->configuration),
$this->configuration
);
}

public function assertDqlProducesSql($actualDql, $expectedSql, $params = []): void
Expand Down
10 changes: 6 additions & 4 deletions tests/Types/CarbonDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Tools\SchemaTool;
use DoctrineExtensions\Tests\Entities\CarbonDate as Entity;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -44,13 +46,13 @@ public function setUp(): void
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('DoctrineExtensions\Tests\PHPUnit\Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(__DIR__ . '/../../Entities'));
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver([__DIR__ . '/../../Entities']));

$this->em = EntityManager::create(
[
$this->em = new EntityManager(
DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'memory' => true,
],
], $config),
$config
);

Expand Down
10 changes: 6 additions & 4 deletions tests/Types/ZendDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace DoctrineExtensions\Tests\Types;

use Doctrine\Common\Cache\ArrayCache;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Tools\SchemaTool;
use DoctrineExtensions\Tests\Entities\ZendDate;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -39,13 +41,13 @@ public function setUp(): void
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('DoctrineExtensions\Tests\PHPUnit\Proxies');
$config->setAutoGenerateProxyClasses(true);
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(__DIR__ . '/../../Entities'));
$config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver([__DIR__ . '/../../Entities']));

$this->em = EntityManager::create(
[
$this->em = new EntityManager(
DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'memory' => true,
],
], $config),
$config
);

Expand Down

0 comments on commit 7951d81

Please sign in to comment.