Passed
Push — master ( 8e04a1...918acc )
by Gerrit
02:12
created

ArgumentFactoryAggregateTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 115
Duplicated Lines 29.57 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 34
loc 115
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
A shouldRejectNonArgumentFactoryInConstructor() 0 10 1
A shouldKnowWhenToUnderstandString() 17 17 1
A dataProviderForShouldKnowWhenToUnderstandString() 0 9 1
A shouldKnowWhenToUnderstandArray() 17 17 1
A dataProviderForShouldKnowWhenToUnderstandArray() 0 9 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
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\SymfonyGenerics\Arguments\ArgumentFactory;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\SymfonyGenerics\Arguments\ArgumentFactory\ArgumentFactoryAggregate;
15
use Addiks\SymfonyGenerics\Arguments\ArgumentFactory\ArgumentFactory;
16
use stdClass;
17
use InvalidArgumentException;
18
19
final class ArgumentFactoryAggregateTest extends TestCase
20
{
21
22
    /**
23
     * @var ArgumentFactoryAggregate
24
     */
25
    private $factoryAggregate;
26
27
    /**
28
     * @var ArgumentFactory
29
     */
30
    private $innerArgumentFactoryA;
31
32
    /**
33
     * @var ArgumentFactory
34
     */
35
    private $innerArgumentFactoryB;
36
37
    /**
38
     * @var ArgumentFactory
39
     */
40
    private $innerArgumentFactoryC;
41
42
    public function setUp()
43
    {
44
        $this->innerArgumentFactoryA = $this->createMock(ArgumentFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...ArgumentFactory::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\SymfonyGen...actory\ArgumentFactory> of property $innerArgumentFactoryA.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
        $this->innerArgumentFactoryB = $this->createMock(ArgumentFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...ArgumentFactory::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\SymfonyGen...actory\ArgumentFactory> of property $innerArgumentFactoryB.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
        $this->innerArgumentFactoryC = $this->createMock(ArgumentFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...ArgumentFactory::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\SymfonyGen...actory\ArgumentFactory> of property $innerArgumentFactoryC.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
48
        $this->factoryAggregate = new ArgumentFactoryAggregate([
49
            $this->innerArgumentFactoryA,
50
            $this->innerArgumentFactoryB,
51
            $this->innerArgumentFactoryC,
52
        ]);
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function shouldRejectNonArgumentFactoryInConstructor()
59
    {
60
        $this->expectException(InvalidArgumentException::class);
61
62
        new ArgumentFactoryAggregate([
63
            $this->innerArgumentFactoryA,
64
            $this->innerArgumentFactoryB,
65
            $this->createMock(stdClass::class),
66
        ]);
67
    }
68
69
    /**
70
     * @test
71
     * @dataProvider dataProviderForShouldKnowWhenToUnderstandString
72
     */
73 View Code Duplication
    public function shouldKnowWhenToUnderstandString(bool $expectedResult, string $source, bool $a, bool $b, bool $c)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        $this->innerArgumentFactoryA->expects($this->any())->method('understandsString')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\SymfonyGen...actory\ArgumentFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
            $this->equalTo($source)
77
        )->willReturn($a);
78
        $this->innerArgumentFactoryB->expects($this->any())->method('understandsString')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\SymfonyGen...actory\ArgumentFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
            $this->equalTo($source)
80
        )->willReturn($b);
81
        $this->innerArgumentFactoryC->expects($this->any())->method('understandsString')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\SymfonyGen...actory\ArgumentFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
            $this->equalTo($source)
83
        )->willReturn($c);
84
85
        /** @var bool $actualResult */
86
        $actualResult = $this->factoryAggregate->understandsString($source);
87
88
        $this->assertEquals($expectedResult, $actualResult);
89
    }
90
91
    public function dataProviderForShouldKnowWhenToUnderstandString()
92
    {
93
        return array(
94
            [false, "foo", false, false, false],
95
            [true,  "foo", true,  false, false],
96
            [true,  "foo", false, true,  false],
97
            [true,  "foo", false, false, true],
98
        );
99
    }
100
101
    /**
102
     * @test
103
     * @dataProvider dataProviderForShouldKnowWhenToUnderstandArray
104
     */
105 View Code Duplication
    public function shouldKnowWhenToUnderstandArray(bool $expectedResult, array $source, bool $a, bool $b, bool $c)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    {
107
        $this->innerArgumentFactoryA->expects($this->any())->method('understandsArray')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\SymfonyGen...actory\ArgumentFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
            $this->equalTo($source)
109
        )->willReturn($a);
110
        $this->innerArgumentFactoryB->expects($this->any())->method('understandsArray')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\SymfonyGen...actory\ArgumentFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
111
            $this->equalTo($source)
112
        )->willReturn($b);
113
        $this->innerArgumentFactoryC->expects($this->any())->method('understandsArray')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\SymfonyGen...actory\ArgumentFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114
            $this->equalTo($source)
115
        )->willReturn($c);
116
117
        /** @var bool $actualResult */
118
        $actualResult = $this->factoryAggregate->understandsArray($source);
119
120
        $this->assertEquals($expectedResult, $actualResult);
121
    }
122
123
    public function dataProviderForShouldKnowWhenToUnderstandArray()
124
    {
125
        return array(
126
            [false, ["foo"], false, false, false],
127
            [true,  ["foo"], true,  false, false],
128
            [true,  ["foo"], false, true,  false],
129
            [true,  ["foo"], false, false, true],
130
        );
131
    }
132
133
}
134