Skip to content

Commit 48d2fe2

Browse files
committed
Skeleton for testing Client
1 parent 76d6f43 commit 48d2fe2

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Clue\React\Ami\Protocol\Event;
66
use Clue\React\Ami\Protocol\Action;
77
use Evenement\EventEmitter;
8-
use React\Stream\Stream;
8+
use React\Stream\StreamInterface;
99
use Clue\React\Ami\Protocol\Parser;
1010
use React\Promise\Deferred;
1111
use Exception;
@@ -19,7 +19,7 @@ class Client extends EventEmitter
1919
private $pending = array();
2020
private $ending = false;
2121

22-
public function __construct(Stream $stream, Parser $parser = null)
22+
public function __construct(StreamInterface $stream, Parser $parser = null)
2323
{
2424
if ($parser === null) {
2525
$parser = new Parser();

tests/ClientTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use React\Stream\Stream;
4+
use Clue\React\Ami\Protocol\Parser;
5+
use Clue\React\Ami\Client;
6+
use React\Stream\ThroughStream;
7+
8+
class ClientTest extends TestCase
9+
{
10+
public function testClosingStreamClosesClient()
11+
{
12+
$stream = new ThroughStream();
13+
14+
$client = new Client($stream);
15+
16+
$client->on('close', $this->expectCallableOnce());
17+
18+
$stream->close();
19+
//$stream->emit('close', array($this));
20+
}
21+
}

tests/bootstrap.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,36 @@
44

55
class TestCase extends PHPUnit_Framework_TestCase
66
{
7+
protected function expectCallableOnce()
8+
{
9+
$mock = $this->createCallableMock();
710

11+
if (func_num_args() > 0) {
12+
$mock
13+
->expects($this->once())
14+
->method('__invoke')
15+
->with($this->equalTo(func_get_arg(0)));
16+
} else {
17+
$mock
18+
->expects($this->once())
19+
->method('__invoke');
20+
}
21+
22+
return $mock;
23+
}
24+
25+
/**
26+
* @link https://github.com/reactphp/react/blob/master/tests/React/Tests/Socket/TestCase.php (taken from reactphp/react)
27+
*/
28+
protected function createCallableMock()
29+
{
30+
return $this->getMock('CallableStub');
31+
}
32+
}
33+
34+
class CallableStub
35+
{
36+
public function __invoke()
37+
{
38+
}
839
}

0 commit comments

Comments
 (0)