Passed
Pull Request — master (#10)
by Anatoly
02:53
created

EntrySerializerTest::testSerializeUpdatedObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.7998
1
<?php declare(strict_types=1);
2
3
namespace App\Bundle\Example\Tests\Service;
4
5
/**
6
 * Import classes
7
 */
8
use App\Bundle\Example\Entity\Entry;
9
use App\Tests\ContainerAwareTrait;
10
use PHPUnit\Framework\TestCase;
11
use DateTime;
12
13
/**
14
 * EntrySerializerTest
15
 */
16
class EntrySerializerTest extends TestCase
17
{
18
    use ContainerAwareTrait;
19
20
    /**
21
     * @return void
22
     *
23
     * @runInSeparateProcess
24
     */
25
    public function testSerializeEmptyObject() : void
26
    {
27
        $container = $this->getContainer();
28
        $entrySerializer = $container->get('entrySerializer');
29
30
        $foo = new Entry();
31
        $this->assertSame([
32
            'id' => $foo->getId()->toString(),
33
            'name' => '',
34
            'slug' => '',
35
            'createdAt' => null,
36
            'updatedAt' => null,
37
        ], $entrySerializer->serialize($foo));
38
    }
39
40
    /**
41
     * @return void
42
     *
43
     * @runInSeparateProcess
44
     */
45
    public function testSerializeNewObject() : void
46
    {
47
        $container = $this->getContainer();
48
        $entrySerializer = $container->get('entrySerializer');
49
50
        $foo = new Entry();
51
        $foo->setName('foo');
52
        $foo->setSlug('bar');
53
        $foo->prePersist();
54
        $this->assertSame([
55
            'id' => $foo->getId()->toString(),
56
            'name' => 'foo',
57
            'slug' => 'bar',
58
            'createdAt' => $foo->getCreatedAt()->format(DateTime::W3C),
59
            'updatedAt' => null,
60
        ], $entrySerializer->serialize($foo));
61
    }
62
63
    /**
64
     * @return void
65
     *
66
     * @runInSeparateProcess
67
     */
68
    public function testSerializeUpdatedObject() : void
69
    {
70
        $container = $this->getContainer();
71
        $entrySerializer = $container->get('entrySerializer');
72
73
        $foo = new Entry();
74
        $foo->setName('foo');
75
        $foo->setSlug('bar');
76
        $foo->prePersist();
77
        $foo->preUpdate();
78
        $this->assertSame([
79
            'id' => $foo->getId()->toString(),
80
            'name' => 'foo',
81
            'slug' => 'bar',
82
            'createdAt' => $foo->getCreatedAt()->format(DateTime::W3C),
83
            'updatedAt' => $foo->getUpdatedAt()->format(DateTime::W3C),
84
        ], $entrySerializer->serialize($foo));
85
    }
86
87
    /**
88
     * @return void
89
     *
90
     * @runInSeparateProcess
91
     */
92
    public function testSerializeList() : void
93
    {
94
        $container = $this->getContainer();
95
        $entrySerializer = $container->get('entrySerializer');
96
97
        $foo = new Entry();
98
        $foo->setName('foo');
99
        $foo->setSlug('bar');
100
101
        $bar = new Entry();
102
        $bar->setName('baz');
103
        $bar->setSlug('qux');
104
105
        $this->assertSame([
106
            [
107
                'id' => $foo->getId()->toString(),
108
                'name' => 'foo',
109
                'slug' => 'bar',
110
                'createdAt' => null,
111
                'updatedAt' => null,
112
            ],
113
            [
114
                'id' => $bar->getId()->toString(),
115
                'name' => 'baz',
116
                'slug' => 'qux',
117
                'createdAt' => null,
118
                'updatedAt' => null,
119
            ],
120
        ], $entrySerializer->serializeList($foo, $bar));
121
    }
122
}
123