Completed
Push — master ( a4e450...e0a9b7 )
by Fwolf
02:09
created

TestCaseTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 82
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildMock() 0 9 1
A testAssertEqualArray() 0 16 1
A testAssertEqualArrayWithDifferentSequence() 0 22 2
A testReflectionMethods() 0 20 1
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);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
45
46
        $testCase->assertEqualArray($ar1, $ar1);
0 ignored issues
show
Bug introduced by
The method assertEqualArray() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
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);
0 ignored issues
show
Bug introduced by
The method assertEqualArray() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
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')
0 ignored issues
show
Bug introduced by
The method reflectionGet() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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
        );
83
84
        $this->assertEquals(3, $dummy->publicMethod());
85
        $this->assertEquals(
86
            3,
87
            $testCase->reflectionCall($dummy, 'privateMethod')
0 ignored issues
show
Bug introduced by
The method reflectionCall() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
88
        );
89
90
        $testCase->reflectionSet($dummy, 'privateProperty', 20);
0 ignored issues
show
Bug introduced by
The method reflectionSet() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
91
        $testCase->reflectionSet($dummy, 'privateStaticProperty', 22);
0 ignored issues
show
Bug introduced by
The method reflectionSet() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
92
        $this->assertEquals(42, $dummy->publicMethod());
93
    }
94
}
95