Completed
Push — ezp25376-fields_groups ( 9b1c3e...03c022 )
by
unknown
37:48 queued 19:51
created

SettingsFieldsGroupsListFactoryTest::testBuild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
rs 9.4285
cc 1
eloc 13
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\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider;
8
use eZ\Publish\Core\Helper\FieldsGroups\SettingsFieldsGroupsListFactory;
9
use PHPUnit_Framework_TestCase;
10
11
class SettingsFieldsGroupsListFactoryTest extends PHPUnit_Framework_TestCase
12
{
13
    private $repositoryConfigMock;
14
15
    private $translatorMock;
16
17
    public function testBuild()
18
    {
19
        $this->getRepositoryConfigMock()
20
            ->expects($this->once())
21
            ->method('getRepositoryConfig')
22
            ->willReturn(['fields_groups' => ['list' => ['group_a', 'group_b'], 'default' => 'group_a']]);
23
24
        $this->getTranslatorMock()
25
            ->expects($this->any())
26
            ->method('trans')
27
            ->will($this->returnArgument(0));
28
29
        $factory = new SettingsFieldsGroupsListFactory($this->getRepositoryConfigMock());
0 ignored issues
show
Bug introduced by
It seems like $this->getRepositoryConfigMock() targeting eZ\Publish\Core\Helper\T...tRepositoryConfigMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Helper\F...tFactory::__construct() does only seem to accept object<eZ\Bundle\EzPubli...yConfigurationProvider>, 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...
30
        $list = $factory->build($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...upsListFactory::build() 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...
31
        
32
        self::assertEquals(['group_a' => 'group_a', 'group_b' => 'group_b'], $list->getGroups());
33
        self::assertEquals('group_a', $list->getDefaultGroup());
34
    }
35
36
    /**
37
     * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider
38
     */
39
    protected function getRepositoryConfigMock()
40
    {
41
        if (!isset($this->repositoryConfigMock)) {
42
            $this->repositoryConfigMock = $this
43
                ->getMockBuilder('eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider')
44
                ->disableOriginalConstructor()
45
                ->getMock();
46
        }
47
48
        return $this->repositoryConfigMock;
49
    }
50
51
    /**
52
     * @return \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\Translation\TranslatorInterface
53
     */
54
    protected function getTranslatorMock()
55
    {
56
        if (!isset($this->translatorMock)) {
57
            $this->translatorMock = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
58
        }
59
60
        return $this->translatorMock;
61
    }
62
}
63