GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

testImmutableHandlerContainer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Thunder\Shortcode\Tests;
3
4
use Thunder\Shortcode\HandlerContainer\HandlerContainer;
5
use Thunder\Shortcode\HandlerContainer\ImmutableHandlerContainer;
6
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
7
8
/**
9
 * @author Tomasz Kowalczyk <[email protected]>
10
 */
11
final class HandlerContainerTest extends AbstractTestCase
12
{
13
    public function testExceptionOnDuplicateHandler()
14
    {
15
        $handlers = new HandlerContainer();
16
        $handlers->add('name', function () {});
17
        $this->willThrowException('RuntimeException');
18
        $handlers->add('name', function () {});
19
    }
20
21
    public function testRemove()
22
    {
23
        $handlers = new HandlerContainer();
24
        static::assertFalse($handlers->has('code'));
25
        $handlers->add('code', function(ShortcodeInterface $s) {});
0 ignored issues
show
Unused Code introduced by
The parameter $s 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...
26
        static::assertTrue($handlers->has('code'));
27
        $handlers->remove('code');
28
        static::assertFalse($handlers->has('code'));
29
    }
30
31
    public function testRemoveException()
32
    {
33
        $handlers = new HandlerContainer();
34
        $this->willThrowException('RuntimeException');
35
        $handlers->remove('code');
36
    }
37
38
    public function testNames()
39
    {
40
        $handlers = new HandlerContainer();
41
        static::assertEmpty($handlers->getNames());
42
        $handlers->add('code', function(ShortcodeInterface $s) {});
0 ignored issues
show
Unused Code introduced by
The parameter $s 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...
43
        static::assertSame(array('code'), $handlers->getNames());
44
        $handlers->addAlias('c', 'code');
45
        static::assertSame(array('code', 'c'), $handlers->getNames());
46
    }
47
48
    public function testHandlerContainer()
49
    {
50
        $x = function () {};
51
52
        $handler = new HandlerContainer();
53
        $handler->add('x', $x);
54
        $handler->addAlias('y', 'x');
55
56
        static::assertSame($x, $handler->get('x'));
57
    }
58
59
    public function testInvalidHandler()
60
    {
61
        $handlers = new HandlerContainer();
62
        $this->willThrowException('RuntimeException');
63
        $handlers->add('invalid', new \stdClass());
0 ignored issues
show
Documentation introduced by
new \stdClass() is of type object<stdClass>, but the function expects a callable.

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...
64
    }
65
66
    public function testDefaultHandler()
67
    {
68
        $handlers = new HandlerContainer();
69
        static::assertNull($handlers->get('missing'));
70
71
        $handlers->setDefault(function () {});
72
        static::assertNotNull($handlers->get('missing'));
73
    }
74
75
    public function testExceptionIfAliasingNonExistentHandler()
76
    {
77
        $handlers = new HandlerContainer();
78
        $this->willThrowException('RuntimeException');
79
        $handlers->addAlias('m', 'missing');
80
    }
81
82
    public function testImmutableHandlerContainer()
83
    {
84
        $handlers = new HandlerContainer();
85
        $handlers->add('code', function () {});
86
        $handlers->addAlias('c', 'code');
87
        $imHandlers = new ImmutableHandlerContainer($handlers);
88
        $handlers->add('not', function() {});
89
90
        static::assertNull($imHandlers->get('missing'));
91
        static::assertNotNull($imHandlers->get('code'));
92
        static::assertNotNull($imHandlers->get('c'));
93
        static::assertNull($imHandlers->get('not'));
94
95
        $defaultHandlers = new HandlerContainer();
96
        $defaultHandlers->setDefault(function () {});
97
        $imDefaultHandlers = new ImmutableHandlerContainer($defaultHandlers);
98
        static::assertNotNull($imDefaultHandlers->get('missing'));
99
    }
100
}
101