Passed
Push — master ( 8e04a1...918acc )
by Gerrit
02:12
created

RequestPayloadArgumentFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A shouldKnowIfUnderstandString() 0 5 1
A shouldKnowIfUnderstandArray() 0 5 1
A shouldCreateArguments() 0 11 1
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\RequestPayloadArgumentFactory;
15
use Symfony\Component\HttpFoundation\RequestStack;
16
use Addiks\SymfonyGenerics\Arguments\RequestPayloadArgument;
17
18
final class RequestPayloadArgumentFactoryTest extends TestCase
19
{
20
21
    /**
22
     * @var RequestPayloadArgumentFactory
23
     */
24
    private $factory;
25
26
    /**
27
     * @var RequestStack
28
     */
29
    private $requestStack;
30
31
    public function setUp()
32
    {
33
        $this->requestStack = $this->createMock(RequestStack::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Symfo...on\RequestStack::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component...oundation\RequestStack> of property $requestStack.

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...
34
35
        $this->factory = new RequestPayloadArgumentFactory($this->requestStack);
0 ignored issues
show
Documentation introduced by
$this->requestStack is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...oundation\RequestStack>.

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...
36
    }
37
38
    /**
39
     * @test
40
     */
41
    public function shouldKnowIfUnderstandString()
42
    {
43
        $this->assertEquals(true, $this->factory->understandsString("$"));
44
        $this->assertEquals(false, $this->factory->understandsString("not $"));
45
    }
46
47
    /**
48
     * @test
49
     */
50
    public function shouldKnowIfUnderstandArray()
51
    {
52
        $this->assertEquals(true, $this->factory->understandsArray(['type' => 'request-payload']));
53
        $this->assertEquals(false, $this->factory->understandsArray(['type' => 'anything else']));
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function shouldCreateArguments()
60
    {
61
        $this->assertEquals(
62
            new RequestPayloadArgument($this->requestStack),
63
            $this->factory->createArgumentFromString("")
64
        );
65
        $this->assertEquals(
66
            new RequestPayloadArgument($this->requestStack),
67
            $this->factory->createArgumentFromArray([])
68
        );
69
    }
70
71
}
72