Completed
Push — master ( 336c64...8fa798 )
by Łukasz
25:31
created

MapperTest::testCreateBookmarkFromCreateStruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
rs 9.4285
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\Bookmark;
10
11
use eZ\Publish\Core\Persistence\Legacy\Bookmark\Mapper;
12
use eZ\Publish\SPI\Persistence\Bookmark\Bookmark;
13
use eZ\Publish\SPI\Persistence\Bookmark\CreateStruct;
14
use PHPUnit\Framework\TestCase;
15
16
class MapperTest extends TestCase
17
{
18
    /** @var \eZ\Publish\Core\Persistence\Legacy\Bookmark\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\Bookmark\Mapper::createBookmarkFromCreateStruct
28
     */
29
    public function testCreateBookmarkFromCreateStruct()
30
    {
31
        $createStruct = new CreateStruct([
32
            'name' => 'Contact',
33
            'locationId' => 54,
34
            'userId' => 87,
35
        ]);
36
37
        $this->assertEquals(new Bookmark([
38
            'name' => 'Contact',
39
            'locationId' => 54,
40
            'userId' => 87,
41
        ]), $this->mapper->createBookmarkFromCreateStruct($createStruct));
42
    }
43
44
    /**
45
     * @covers \eZ\Publish\Core\Persistence\Legacy\Bookmark\Mapper::extractBookmarksFromRows
46
     */
47
    public function testExtractBookmarksFromRows()
48
    {
49
        $rows = [
50
            [
51
                'id' => '12',
52
                'name' => 'Home',
53
                'node_id' => '2',
54
                'user_id' => '78',
55
            ],
56
            [
57
                'id' => '75',
58
                'name' => 'Contact',
59
                'node_id' => '54',
60
                'user_id' => '87',
61
            ],
62
        ];
63
64
        $objects = [
65
            new Bookmark([
66
                'id' => 12,
67
                'name' => 'Home',
68
                'locationId' => 2,
69
                'userId' => 78,
70
            ]),
71
            new Bookmark([
72
                'id' => 75,
73
                'name' => 'Contact',
74
                'locationId' => 54,
75
                'userId' => 87,
76
            ]),
77
        ];
78
79
        $this->assertEquals($objects, $this->mapper->extractBookmarksFromRows($rows));
80
    }
81
}
82