1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Stefano Torresi (http://stefanotorresi.it) |
4
|
|
|
* @license See the file LICENSE.txt for copying permission. |
5
|
|
|
* ************************************************ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Thorr\Persistence\Doctrine\Test\Integration; |
9
|
|
|
|
10
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; |
11
|
|
|
use Doctrine\ORM\EntityManager; |
12
|
|
|
use Doctrine\ORM\Mapping\Driver\XmlDriver; |
13
|
|
|
use Doctrine\ORM\Tools\SchemaTool; |
14
|
|
|
use Doctrine\ORM\Tools\Setup; |
15
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
16
|
|
|
use Ramsey\Uuid\Uuid; |
17
|
|
|
use Thorr\Persistence\Doctrine\DataMapper\DoctrineAdapter; |
18
|
|
|
use Thorr\Persistence\Entity\AbstractEntity; |
19
|
|
|
|
20
|
|
|
class ORMIntegrationTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var DoctrineAdapter |
24
|
|
|
*/ |
25
|
|
|
protected $adapter; |
26
|
|
|
|
27
|
|
|
public function setUp() |
28
|
|
|
{ |
29
|
|
|
$conn = [ |
30
|
|
|
'driver' => 'pdo_sqlite', |
31
|
|
|
'memory' => true, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
$driver = new MappingDriverChain(); |
35
|
|
|
$driver->addDriver(new XmlDriver('config'), AbstractEntity::class); |
36
|
|
|
$driver->addDriver(new XmlDriver(__DIR__ . '/Asset'), Asset\Entity::class); |
37
|
|
|
|
38
|
|
|
$config = Setup::createConfiguration(true); |
39
|
|
|
$config->setMetadataDriverImpl($driver); |
40
|
|
|
|
41
|
|
|
$entityManager = EntityManager::create($conn, $config); |
42
|
|
|
|
43
|
|
|
$classes = $entityManager->getMetadataFactory()->getAllMetadata(); |
44
|
|
|
$schemaTool = new SchemaTool($entityManager); |
45
|
|
|
$schemaTool->dropDatabase(); |
46
|
|
|
$schemaTool->createSchema($classes); |
47
|
|
|
|
48
|
|
|
$this->adapter = new DoctrineAdapter(Asset\Entity::class, $entityManager); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testUuidIntegration() |
52
|
|
|
{ |
53
|
|
|
$entity = new Asset\Entity(); |
54
|
|
|
$uuid = $entity->getUuid(); |
55
|
|
|
|
56
|
|
|
$this->adapter->save($entity); |
57
|
|
|
|
58
|
|
|
$this->assertSame($uuid, $entity->getUuid()); |
59
|
|
|
|
60
|
|
|
$this->assertSame( |
61
|
|
|
$entity, |
62
|
|
|
$this->adapter->findByUuid($uuid), |
63
|
|
|
sprintf('Failed to find an entity with uuid %s', $uuid) |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->assertSame( |
67
|
|
|
$entity, |
68
|
|
|
$this->adapter->findByUuid(Uuid::fromString($uuid)), |
|
|
|
|
69
|
|
|
'Failed to find an entity with uuid object' |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$this->adapter->removeByUuid($uuid); |
73
|
|
|
|
74
|
|
|
$this->assertNull($this->adapter->findByUuid($uuid)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testSaveDeferred() |
78
|
|
|
{ |
79
|
|
|
$entity = new Asset\Entity(); |
80
|
|
|
|
81
|
|
|
$this->adapter->saveDeferred($entity); |
82
|
|
|
$this->assertNull($this->adapter->findByUuid($entity->getUuid())); |
83
|
|
|
|
84
|
|
|
$this->adapter->commit(); |
85
|
|
|
$this->assertSame($entity, $this->adapter->findByUuid($entity->getUuid())); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testRemoveDeferred() |
89
|
|
|
{ |
90
|
|
|
$entity = new Asset\Entity(); |
91
|
|
|
$this->adapter->save($entity); |
92
|
|
|
|
93
|
|
|
$this->adapter->removeDeferred($entity); |
94
|
|
|
$this->assertEquals($entity, $this->adapter->findByUuid($entity->getUuid())); |
95
|
|
|
|
96
|
|
|
$this->adapter->commit(); |
97
|
|
|
$this->assertNull($this->adapter->findByUuid($entity->getUuid())); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: