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