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); |
|
|
|
|
45
|
|
|
$this->innerArgumentFactoryB = $this->createMock(ArgumentFactory::class); |
|
|
|
|
46
|
|
|
$this->innerArgumentFactoryC = $this->createMock(ArgumentFactory::class); |
|
|
|
|
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) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$this->innerArgumentFactoryA->expects($this->any())->method('understandsString')->with( |
|
|
|
|
76
|
|
|
$this->equalTo($source) |
77
|
|
|
)->willReturn($a); |
78
|
|
|
$this->innerArgumentFactoryB->expects($this->any())->method('understandsString')->with( |
|
|
|
|
79
|
|
|
$this->equalTo($source) |
80
|
|
|
)->willReturn($b); |
81
|
|
|
$this->innerArgumentFactoryC->expects($this->any())->method('understandsString')->with( |
|
|
|
|
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) |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$this->innerArgumentFactoryA->expects($this->any())->method('understandsArray')->with( |
|
|
|
|
108
|
|
|
$this->equalTo($source) |
109
|
|
|
)->willReturn($a); |
110
|
|
|
$this->innerArgumentFactoryB->expects($this->any())->method('understandsArray')->with( |
|
|
|
|
111
|
|
|
$this->equalTo($source) |
112
|
|
|
)->willReturn($b); |
113
|
|
|
$this->innerArgumentFactoryC->expects($this->any())->method('understandsArray')->with( |
|
|
|
|
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
|
|
|
|
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..