1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace App\Bundle\Example\Tests\Entity; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Import classes |
7
|
|
|
*/ |
8
|
|
|
use App\Bundle\Example\Entity\Entry; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use Ramsey\Uuid\UuidInterface; |
11
|
|
|
use DateTimeInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* EntryTest |
15
|
|
|
*/ |
16
|
|
|
class EntryTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
|
public function testConstructor() : void |
23
|
|
|
{ |
24
|
|
|
$entry = new Entry(); |
25
|
|
|
$this->assertInstanceOf(UuidInterface::class, $entry->getId()); |
26
|
|
|
$this->assertSame('', $entry->getName()); |
27
|
|
|
$this->assertSame('', $entry->getSlug()); |
28
|
|
|
$this->assertNull($entry->getCreatedAt()); |
29
|
|
|
$this->assertNull($entry->getUpdatedAt()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function testName() : void |
36
|
|
|
{ |
37
|
|
|
$entry = new Entry(); |
38
|
|
|
$this->assertSame('', $entry->getName()); |
39
|
|
|
$entry->setName('foo'); |
40
|
|
|
$this->assertSame('foo', $entry->getName()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
public function testSlug() : void |
47
|
|
|
{ |
48
|
|
|
$entry = new Entry(); |
49
|
|
|
$this->assertSame('', $entry->getSlug()); |
50
|
|
|
$entry->setSlug('foo'); |
51
|
|
|
$this->assertSame('foo', $entry->getSlug()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
public function testEvents() : void |
58
|
|
|
{ |
59
|
|
|
$entry = new Entry(); |
60
|
|
|
$this->assertNull($entry->getCreatedAt()); |
61
|
|
|
$this->assertNull($entry->getUpdatedAt()); |
62
|
|
|
|
63
|
|
|
$entry = new Entry(); |
64
|
|
|
$entry->prePersist(); |
65
|
|
|
$this->assertInstanceOf(DateTimeInterface::class, $entry->getCreatedAt()); |
66
|
|
|
$this->assertNull($entry->getUpdatedAt()); |
67
|
|
|
|
68
|
|
|
$entry = new Entry(); |
69
|
|
|
$entry->preUpdate(); |
70
|
|
|
$this->assertNull($entry->getCreatedAt()); |
71
|
|
|
$this->assertInstanceOf(DateTimeInterface::class, $entry->getUpdatedAt()); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|