From bfca1d2825faf552ef9b449cec373a7e408bad0e Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Mon, 17 Jul 2023 10:52:46 -0700 Subject: [PATCH] Add tests for interacting with Attribute driver (#36) No logic changes, but this helps verify there are no weird behaviors when using the attribute driver. --- composer.json | 2 +- tests/AttributeDriverTest.php | 29 +++++++++++++++++++++++++++++ tests/Entities/GrabBag.php | 9 +++++++++ tests/Entities/Group.php | 4 ++++ tests/Entities/Node.php | 6 ++++++ tests/Entities/StringId.php | 7 +++++++ tests/Entities/UnspecifiedId.php | 7 +++++++ tests/Entities/User.php | 11 +++++++++++ 8 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/AttributeDriverTest.php diff --git a/composer.json b/composer.json index cf28b73..19db2bc 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "php": "^7.4 || ^8.0", "doctrine/annotations": "^1.10", "doctrine/collections": "^1.6", - "doctrine/orm": "^2.7", + "doctrine/orm": "^2.9", "doctrine/persistence": "^1.3 || ^2.0", "symfony/polyfill-php80": "^1.20" }, diff --git a/tests/AttributeDriverTest.php b/tests/AttributeDriverTest.php new file mode 100644 index 0000000..7d1645d --- /dev/null +++ b/tests/AttributeDriverTest.php @@ -0,0 +1,29 @@ +markTestSkipped('Attribute tests require PHP8+'); + } + } + + protected function getEntityManager(): InMemoryEntityManager + { + $driver = new Mapping\Driver\AttributeDriver([__DIR__ . '/Entities']); + return new InMemoryEntityManager($driver); + } +} diff --git a/tests/Entities/GrabBag.php b/tests/Entities/GrabBag.php index 9652510..2741645 100644 --- a/tests/Entities/GrabBag.php +++ b/tests/Entities/GrabBag.php @@ -5,37 +5,46 @@ namespace Firehed\Mocktrine\Entities; use DateTimeInterface; +use Doctrine\ORM\Mapping; /** * @Entity * @Table(name="grab_bags") */ +#[Mapping\Entity] +#[Mapping\Table(name: 'grab_bags')] class GrabBag { /** * @Id * @Column */ + #[Mapping\Id] + #[Mapping\Column] private int $id; /** * @Column(name="bool_field", type="boolean") */ + #[Mapping\Column] private bool $boolField; /** * @Column(name="float_field", type="float") */ + #[Mapping\Column] private float $floatField; /** * @Column(name="str_field") */ + #[Mapping\Column] private string $strField; /** * @Column(name="date_field", type="date") */ + #[Mapping\Column] private DateTimeInterface $dateField; public function __construct( diff --git a/tests/Entities/Group.php b/tests/Entities/Group.php index e365db5..4c5e37f 100644 --- a/tests/Entities/Group.php +++ b/tests/Entities/Group.php @@ -4,10 +4,14 @@ namespace Firehed\Mocktrine\Entities; +use Doctrine\ORM\Mapping; + /** * @Entity * @Table(name="groups") */ +#[Mapping\Entity] +#[Mapping\Table(name: 'groups')] class Group { } diff --git a/tests/Entities/Node.php b/tests/Entities/Node.php index 9e40f11..b0a46f8 100644 --- a/tests/Entities/Node.php +++ b/tests/Entities/Node.php @@ -4,10 +4,14 @@ namespace Firehed\Mocktrine\Entities; +use Doctrine\ORM\Mapping; + /** * @Entity * @Table(name="nodes") */ +#[Mapping\Entity] +#[Mapping\Table(name: 'nodes')] class Node { /** @@ -15,6 +19,8 @@ class Node * @Column * @var string */ + #[Mapping\Id] + #[Mapping\Column] private $nodeId; public function __construct() diff --git a/tests/Entities/StringId.php b/tests/Entities/StringId.php index efadd34..51eae98 100644 --- a/tests/Entities/StringId.php +++ b/tests/Entities/StringId.php @@ -4,10 +4,14 @@ namespace Firehed\Mocktrine\Entities; +use Doctrine\ORM\Mapping; + /** * @Entity * @Table(name="string_ids") */ +#[Mapping\Entity] +#[Mapping\Table(name: 'string_ids')] class StringId { /** @@ -16,6 +20,9 @@ class StringId * @GeneratedValue * @var ?string */ + #[Mapping\Id] + #[Mapping\Column] + #[Mapping\GeneratedValue] private $id; public function getId(): ?string diff --git a/tests/Entities/UnspecifiedId.php b/tests/Entities/UnspecifiedId.php index 62c8e35..141a26d 100644 --- a/tests/Entities/UnspecifiedId.php +++ b/tests/Entities/UnspecifiedId.php @@ -4,10 +4,14 @@ namespace Firehed\Mocktrine\Entities; +use Doctrine\ORM\Mapping; + /** * @Entity * @Table(name="unspecified_ids") */ +#[Mapping\Entity] +#[Mapping\Table(name: 'unspecified_ids')] class UnspecifiedId { /** @@ -16,6 +20,9 @@ class UnspecifiedId * @GeneratedValue * @var ?string */ + #[Mapping\Id] + #[Mapping\Column] + #[Mapping\GeneratedValue] private $id; public function getId(): ?string diff --git a/tests/Entities/User.php b/tests/Entities/User.php index 5ebd7fc..c30d68a 100644 --- a/tests/Entities/User.php +++ b/tests/Entities/User.php @@ -4,10 +4,15 @@ namespace Firehed\Mocktrine\Entities; +use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\Mapping; + /** * @Entity * @Table(name="users") */ +#[Mapping\Entity] +#[Mapping\Table(name: 'users')] class User { /** @@ -16,24 +21,30 @@ class User * @GeneratedValue * @var ?int */ + #[Mapping\Id] + #[Mapping\Column(type: Types::INTEGER)] + #[Mapping\GeneratedValue] private $id; /** * @Column * @var string */ + #[Mapping\Column] private $email; /** * @Column(type="boolean") * @var bool */ + #[Mapping\Column(type: Types::BOOLEAN)] private $active = false; /** * @Column(name="last_name") * @var string */ + #[Mapping\Column] private $lastName; /**