|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FwolfTest\Wrapper\PHPUnit; |
|
4
|
|
|
|
|
5
|
|
|
use Fwolf\Wrapper\PHPUnit\TestCase; |
|
6
|
|
|
use PHPUnit\Framework\ExpectationFailedException; |
|
7
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @copyright Copyright 2015-2019 Fwolf |
|
11
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
12
|
|
|
*/ |
|
13
|
|
|
class TestCaseTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @return MockObject | TestCase |
|
17
|
|
|
*/ |
|
18
|
|
|
protected function buildMock() |
|
19
|
|
|
{ |
|
20
|
|
|
$mock = $this->getMockBuilder(TestCase::class) |
|
21
|
|
|
->setMethods(null) |
|
22
|
|
|
->getMock() |
|
23
|
|
|
; |
|
24
|
|
|
|
|
25
|
|
|
return $mock; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Assoc with different key sequence is equal by default |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testAssertEqualArray() |
|
33
|
|
|
{ |
|
34
|
|
|
$testCase = $this->buildMock(); |
|
35
|
|
|
|
|
36
|
|
|
$ar1 = [ |
|
37
|
|
|
'foo' => 1, |
|
38
|
|
|
'bar' => 2, |
|
39
|
|
|
]; |
|
40
|
|
|
$ar2 = [ |
|
41
|
|
|
'bar' => 2, |
|
42
|
|
|
'foo' => 1, |
|
43
|
|
|
]; |
|
44
|
|
|
$testCase->assertEquals($ar1, $ar2); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$testCase->assertEqualArray($ar1, $ar1); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
public function testAssertEqualArrayWithDifferentSequence() |
|
51
|
|
|
{ |
|
52
|
|
|
$testCase = $this->buildMock(); |
|
53
|
|
|
|
|
54
|
|
|
$ar1 = [ |
|
55
|
|
|
'foo' => 1, |
|
56
|
|
|
'bar' => 2, |
|
57
|
|
|
]; |
|
58
|
|
|
$ar2 = [ |
|
59
|
|
|
'bar' => 2, |
|
60
|
|
|
'foo' => 1, |
|
61
|
|
|
]; |
|
62
|
|
|
try { |
|
63
|
|
|
$testCase->assertEqualArray($ar1, $ar2); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
// No error caught means test fail |
|
66
|
|
|
$this->assertTrue(false); |
|
67
|
|
|
} catch (ExpectationFailedException $e) { |
|
68
|
|
|
// Caught exception means 2 array are not equal |
|
69
|
|
|
$this->assertTrue(true); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function testReflectionMethods() |
|
75
|
|
|
{ |
|
76
|
|
|
$testCase = $this->buildMock(); |
|
77
|
|
|
$dummy = new PHPUnitTestCaseTestDummy(); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertEquals( |
|
80
|
|
|
1, |
|
81
|
|
|
$testCase->reflectionGet($dummy, 'privateProperty') |
|
|
|
|
|
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertEquals(3, $dummy->publicMethod()); |
|
85
|
|
|
$this->assertEquals( |
|
86
|
|
|
3, |
|
87
|
|
|
$testCase->reflectionCall($dummy, 'privateMethod') |
|
|
|
|
|
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$testCase->reflectionSet($dummy, 'privateProperty', 20); |
|
|
|
|
|
|
91
|
|
|
$testCase->reflectionSet($dummy, 'privateStaticProperty', 22); |
|
|
|
|
|
|
92
|
|
|
$this->assertEquals(42, $dummy->publicMethod()); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
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.