Passed
Push — master ( 4fd14e...da3759 )
by Gerrit
02:04
created

dataProviderForShouldCreateCallArgumentFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 9.1127
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\ArgumentFactory;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\SymfonyGenerics\Arguments\ArgumentFactory\ArgumentCallFactory;
15
use Addiks\SymfonyGenerics\Arguments\ArgumentFactory\ArgumentFactory;
16
use InvalidArgumentException;
17
use Addiks\SymfonyGenerics\Arguments\ArgumentCall;
18
use Addiks\SymfonyGenerics\Arguments\Argument;
19
20
final class ArgumentCallFactoryTest extends TestCase
21
{
22
23
    /**
24
     * @var ArgumentCallFactory
25
     */
26
    private $factory;
27
28
    /**
29
     * @var ArgumentFactory
30
     */
31
    private $argumentFactory;
32
33
    public function setUp()
34
    {
35
        $this->argumentFactory = $this->createMock(ArgumentFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...ArgumentFactory::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\SymfonyGen...actory\ArgumentFactory> of property $argumentFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
37
        $this->factory = new ArgumentCallFactory($this->argumentFactory);
0 ignored issues
show
Documentation introduced by
$this->argumentFactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\SymfonyGen...actory\ArgumentFactory>.

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...
38
    }
39
40
    /**
41
     * @test
42
     * @dataProvider dataProviderForShouldKnowIfUnderstandString
43
     */
44
    public function shouldKnowIfUnderstandString(bool $expectedResult, string $source)
45
    {
46
        /** @var bool $actualResult */
47
        $actualResult = $this->factory->understandsString($source);
48
49
        $this->assertEquals($expectedResult, $actualResult);
50
    }
51
52
    public function dataProviderForShouldKnowIfUnderstandString()
53
    {
54
        return array(
55
            [true, 'a::b'],
56
            [true, 'foo::bar'],
57
            [true, 'foo::bar(baz)'],
58
            [false, '::b'],
59
            [false, 'a::'],
60
            [false, '::'],
61
        );
62
    }
63
64
    /**
65
     * @test
66
     * @dataProvider dataProviderForShouldKnowIfUnderstandArray
67
     */
68
    public function shouldKnowIfUnderstandArray(bool $expectedResult, array $source)
69
    {
70
        /** @var bool $actualResult */
71
        $actualResult = $this->factory->understandsArray($source);
72
73
        $this->assertEquals($expectedResult, $actualResult);
74
    }
75
76
    public function dataProviderForShouldKnowIfUnderstandArray()
77
    {
78
        return array(
79
            [true,  ['callee' => 'foo', 'method' => 'bar']],
80
            [true,  ['callee' => 'foo', 'method' => 'bar', 'arguments' => []]],
81
            [false, ['method' => 'bar']],
82
            [false, ['callee' => 'foo']],
83
        );
84
    }
85
86
    /**
87
     * @test
88
     * @dataProvider dataProviderForShouldCreateCallArgumentFromString
89
     */
90
    public function shouldCreateCallArgumentFromString(
91
        ?ArgumentCall $expectedResult,
92
        string $source,
93
        bool $shouldRejectCreation
94
    ) {
95
        if ($shouldRejectCreation) {
96
            $this->expectException(InvalidArgumentException::class);
97
98
        } else {
99
            $this->argumentFactory->method('createArgumentFromString')->willReturn($this->createMock(Argument::class));
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\SymfonyGen...actory\ArgumentFactory>.

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...
100
        }
101
102
        $actualResult = $this->factory->createArgumentFromString($source);
103
104
        $this->assertEquals($expectedResult, $actualResult);
105
    }
106
107
    public function dataProviderForShouldCreateCallArgumentFromString(): array
108
    {
109
        return array(
110
            [new ArgumentCall($this->createMock(Argument::class), 'someMethod', []), 'some-callee::someMethod', false],
0 ignored issues
show
Documentation introduced by
$this->createMock(\Addik...uments\Argument::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
111
            [new ArgumentCall($this->createMock(Argument::class), 'someMethod', [
0 ignored issues
show
Documentation introduced by
$this->createMock(\Addik...uments\Argument::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
112
                $this->createMock(Argument::class),
113
                $this->createMock(Argument::class)
114
            ]), 'some-callee::someMethod(a, b)', false],
115
            [null, 'a::', true],
116
            [null, '::b', true],
117
            [null, '::', true],
118
        );
119
    }
120
121
    /**
122
     * @test
123
     * @dataProvider dataProviderForShouldCreateCallArgumentFromArray
124
     */
125
    public function shouldCreateCallArgumentFromArray(
126
        $expectedResult,
127
        array $source,
128
        bool $shouldRejectCreation
129
    ) {
130
        if ($shouldRejectCreation) {
131
            $this->expectException(InvalidArgumentException::class);
132
133
        } else {
134
            $this->argumentFactory->method('createArgumentFromString')->willReturn($this->createMock(Argument::class));
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\SymfonyGen...actory\ArgumentFactory>.

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...
135
            $this->argumentFactory->method('createArgumentFromArray')->willReturn($this->createMock(Argument::class));
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\SymfonyGen...actory\ArgumentFactory>.

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...
136
        }
137
138
        $actualResult = $this->factory->createArgumentFromArray($source);
139
140
        $this->assertEquals($expectedResult, $actualResult);
141
    }
142
143
    public function dataProviderForShouldCreateCallArgumentFromArray(): array
144
    {
145
        return array(
146
            [null, [], true],
147
            [null, ['method' => 'foo'], true],
148
            [null, ['callee' => 'bar'], true],
149
            [new ArgumentCall($this->createMock(Argument::class), 'someMethod', []), [
0 ignored issues
show
Documentation introduced by
$this->createMock(\Addik...uments\Argument::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
150
                'callee' => 'some-callee',
151
                'method' => 'someMethod'
152
            ], false],
153
            [new ArgumentCall($this->createMock(Argument::class), 'someMethod', []), [
0 ignored issues
show
Documentation introduced by
$this->createMock(\Addik...uments\Argument::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
154
                'callee' => ['some-callee'],
155
                'method' => 'someMethod'
156
            ], false],
157
            [new ArgumentCall($this->createMock(Argument::class), 'someMethod', [
0 ignored issues
show
Documentation introduced by
$this->createMock(\Addik...uments\Argument::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
158
                $this->createMock(Argument::class),
159
                $this->createMock(Argument::class)
160
            ]), [
161
                'callee' => 'some-callee',
162
                'method' => 'someMethod',
163
                'arguments' => [
164
                    'foo',
165
                    'bar'
166
                ]
167
            ], false],
168
            [new ArgumentCall($this->createMock(Argument::class), 'someMethod', [
0 ignored issues
show
Documentation introduced by
$this->createMock(\Addik...uments\Argument::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
169
                $this->createMock(Argument::class),
170
                $this->createMock(Argument::class)
171
            ]), [
172
                'callee' => ['some-callee'],
173
                'method' => 'someMethod',
174
                'arguments' => [
175
                    'foo',
176
                    'bar'
177
                ]
178
            ], false],
179
            [new ArgumentCall($this->createMock(Argument::class), 'someMethod', [
0 ignored issues
show
Documentation introduced by
$this->createMock(\Addik...uments\Argument::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\SymfonyGenerics\Arguments\Argument>.

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...
180
                $this->createMock(Argument::class),
181
                $this->createMock(Argument::class)
182
            ]), [
183
                'callee' => 'some-callee',
184
                'method' => 'someMethod',
185
                'arguments' => [
186
                    ['foo'],
187
                    ['bar']
188
                ]
189
            ], false],
190
        );
191
    }
192
193
}
194