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.
Completed
Branch master (70f706)
by Navarr
02:05 queued 19s
created

ServerTest::testAddingSameHookMultipleTimesWorksProperly()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 13
nc 2
nop 1
1
<?php
2
3
namespace Navarr\Socket\Test;
4
5
use Navarr\Socket\Server;
6
7
class ServerTest extends \PHPUnit_Framework_TestCase
8
{
9
    public function testAddingSingleHookWorksProperly()
10
    {
11
        $server = new Server('127.0.0.1', 9000);
12
        $exampleReturn = '__NAVARR_SOCKET_TEST_EXAMPLE_RETURN__';
13
        $server->addHook(
14
            Server::HOOK_CONNECT,
15
            function () {
16
                return '__NAVARR_SOCKET_TEST_EXAMPLE_RETURN__';
17
            }
18
        );
19
20
        $serverClass = new \ReflectionClass($server);
21
        $hooksProperty = $serverClass->getProperty('hooks');
22
        $hooksProperty->setAccessible(true);
23
24
        $hooks = $hooksProperty->getValue($server);
25
26
        // Hooks should be a protected property
27
        $this->assertTrue($hooksProperty->isProtected());
28
        // Hooks should be an array
29
        $this->assertTrue(is_array($hooks));
30
        // Hooks should have a single callable in $hooks[Server::HOOK_CONNECT]
31
        $this->assertEquals(1, count($hooks[Server::HOOK_CONNECT]));
32
        // Values in $hooks[Server::HOOK_CONNECT] should be callables
33
        $this->assertTrue(is_callable($hooks[Server::HOOK_CONNECT][0]));
34
        // Make sure the callable in $hooks[Server::HOOK_CONNECT] is the return value we expect
35
        $this->assertEquals($exampleReturn, call_user_func($hooks[Server::HOOK_CONNECT][0]));
36
37
        return $server;
38
    }
39
40
    /**
41
     * @param Server $server
42
     *
43
     * @depends testAddingSingleHookWorksProperly
44
     *
45
     * @return Server
46
     */
47
    public function testAddingMultipleHooksWorksProperly($server)
48
    {
49
        $server->addHook(
50
            Server::HOOK_CONNECT,
51
            function () {
52
                return '__NAVARR_SOCKET_TEST_EXAMPLE_RETURN_2__';
53
            }
54
        );
55
56
        $serverClass = new \ReflectionClass($server);
57
        $hooksProperty = $serverClass->getProperty('hooks');
58
        $hooksProperty->setAccessible(true);
59
60
        $hooks = $hooksProperty->getValue($server);
61
62
        // Hooks should have two callables in $hooks[Server::HOOK_CONNECT]
63
        $this->assertEquals(2, count($hooks[Server::HOOK_CONNECT]));
64
        // Values in $hooks[Server::HOOK_CONNECT] should be callables
65
        foreach ($hooks[Server::HOOK_CONNECT] as $callable) {
66
            $this->assertTrue(is_callable($callable));
67
        }
68
        // Make sure the callable in $hooks[Server::HOOK_CONNECT] is the return value we expect
69
        $this->assertEquals('__NAVARR_SOCKET_TEST_EXAMPLE_RETURN_2__', call_user_func($hooks[Server::HOOK_CONNECT][1]));
70
71
        return $server;
72
    }
73
74
    /**
75
     * @param Server $server
76
     *
77
     * @depends testAddingMultipleHooksWorksProperly
78
     */
79
    public function testAddingSameHookMultipleTimesWorksProperly($server)
80
    {
81
        $callable = function () {
82
            return '__NAVARR_SOCKET_TEST_EXAMPLE_RETURN_3__';
83
        };
84
        $server->addHook(Server::HOOK_CONNECT, $callable);
85
        $server->addHook(Server::HOOK_CONNECT, $callable);
86
87
        $serverClass = new \ReflectionClass($server);
88
        $hooksProperty = $serverClass->getProperty('hooks');
89
        $hooksProperty->setAccessible(true);
90
91
        $hooks = $hooksProperty->getValue($server);
92
93
        // Hooks should have two callables in $hooks[Server::HOOK_CONNECT]
94
        $this->assertEquals(3, count($hooks[Server::HOOK_CONNECT]));
95
        // Values in $hooks[Server::HOOK_CONNECT] should be callables
96
        foreach ($hooks[Server::HOOK_CONNECT] as $callable) {
97
            $this->assertTrue(is_callable($callable));
98
        }
99
        // Make sure the callable in $hooks[Server::HOOK_CONNECT] is the return value we expect
100
        $this->assertEquals('__NAVARR_SOCKET_TEST_EXAMPLE_RETURN_3__', call_user_func($hooks[Server::HOOK_CONNECT][2]));
101
    }
102
}
103