Completed
Push — ezp25376-fields_groups ( 240dba...3c499d )
by
unknown
44:05 queued 20:09
created

testTranslatesGroups()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 25
rs 8.8571
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
/**
3
 * @license For full copyright and license information view LICENSE file distributed with this source code.
4
 */
5
namespace eZ\Publish\Core\Helper\Tests\FieldsGroups;
6
7
use eZ\Publish\Core\Helper\FieldsGroups\ArrayTranslatorFieldsGroupsList;
8
use PHPUnit_Framework_TestCase;
9
10
class ArrayTranslatorFieldsGroupsListTest extends PHPUnit_Framework_TestCase
11
{
12
    private $translatorMock;
13
14
    public function testTranslatesGroups()
15
    {
16
        $groups = ['slayer', 'system_of_a_down'];
17
        $default = 'system_of_a_down';
18
19
        $this->getTranslatorMock()
20
            ->expects($this->any())
21
            ->method('trans')
22
            ->will(
23
                $this->returnValueMap([
24
                    ['slayer', [], 'ezplatform_fields_groups', null, 'Slayer'],
25
                    ['system_of_a_down', [], 'ezplatform_fields_groups', null, 'System of a down'],
26
                ])
27
            );
28
29
        $list = $this->buildList($groups, $default);
30
31
        self::assertEquals(
32
            [
33
                'slayer' => 'Slayer',
34
                'system_of_a_down' => 'System of a down',
35
            ],
36
            $list->getGroups()
37
        );
38
    }
39
40
    public function testReturnsDefault()
41
    {
42
        $list = $this->buildList([], 'A');
43
44
        self::assertEquals('A', $list->getDefaultGroup());
45
    }
46
47
    public function testUsesIdentifierIfNoTranslation()
48
    {
49
        $groups = ['slayer', 'system_of_a_down'];
50
        $default = 'system_of_a_down';
51
52
        $this->getTranslatorMock()
53
            ->expects($this->any())
54
            ->method('trans')
55
            ->will($this->returnArgument(0));
56
57
        $list = $this->buildList($groups, $default);
58
59
        self::assertEquals(
60
            [
61
                'slayer' => 'slayer',
62
                'system_of_a_down' => 'system_of_a_down',
63
            ],
64
            $list->getGroups()
65
        );
66
    }
67
68
    private function buildList($groups, $default)
69
    {
70
        return new ArrayTranslatorFieldsGroupsList(
71
            $this->getTranslatorMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getTranslatorMock() targeting eZ\Publish\Core\Helper\T...st::getTranslatorMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Helper\F...oupsList::__construct() does only seem to accept object<Symfony\Component...on\TranslatorInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
72
            $default,
73
            $groups
74
        );
75
    }
76
77
    /**
78
     * @return \Symfony\Component\Translation\TranslatorInterface|\PHPUnit_Framework_MockObject_MockObject
79
     */
80
    private function getTranslatorMock()
81
    {
82
        if ($this->translatorMock === null) {
83
            $this->translatorMock = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
84
        }
85
86
        return $this->translatorMock;
87
    }
88
}
89