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\Test\Entity; |
9
|
|
|
|
10
|
|
|
use Doctrine\Instantiator\Instantiator; |
11
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
12
|
|
|
use Ramsey\Uuid\Uuid; |
13
|
|
|
use Thorr\Persistence\Entity\AbstractEntity; |
14
|
|
|
use Thorr\Persistence\Test\Asset\TestEntity; |
15
|
|
|
|
16
|
|
|
class AbstractEntityTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
public function testUuid() |
19
|
|
|
{ |
20
|
|
|
$uuid = Uuid::uuid4(); |
21
|
|
|
|
22
|
|
|
/** @var AbstractEntity $entity */ |
23
|
|
|
$entity = $this->getMockForAbstractClass(AbstractEntity::class, [ $uuid ]); |
24
|
|
|
|
25
|
|
|
$this->assertEquals($uuid, $entity->getUuid()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testUuidIsAutomaticallyGenerated() |
29
|
|
|
{ |
30
|
|
|
/** @var AbstractEntity $entity */ |
31
|
|
|
$entity = $this->getMockForAbstractClass(AbstractEntity::class); |
32
|
|
|
|
33
|
|
|
$this->assertNotEmpty($entity->getUuid()); |
34
|
|
|
$this->assertTrue(Uuid::isValid($entity->getUuid())); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testUuidFromString() |
38
|
|
|
{ |
39
|
|
|
$uuid = Uuid::uuid4()->toString(); |
40
|
|
|
|
41
|
|
|
/** @var AbstractEntity $entity */ |
42
|
|
|
$entity = $this->getMockForAbstractClass(AbstractEntity::class, [ $uuid ]); |
43
|
|
|
|
44
|
|
|
$this->assertSame($uuid, $entity->getUuid()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testCloningChangesUuid() |
48
|
|
|
{ |
49
|
|
|
$entity = new TestEntity(); |
50
|
|
|
|
51
|
|
|
$clone = clone $entity; |
52
|
|
|
$this->assertNotEquals($entity->getUuid(), $clone->getUuid()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testCloningDoesntRefreshUuidIfWasntSet() |
56
|
|
|
{ |
57
|
|
|
$instantiator = new Instantiator(); |
58
|
|
|
/** @var TestEntity $entity */ |
59
|
|
|
$entity = $instantiator->instantiate(TestEntity::class); |
60
|
|
|
$this->assertNull($entity->getUuid()); |
61
|
|
|
$clone = clone $entity; |
62
|
|
|
$this->assertNull($clone->getUuid()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|