Completed
Push — EZP-30461 ( f31212 )
by
unknown
50:37 queued 24:12
created

FieldValueConverterRegistryTest::testHasStorage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\FieldValueConverterRegistryTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content;
10
11
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
12
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry as Registry;
13
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
14
15
/**
16
 * Test case for FieldValue Converter Registry.
17
 */
18
class FieldValueConverterRegistryTest extends TestCase
19
{
20
    /**
21
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry::register
22
     */
23
    public function testRegister(): void
24
    {
25
        $converter = $this->getFieldValueConverterMock();
26
        $registry = new Registry(array('some-type' => $converter));
27
28
        $this->assertAttributeSame(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertAttributeSame() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3338

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
29
            array(
30
                'some-type' => $converter,
31
            ),
32
            'converterMap',
33
            $registry
34
        );
35
    }
36
37
    /**
38
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry::getConverter
39
     */
40
    public function testGetStorage(): void
41
    {
42
        $converter = $this->getFieldValueConverterMock();
43
        $registry = new Registry(array('some-type' => $converter));
44
45
        $res = $registry->getConverter('some-type');
46
47
        $this->assertSame(
48
            $converter,
49
            $res
50
        );
51
    }
52
53
    /**
54
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry::getConverter
55
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound
56
     * @expectedException \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\Exception\NotFound
57
     */
58
    public function testGetNotFound(): void
59
    {
60
        $registry = new Registry(array());
61
62
        $registry->getConverter('not-found');
63
    }
64
65
    /**
66
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry::hasConverter
67
     */
68 View Code Duplication
    public function testHasStorage(): void
69
    {
70
        $converter = $this->getFieldValueConverterMock();
71
        $registry = new Registry(array('some-type' => $converter));
72
73
        $this->assertTrue(
74
            $registry->hasConverter('some-type')
75
        );
76
    }
77
78
    /**
79
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry::hasConverter
80
     */
81 View Code Duplication
    public function testHasNoStorage(): void
82
    {
83
        $converter = $this->getFieldValueConverterMock();
84
        $registry = new Registry(array('some-type' => $converter));
85
86
        $this->assertFalse(
87
            $registry->hasConverter('some-other-type')
88
        );
89
    }
90
91
    /**
92
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter|\PHPUnit\Framework\MockObject\MockObject
93
     */
94
    protected function getFieldValueConverterMock()
95
    {
96
        return $this->createMock(Converter::class);
97
    }
98
}
99