Completed
Push — develop ( 81716f )
by Stefano
16:01
created

AbstractEntityTest::testCloningChangesUuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
c 1
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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