Completed
Push — master ( bb497c...039325 )
by Alexander
10:30
created

ProviderTest::testInvokable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 8
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Yii\EventDispatcher\Tests\Provider;
3
4
use PHPUnit\Framework\TestCase;
5
use Yii\EventDispatcher\Provider\Provider;
6
use Yii\EventDispatcher\Tests\EventListener;
7
use Yii\EventDispatcher\Tests\InvokableEventListener;
8
use Yii\EventDispatcher\Tests\CustomEvent;
9
use Yii\EventDispatcher\Tests\StaticEventListener;
10
11
class ProviderTest extends TestCase
12
{
13 View Code Duplication
    public function testAttachCallableArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        $provider = new Provider();
16
        $provider->attach([StaticEventListener::class, 'handle']);
17
18
        $listeners = $provider->getListenersForEvent(new CustomEvent());
0 ignored issues
show
Documentation introduced by
new \Yii\EventDispatcher\Tests\CustomEvent() is of type object<Yii\EventDispatcher\Tests\CustomEvent>, but the function expects a object<Yii\EventDispatcher\Provider\object>.

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...
19
        $this->assertCount(1, $listeners);
20
21
    }
22
23 View Code Duplication
    public function testAttachCallableFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $provider = new Provider();
26
        $provider->attach('Yii\EventDispatcher\Tests\Provider\handle');
27
28
        $listeners = $provider->getListenersForEvent(new CustomEvent());
0 ignored issues
show
Documentation introduced by
new \Yii\EventDispatcher\Tests\CustomEvent() is of type object<Yii\EventDispatcher\Tests\CustomEvent>, but the function expects a object<Yii\EventDispatcher\Provider\object>.

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->assertCount(1, $listeners);
30
    }
31
32 View Code Duplication
    public function testAttachClosure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        $provider = new Provider();
35
        $provider->attach(function (CustomEvent $event) {});
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...
36
37
        $listeners = $provider->getListenersForEvent(new CustomEvent());
0 ignored issues
show
Documentation introduced by
new \Yii\EventDispatcher\Tests\CustomEvent() is of type object<Yii\EventDispatcher\Tests\CustomEvent>, but the function expects a object<Yii\EventDispatcher\Provider\object>.

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
        $this->assertCount(1, $listeners);
39
    }
40
41 View Code Duplication
    public function testAttachCallableObject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $provider = new Provider();
44
        $provider->attach([new EventListener(), 'handle']);
45
46
        $listeners = $provider->getListenersForEvent(new CustomEvent());
0 ignored issues
show
Documentation introduced by
new \Yii\EventDispatcher\Tests\CustomEvent() is of type object<Yii\EventDispatcher\Tests\CustomEvent>, but the function expects a object<Yii\EventDispatcher\Provider\object>.

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...
47
        $this->assertCount(1, $listeners);
48
    }
49
50 View Code Duplication
    public function testInvokable()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $provider = new Provider();
53
        $provider->attach(new InvokableEventListener());
54
55
        $listeners = $provider->getListenersForEvent(new CustomEvent());
0 ignored issues
show
Documentation introduced by
new \Yii\EventDispatcher\Tests\CustomEvent() is of type object<Yii\EventDispatcher\Tests\CustomEvent>, but the function expects a object<Yii\EventDispatcher\Provider\object>.

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...
56
        $this->assertCount(1, $listeners);
57
    }
58
}
59
60
function handle(CustomEvent $event)
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...
61
{
62
    // do nothing
63
}
64