Passed
Push — master ( ef92a5...f096ba )
by Gerrit
02:09
created

shouldHaveEntityClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
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\Events;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\SymfonyGenerics\Events\EntityInteractionEvent;
15
use stdClass;
16
use InvalidArgumentException;
17
18
final class EntityInteractionEventTest extends TestCase
19
{
20
21
    /**
22
     * @var EntityInteractionEvent
23
     */
24
    private $event;
25
26
    /**
27
     * @var stdClass
28
     */
29
    private $entity;
30
31
    public function setUp()
32
    {
33
        $this->entity = $this->createMock(stdClass::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\stdClass::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<stdClass> of property $entity.

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->event = new EntityInteractionEvent(
36
            "stdClass",
37
            "some-entity-id",
38
            $this->entity,
39
            "someMethod",
40
            ['foo', 'bar']
41
        );
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function shouldRejectNonExistingClass()
48
    {
49
        $this->expectException(InvalidArgumentException::class);
50
51
        new EntityInteractionEvent(
52
            "doesNotExist",
53
            "some-entity-id",
54
            $this->entity,
55
            "someMethod",
56
            ['foo', 'bar']
57
        );
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function shouldRejectNonObjectEntity()
64
    {
65
        $this->expectException(InvalidArgumentException::class);
66
67
        new EntityInteractionEvent(
68
            "stdClass",
69
            "some-entity-id",
70
            "entity",
0 ignored issues
show
Documentation introduced by
'entity' is of type string, but the function expects a object|null.

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...
71
            "someMethod",
72
            ['foo', 'bar']
73
        );
74
    }
75
76
    /**
77
     * @test
78
     */
79
    public function shouldHaveEntityClass()
80
    {
81
        $this->assertEquals("stdClass", $this->event->getEntityClass());
82
    }
83
84
    /**
85
     * @test
86
     */
87
    public function shouldHaveEntityId()
88
    {
89
        $this->assertEquals("some-entity-id", $this->event->getEntityId());
90
    }
91
92
    /**
93
     * @test
94
     */
95
    public function shouldHaveEntity()
96
    {
97
        $this->assertSame($this->entity, $this->event->getEntity());
98
    }
99
100
    /**
101
     * @test
102
     */
103
    public function shouldHaveMethod()
104
    {
105
        $this->assertEquals("someMethod", $this->event->getMethod());
106
    }
107
108
    /**
109
     * @test
110
     */
111
    public function shouldHaveArguments()
112
    {
113
        $this->assertEquals(['foo', 'bar'], $this->event->getArguments());
114
    }
115
116
}
117