forked from clue/reactphp-ami
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionalTest.php
More file actions
110 lines (88 loc) · 2.82 KB
/
FunctionalTest.php
File metadata and controls
110 lines (88 loc) · 2.82 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
<?php
namespace Clue\Tests\React\Ami;
use Clue\React\Ami\ActionSender;
use Clue\React\Ami\Client;
use Clue\React\Ami\Factory;
use Clue\React\Ami\Protocol\Response;
use React\EventLoop\Loop;
class FunctionalTest extends TestCase
{
private static $address = false;
private static $loop;
/**
* @beforeClass
*/
public static function setUpLoopBeforeClass()
{
self::$address = getenv('LOGIN');
}
/**
* @before
*/
public function setUpSkipTest()
{
if (self::$address === false) {
$this->markTestSkipped('No ENV named LOGIN found. Please use "export LOGIN=\'user:pass@host\'.');
}
}
public function testConnection()
{
$factory = new Factory();
$client = \React\Async\await($factory->createClient(self::$address));
assert($client instanceof Client);
// let loop tick for reactphp/async v4 to clean up any remaining references
// @link https://github.com/reactphp/async/pull/65 reported upstream // TODO remove me once merged
if (function_exists('React\Async\async')) {
\React\Async\delay(0.0);
}
$this->assertFalse($client->isBusy());
return $client;
}
/**
* @depends testConnection
* @param Client $client
*/
public function testPing(Client $client)
{
$sender = new ActionSender($client);
$pong = \React\Async\await($sender->ping());
$this->assertInstanceOf('Clue\React\Ami\Protocol\Response', $pong);
}
/**
* @depends testConnection
* @param Client $client
*/
public function testInvalidCommandGetsRejected(Client $client)
{
$this->setExpectedException('Exception');
\React\Async\await($client->request($client->createAction('Invalid')));
}
/**
* @depends testConnection
* @param Client $client
*/
public function testActionSenderLogoffDisconnects(Client $client)
{
$sender = new ActionSender($client);
$ret = \React\Async\await($sender->logoff());
assert($ret instanceof Response);
// let loop tick for reactphp/async v4 to clean up any remaining references
// @link https://github.com/reactphp/async/pull/65 reported upstream // TODO remove me once merged
if (function_exists('React\Async\async')) {
\React\Async\delay(0.0);
}
$this->assertFalse($client->isBusy());
//$client->on('close', $this->expectCallableOnce());
Loop::run();
return $client;
}
/**
* @depends testActionSenderLogoffDisconnects
* @param Client $client
*/
public function testSendRejectedAfterClose(Client $client)
{
$this->setExpectedException('Exception');
\React\Async\await($client->request($client->createAction('Ping')));
}
}