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\Tests\Unit\Arguments; |
12
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
use Addiks\SymfonyGenerics\Arguments\ArgumentCall; |
15
|
|
|
use Addiks\SymfonyGenerics\Arguments\Argument; |
16
|
|
|
use InvalidArgumentException; |
17
|
|
|
use stdClass; |
18
|
|
|
|
19
|
|
|
final class ArgumentCallTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @test |
24
|
|
|
*/ |
25
|
|
|
public function shouldResolveCallArgument() |
26
|
|
|
{ |
27
|
|
|
/** @var Argument $callee */ |
28
|
|
|
$callee = $this->createMock(Argument::class); |
29
|
|
|
$callee->method("resolve")->willReturn($this); |
|
|
|
|
30
|
|
|
|
31
|
|
|
/** @var Argument $argumentA */ |
32
|
|
|
$argumentA = $this->createMock(Argument::class); |
33
|
|
|
$argumentA->method("resolve")->willReturn("some-foo"); |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** @var Argument $argumentB */ |
36
|
|
|
$argumentB = $this->createMock(Argument::class); |
37
|
|
|
$argumentB->method("resolve")->willReturn(31415); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$subject = new ArgumentCall($callee, "someMethod", [ |
40
|
|
|
$argumentA, |
41
|
|
|
$argumentB |
42
|
|
|
]); |
43
|
|
|
|
44
|
|
|
/** @var mixed $actualResult */ |
45
|
|
|
$actualResult = $subject->resolve(); |
46
|
|
|
|
47
|
|
|
$this->assertEquals("some-result", $actualResult); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function someMethod(string $foo, int $bar): string |
51
|
|
|
{ |
52
|
|
|
$this->assertEquals("some-foo", $foo); |
53
|
|
|
$this->assertEquals(31415, $bar); |
54
|
|
|
return "some-result"; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @test |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function shouldRejectNonObjectCallee() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$this->expectException(InvalidArgumentException::class); |
63
|
|
|
|
64
|
|
|
/** @var Argument $callee */ |
65
|
|
|
$callee = $this->createMock(Argument::class); |
66
|
|
|
$callee->method("resolve")->willReturn("non-object"); |
|
|
|
|
67
|
|
|
|
68
|
|
|
$subject = new ArgumentCall($callee, "someMethod", []); |
69
|
|
|
|
70
|
|
|
$subject->resolve(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @test |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
public function shouldRejectCalleeWithoutCalledMethod() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
$this->expectException(InvalidArgumentException::class); |
79
|
|
|
|
80
|
|
|
/** @var Argument $callee */ |
81
|
|
|
$callee = $this->createMock(Argument::class); |
82
|
|
|
$callee->method("resolve")->willReturn($this->createMock(stdClass::class)); |
|
|
|
|
83
|
|
|
|
84
|
|
|
$subject = new ArgumentCall($callee, "someMethod", []); |
85
|
|
|
|
86
|
|
|
$subject->resolve(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
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.