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

SettingsFieldsGroupsListFactoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testBuild() 0 18 1
A getRepositoryConfigMock() 0 11 2
A getTranslatorMock() 0 8 2
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