Skip to content

Commit

Permalink
Add tests for interacting with Attribute driver (#36)
Browse files Browse the repository at this point in the history
No logic changes, but this helps verify there are no weird behaviors
when using the attribute driver.
  • Loading branch information
Firehed committed Jul 17, 2023
1 parent 9bfca30 commit bfca1d2
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
29 changes: 29 additions & 0 deletions tests/AttributeDriverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Firehed\Mocktrine;

use Doctrine\ORM\{
EntityManagerInterface,
Mapping,
};

/**
* @covers Firehed\Mocktrine\InMemoryEntityManager
*/
class AttributeDriverTest extends InMemoryEntityManagerTest
{
public function setUp(): void
{
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
$this->markTestSkipped('Attribute tests require PHP8+');
}
}

protected function getEntityManager(): InMemoryEntityManager
{
$driver = new Mapping\Driver\AttributeDriver([__DIR__ . '/Entities']);
return new InMemoryEntityManager($driver);
}
}
9 changes: 9 additions & 0 deletions tests/Entities/GrabBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions tests/Entities/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

namespace Firehed\Mocktrine\Entities;

use Doctrine\ORM\Mapping;

/**
* @Entity
* @Table(name="groups")
*/
#[Mapping\Entity]
#[Mapping\Table(name: 'groups')]
class Group
{
}
6 changes: 6 additions & 0 deletions tests/Entities/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@

namespace Firehed\Mocktrine\Entities;

use Doctrine\ORM\Mapping;

/**
* @Entity
* @Table(name="nodes")
*/
#[Mapping\Entity]
#[Mapping\Table(name: 'nodes')]
class Node
{
/**
* @Id
* @Column
* @var string
*/
#[Mapping\Id]
#[Mapping\Column]
private $nodeId;

public function __construct()
Expand Down
7 changes: 7 additions & 0 deletions tests/Entities/StringId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand All @@ -16,6 +20,9 @@ class StringId
* @GeneratedValue
* @var ?string
*/
#[Mapping\Id]
#[Mapping\Column]
#[Mapping\GeneratedValue]
private $id;

public function getId(): ?string
Expand Down
7 changes: 7 additions & 0 deletions tests/Entities/UnspecifiedId.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand All @@ -16,6 +20,9 @@ class UnspecifiedId
* @GeneratedValue
* @var ?string
*/
#[Mapping\Id]
#[Mapping\Column]
#[Mapping\GeneratedValue]
private $id;

public function getId(): ?string
Expand Down
11 changes: 11 additions & 0 deletions tests/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand All @@ -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;

/**
Expand Down

0 comments on commit bfca1d2

Please sign in to comment.