Completed
Push — master ( 47ba96...4fd14e )
by Gerrit
02:18
created

shouldKnowIfUnderstandArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\SymfonyGenerics\Arguments\ArgumentFactory\ArgumentCallFactory;
15
use Addiks\SymfonyGenerics\Arguments\ArgumentFactory\ArgumentFactory;
16
17
final class ArgumentCallFactoryTest extends TestCase
18
{
19
20
    /**
21
     * @var ArgumentCallFactory
22
     */
23
    private $factory;
24
25
    /**
26
     * @var ArgumentFactory
27
     */
28
    private $argumentFactory;
29
30
    public function setUp()
31
    {
32
        $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...
33
34
        $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...
35
    }
36
37
    /**
38
     * @test
39
     * @dataProvider dataProviderForShouldKnowIfUnderstandString
40
     */
41
    public function shouldKnowIfUnderstandString(bool $expectedResult, string $source)
42
    {
43
        /** @var bool $actualResult */
44
        $actualResult = $this->factory->understandsString($source);
45
46
        $this->assertEquals($expectedResult, $actualResult);
47
    }
48
49
    public function dataProviderForShouldKnowIfUnderstandString()
50
    {
51
        return array(
52
            [true, 'a::b'],
53
            [true, 'foo::bar'],
54
            [true, 'foo::bar(baz)'],
55
            [false, '::b'],
56
            [false, 'a::'],
57
            [false, '::'],
58
        );
59
    }
60
61
    /**
62
     * @test
63
     * @dataProvider dataProviderForShouldKnowIfUnderstandArray
64
     */
65
    public function shouldKnowIfUnderstandArray(bool $expectedResult, array $source)
66
    {
67
        /** @var bool $actualResult */
68
        $actualResult = $this->factory->understandsArray($source);
69
70
        $this->assertEquals($expectedResult, $actualResult);
71
    }
72
73
    public function dataProviderForShouldKnowIfUnderstandArray()
74
    {
75
        return array(
76
            [true,  ['callee' => 'foo', 'method' => 'bar']],
77
            [true,  ['callee' => 'foo', 'method' => 'bar', 'arguments' => []]],
78
            [false, ['method' => 'bar']],
79
            [false, ['callee' => 'foo']],
80
        );
81
    }
82
83
}
84