Test Failed
Push — master ( 310ecf...5d6054 )
by Alexey
05:08
created

InjiTest::testSavingEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class InjiTest extends PHPUnit\Framework\TestCase {
4
5
    function setUp() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6
        
7
    }
8
9
    /**
10
     * @covers Inji::listen
11
     * @covers Inji::event
12
     * @covers Inji::unlisten
13
     */
14
    public function testNotSavingEvent() {
15
        \Inji::$inst->listen('testEvent', 'testCallback', function() {
16
            return true;
17
        });
18
        $this->assertEquals(true, Inji::$inst->event('testEvent'));
19
        \Inji::$inst->unlisten('testEvent', 'testCallback');
20
    }
21
22
    /**
23
     * @covers Inji::listen
24
     * @covers Inji::event
25
     * @covers Inji::unlisten
26
     */
27
    public function testSavingEvent() {
28
        \Inji::$inst->listen('testEvent2', 'testCallback', 'InjiTestcallback', true);
0 ignored issues
show
Documentation introduced by
'InjiTestcallback' is of type string, but the function expects a array|object<Closure>.

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...
29
        $this->assertEquals(true, Inji::$inst->event('testEvent2'));
30
        \Inji::$inst->unlisten('testEvent2', 'testCallback', true);
31
    }
32
33
    /**
34
     * @covers Inji::listen
35
     * @covers Inji::event
36
     */
37
    public function testArrayWithCallback() {
38
        $callbackOptions = ['callback' => 'InjiTestcallbackArray', 'data' => 'data'];
39
        \Inji::$inst->listen('testEvent3', 'testCallback', $callbackOptions);
40
        $this->assertEquals($callbackOptions, Inji::$inst->event('testEvent3'));
41
    }
42
}
43
44
function InjiTestcallback() {
45
    return true;
46
}
47
48
function InjiTestcallbackArray($event, $callbackOptions) {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    return $callbackOptions;
50
}
51