testBuildEasyMockForAbstractClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace FwolfTest\Wrapper\PHPUnit\Helper;
4
5
use Fwolf\Wrapper\PHPUnit\Helper\BuildEasyMockTrait;
6
use Fwolf\Wrapper\PHPUnit\TestCase;
7
use FwolfTest\Wrapper\PHPUnit\PHPUnitTestCaseTestDummy;
8
use PHPUnit\Framework\MockObject\MockObject;
9
10
/**
11
 * @copyright   Copyright 2015-2019 Fwolf
12
 * @license     http://opensource.org/licenses/MIT MIT
13
 */
14
class BuildEasyMockTraitTest extends TestCase
15
{
16
    /**
17
     * @param string[] $methods
18
     * @return  MockObject | BuildEasyMockTrait
19
     */
20
    protected function buildMock(array $methods = null)
21
    {
22
        $mock = $this->getMockBuilder(BuildEasyMockTrait::class)
23
            ->setMethods($methods)
24
            ->getMockForTrait()
25
        ;
26
27
        return $mock;
28
    }
29
30
31
    public function testBuildEasyMock()
32
    {
33
        $trait = $this->buildEasyMock(PHPUnitTestCaseTestDummy::class, [
34
            'publicMethod'   => 2019,
35
            'notExistMethod' => 'bar',
36
        ]);
37
38
        $this->assertEquals(2019, $trait->publicMethod());
0 ignored issues
show
Bug introduced by
The method publicMethod() 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...
39
        $this->assertEquals('bar', $trait->notExistMethod());
0 ignored issues
show
Bug introduced by
The method notExistMethod() 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...
40
41
42
        // Empty method will got a workable mock
43
        $trait = $this->buildEasyMock(PHPUnitTestCaseTestDummy::class);
44
45
        $this->assertNotEmpty($trait->publicMethod());
0 ignored issues
show
Bug introduced by
The method publicMethod() 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...
46
    }
47
48
49
    public function testBuildEasyMockForAbstractClass()
50
    {
51
        $trait = $this->buildEasyMock(AbstractClassDummy::class, [
52
            'get' => 42,
53
        ]);
54
55
        $this->assertEquals(42, $trait->get());
0 ignored issues
show
Bug introduced by
The method get() 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...
56
    }
57
58
59
    public function testBuildEasyMockForTrait()
60
    {
61
        $trait = $this->buildEasyMock(BuildEasyMockTrait::class, [
62
            'get' => 42,
63
        ]);
64
65
        $this->assertEquals(42, $trait->get());
0 ignored issues
show
Bug introduced by
The method get() 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...
66
    }
67
}
68