Passed
Push — master ( 928c25...8579cb )
by Gerrit
02:16
created

edMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
use Addiks\SymfonyGenerics\Services\ArgumentCompilerInterface;
19
use ReflectionMethod;
20
21
final class ArgumentCallTest extends TestCase
22
{
23
24
    /**
25
     * @test
26
     */
27
    public function shouldResolveCallArgument()
28
    {
29
        /** @var Argument $callee */
30
        $callee = $this->createMock(Argument::class);
31
        $callee->method("resolve")->willReturn($this);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
32
33
        /** @var Argument $argumentA */
34
        $argumentA = $this->createMock(Argument::class);
35
        $argumentA->method("resolve")->willReturn("some-foo");
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
36
37
        /** @var Argument $argumentB */
38
        $argumentB = $this->createMock(Argument::class);
39
        $argumentB->method("resolve")->willReturn(31415);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\SymfonyGenerics\Arguments\Argument>.

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
        /** @var ArgumentCompilerInterface $argumentCompiler */
42
        $argumentCompiler = $this->createMock(ArgumentCompilerInterface::class);
43
        $argumentCompiler->expects($this->any())->method('buildCallArguments')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\SymfonyGen...umentCompilerInterface>.

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...
44
            $this->equalTo(new ReflectionMethod(__CLASS__, 'someMethod')),
45
            $this->equalTo(["some-foo", 31415])
46
        )->willReturn(["some-foo", 31415]);
47
48
        $subject = new ArgumentCall(
49
            $argumentCompiler,
50
            $callee,
51
            "someMethod",
52
            [
53
                $argumentA,
54
                $argumentB
55
            ]
56
        );
57
58
        /** @var mixed $actualResult */
59
        $actualResult = $subject->resolve();
60
61
        $this->assertEquals("some-result", $actualResult);
62
    }
63
64
    public function someMethod(string $foo, int $bar): string
65
    {
66
        $this->assertEquals("some-foo", $foo);
67
        $this->assertEquals(31415, $bar);
68
        return "some-result";
69
    }
70
71
    /**
72
     * @test
73
     */
74 View Code Duplication
    public function shouldRejectNonObjectCallee()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $this->expectException(InvalidArgumentException::class);
77
78
        /** @var Argument $callee */
79
        $callee = $this->createMock(Argument::class);
80
        $callee->method("resolve")->willReturn("non-object");
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
81
82
        $subject = new ArgumentCall(
83
            $this->createMock(ArgumentCompilerInterface::class),
0 ignored issues
show
Documentation introduced by
$this->createMock(\Addik...mpilerInterface::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\SymfonyGen...umentCompilerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
            $callee,
85
            "someMethod",
86
            []
87
        );
88
89
        $subject->resolve();
90
    }
91
92
}
93