Completed
Push — 6.13 ( 9c335d...8c8805 )
by
unknown
16:33
created

MultipleValuedTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 43.4 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 23
loc 53
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetMatchingConfig() 12 12 3
A matchingConfigProvider() 11 11 1
A testInjectRepository() 0 6 1
A getMultipleValuedMatcherMock() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * File containing the MultipleValuedTest 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\MVC\Symfony\Matcher\Tests\ContentBased;
10
11
use eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued;
12
13
class MultipleValuedTest extends BaseTest
14
{
15
    /**
16
     * @dataProvider matchingConfigProvider
17
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig
18
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::getValues
19
     */
20 View Code Duplication
    public function testSetMatchingConfig($matchingConfig)
21
    {
22
        $matcher = $this->getMultipleValuedMatcherMock();
23
        $matcher->setMatchingConfig($matchingConfig);
24
        $values = $matcher->getValues();
25
        $this->assertInternalType('array', $values);
26
27
        $matchingConfig = is_array($matchingConfig) ? $matchingConfig : [$matchingConfig];
28
        foreach ($matchingConfig as $val) {
29
            $this->assertContains($val, $values);
30
        }
31
    }
32
33
    /**
34
     * Returns a set of matching values, either single or multiple.
35
     *
36
     * @return array
37
     */
38 View Code Duplication
    public function matchingConfigProvider()
39
    {
40
        return [
41
            [
42
                'singleValue',
43
                ['one', 'two', 'three'],
44
                [123, 'nous irons au bois'],
45
                456,
46
            ],
47
        ];
48
    }
49
50
    /**
51
     * @covers \eZ\Publish\Core\MVC\RepositoryAware::setRepository
52
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::getRepository
53
     */
54
    public function testInjectRepository()
55
    {
56
        $matcher = $this->getMultipleValuedMatcherMock();
57
        $matcher->setRepository($this->repositoryMock);
58
        $this->assertSame($this->repositoryMock, $matcher->getRepository());
59
    }
60
61
    private function getMultipleValuedMatcherMock()
62
    {
63
        return $this->getMockForAbstractClass(MultipleValued::class);
64
    }
65
}
66