This repository was archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathProtocolTest.php
More file actions
121 lines (109 loc) · 3.04 KB
/
ProtocolTest.php
File metadata and controls
121 lines (109 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace DNode;
class ProtocolTest extends TestCase
{
public function setUp()
{
$this->protocol = new Protocol(new Dog());
}
/**
* @test
* @covers DNode\Protocol::__construct
* @covers DNode\Protocol::create
*/
public function createShouldReturnSession()
{
$session = $this->protocol->create();
$this->assertInstanceOf('DNode\Session', $session);
}
/**
* @test
* @covers DNode\Protocol::destroy
*/
public function destroyShouldUnsetSession()
{
$session = $this->protocol->create();
$this->protocol->destroy($session->id);
}
/**
* @test
* @covers DNode\Protocol::end
*/
public function endShouldCallEndOnAllSessions()
{
$sessions = array(
$this->protocol->create(),
$this->protocol->create(),
);
foreach ($sessions as $session) {
$session->on('end', $this->expectCallableOnce());
}
$this->protocol->end();
}
/**
* @test
* @covers DNode\Protocol::parseArgs
* @dataProvider provideParseArgs
*/
public function parseArgsShouldParseArgsCorrectly($expected, $args)
{
$this->assertSame($expected, $this->protocol->parseArgs($args));
}
public function provideParseArgs()
{
$closure = function () {};
$server = new ServerStub();
$obj = new \stdClass();
$obj->foo = 'bar';
$obj->baz = 'qux';
$arr = array(
'quux' => 'corge',
'grault' => 'garply'
);
return array(
'string number becomes port' => array(
array('port' => '8080'),
array('8080'),
),
'leading / becomes path' => array(
array('path' => '/foo'),
array('/foo'),
),
'string becomes host' => array(
array('host' => 'foo'),
array('foo'),
),
'integer becomes port' => array(
array('port' => 8080),
array(8080),
),
'array becomes merged' => array(
array('quux' => 'corge', 'grault' => 'garply'),
array($arr),
),
'Closure becomes block' => array(
array('block' => $closure),
array($closure),
),
'ServerInterface becomes server' => array(
array('server' => $server),
array($server),
),
'random object becomes key => val' => array(
array('foo' => 'bar', 'baz' => 'qux'),
array($obj),
),
);
}
/**
* @test
* @covers DNode\Protocol::parseArgs
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Not sure what to do about boolean arguments
*/
public function parseArgsShouldRejectInvalidArgs()
{
$args = array(true);
$this->protocol->parseArgs($args);
}
}