Completed
Push — master ( 7d9afb...4e0ac6 )
by Łukasz
49:46 queued 21:48
created

MapperTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testExtractNotificationsFromRows() 0 50 1
A testExtractNotificationsFromRowsThrowsRuntimeException() 0 15 1
A testCreateNotificationFromUpdateStruct() 0 10 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Notification;
10
11
use eZ\Publish\Core\Persistence\Legacy\Notification\Mapper;
12
use eZ\Publish\SPI\Persistence\Notification\Notification;
13
use eZ\Publish\SPI\Persistence\Notification\UpdateStruct;
14
use PHPUnit\Framework\TestCase;
15
16
class MapperTest extends TestCase
17
{
18
    /** @var \eZ\Publish\Core\Persistence\Legacy\Notification\Mapper */
19
    private $mapper;
20
21
    protected function setUp()
22
    {
23
        $this->mapper = new Mapper();
24
    }
25
26
    /**
27
     * @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Mapper::extractNotificationsFromRows
28
     */
29
    public function testExtractNotificationsFromRows()
30
    {
31
        $rows = [
32
            [
33
                'id' => 1,
34
                'owner_id' => 5,
35
                'type' => 'FOO',
36
                'created' => 1529913161,
37
                'is_pending' => 0,
38
                'data' => null,
39
            ],
40
            [
41
                'id' => 1,
42
                'owner_id' => 5,
43
                'type' => 'BAR',
44
                'created' => 1529910161,
45
                'is_pending' => 1,
46
                'data' => json_encode([
47
                    'foo' => 'Foo',
48
                    'bar' => 'Bar',
49
                    'baz' => ['B', 'A', 'Z'],
50
                ]),
51
            ],
52
        ];
53
54
        $objects = [
55
            new Notification([
56
                'id' => 1,
57
                'ownerId' => 5,
58
                'type' => 'FOO',
59
                'created' => 1529913161,
60
                'isPending' => false,
61
                'data' => [],
62
            ]),
63
            new Notification([
64
                'id' => 1,
65
                'ownerId' => 5,
66
                'type' => 'BAR',
67
                'created' => 1529910161,
68
                'isPending' => true,
69
                'data' => [
70
                    'foo' => 'Foo',
71
                    'bar' => 'Bar',
72
                    'baz' => ['B', 'A', 'Z'],
73
                ],
74
            ]),
75
        ];
76
77
        $this->assertEquals($objects, $this->mapper->extractNotificationsFromRows($rows));
78
    }
79
80
    /**
81
     * @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Mapper::extractNotificationsFromRows
82
     * @expectedException \RuntimeException
83
     */
84
    public function testExtractNotificationsFromRowsThrowsRuntimeException()
85
    {
86
        $rows = [
87
            [
88
                'id' => 1,
89
                'owner_id' => 5,
90
                'type' => 'FOO',
91
                'created' => 1529913161,
92
                'is_pending' => false,
93
                'data' => '{ InvalidJSON }',
94
            ],
95
        ];
96
97
        $this->mapper->extractNotificationsFromRows($rows);
98
    }
99
100
    /**
101
     * @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Mapper::createNotificationFromUpdateStruct
102
     */
103
    public function testCreateNotificationFromUpdateStruct()
104
    {
105
        $updateStruct = new UpdateStruct([
106
            'isPending' => false,
107
        ]);
108
109
        $this->assertEquals(new Notification([
110
            'isPending' => false,
111
        ]), $this->mapper->createNotificationFromUpdateStruct($updateStruct));
112
    }
113
}
114