-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathRunnerTest.php
More file actions
124 lines (105 loc) · 3.74 KB
/
Copy pathRunnerTest.php
File metadata and controls
124 lines (105 loc) · 3.74 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
122
123
124
<?php
/**
* Copyright (C) 2014-2026 Textalk and contributors.
* This file is part of Websocket PHP and is free software under the ISC License.
*/
declare(strict_types=1);
namespace WebSocket\Test\Runtime;
use Phrity\Net\Mock\StreamFactory;
use PHPUnit\Framework\TestCase;
use WebSocket\Exception\RunnerException;
use WebSocket\Runtime\Runner;
use WebSocket\Test\{
MockStreamContainer,
MockStreamTrait,
};
/**
* Test case for WebSocket\Runtime\Runner
*/
class RunnerTest extends TestCase
{
use MockStreamTrait;
public function setUp(): void
{
$this->setUpStack();
}
public function tearDown(): void
{
$this->tearDownStack();
}
public function testHandling(): void
{
$this->expectStreamFactory();
$factory = new StreamFactory();
$this->expectStreamFactoryCreateStreamCollection();
$this->expectStreamCollection();
$runner = new Runner($factory);
$this->expectStreamFactoryCreateStream();
$this->expectStreamFactoryCreateStreamFromResource();
$this->expectStream();
$this->expectStreamGetMetadata();
$this->expectContext();
$streamContainer = new MockStreamContainer($factory);
$this->expectStreamCollectionAttach();
$runner->attach($streamContainer, function () {
// ignore
}, $streamContainer->getIdentity());
$this->expectStreamCollectionWaitRead();
$this->expectStreamCollection();
$runner->handle(0);
$this->expectStreamCollectionDetach();
$runner->detach($streamContainer->getIdentity());
}
public function testIdentityConflictResolvable(): void
{
$this->expectStreamFactory();
$factory = new StreamFactory();
$this->expectStreamFactoryCreateStreamCollection();
$this->expectStreamCollection();
$runner = new Runner($factory);
$this->expectStreamFactoryCreateStream();
$this->expectStreamFactoryCreateStreamFromResource();
$this->expectStream();
$this->expectStreamGetMetadata();
$this->expectContext();
$streamContainer = new MockStreamContainer($factory);
$this->expectStreamCollectionAttach();
$runner->attach($streamContainer, function () {
// ignore
}, $streamContainer->getIdentity());
$this->expectStreamIsReadable()->setReturn(function () {
return false;
});
$this->expectStreamCollectionDetach();
$this->expectStreamCollectionAttach();
$runner->attach($streamContainer, function () {
// ignore
}, $streamContainer->getIdentity());
}
public function testIdentityConflict(): void
{
$this->expectStreamFactory();
$factory = new StreamFactory();
$this->expectStreamFactoryCreateStreamCollection();
$this->expectStreamCollection();
$runner = new Runner($factory);
$this->expectStreamFactoryCreateStream();
$this->expectStreamFactoryCreateStreamFromResource();
$this->expectStream();
$this->expectStreamGetMetadata();
$this->expectContext();
$streamContainer = new MockStreamContainer($factory);
$this->expectStreamCollectionAttach();
$runner->attach($streamContainer, function () {
// ignore
}, $streamContainer->getIdentity());
$this->expectStreamIsReadable()->setReturn(function () {
return true;
});
$this->expectException(RunnerException::class);
$this->expectExceptionMessage('Stream container with identity mock-stream-container already attached');
$runner->attach($streamContainer, function () {
// ignore
}, $streamContainer->getIdentity());
}
}