Skip to content

Commit 446126b

Browse files
committed
Add unit tests for PairApp
1 parent 06e9f3a commit 446126b

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace React\Chatroulette;
4+
5+
class CallableStub
6+
{
7+
public function __invoke()
8+
{
9+
}
10+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace React\Chatroulette;
4+
5+
use React\Socket\ConnectionInterface;
6+
7+
class PairAppTest extends \PHPUnit_Framework_TestCase
8+
{
9+
private $app;
10+
11+
public function setUp()
12+
{
13+
$this->app = new PairApp();
14+
}
15+
16+
/** @test */
17+
public function connectingOneUserShouldMakeHimWait()
18+
{
19+
$alice = new ConnectionStub();
20+
$alice->id = 'Alice';
21+
$alice->on('wait', $this->expectCallableOnce());
22+
23+
$this->app->connect($alice);
24+
}
25+
26+
/** @test */
27+
public function connectingTwoUsersShouldPairThemUp()
28+
{
29+
$alice = new ConnectionStub();
30+
$alice->id = 'Alice';
31+
$alice->on('pipe', $this->expectCallableOnce());
32+
33+
$bob = new ConnectionStub();
34+
$bob->id = 'Bob';
35+
$bob->on('pipe', $this->expectCallableOnce());
36+
37+
$this->app->connect($alice);
38+
$this->app->connect($bob);
39+
}
40+
41+
/** @test */
42+
public function connectingThreeUsersShouldMakeTheThirdOneWait()
43+
{
44+
$alice = new ConnectionStub();
45+
$alice->id = 'Alice';
46+
47+
$bob = new ConnectionStub();
48+
$bob->id = 'Bob';
49+
50+
$carol = new ConnectionStub();
51+
$carol->id = 'Carol';
52+
$carol->on('wait', $this->expectCallableOnce());
53+
54+
$this->app->connect($alice);
55+
$this->app->connect($bob);
56+
$this->app->connect($carol);
57+
}
58+
59+
/** @test */
60+
public function connectingFourUsersShouldPairThemUpInPairs()
61+
{
62+
$alice = new ConnectionStub();
63+
$alice->id = 'Alice';
64+
65+
$bob = new ConnectionStub();
66+
$bob->id = 'Bob';
67+
68+
$carol = new ConnectionStub();
69+
$carol->id = 'Carol';
70+
$carol->on('pipe', $this->expectCallableOnce());
71+
72+
$dan = new ConnectionStub();
73+
$dan->id = 'Dan';
74+
$dan->on('pipe', $this->expectCallableOnce());
75+
76+
$this->app->connect($alice);
77+
$this->app->connect($bob);
78+
$this->app->connect($carol);
79+
$this->app->connect($dan);
80+
}
81+
82+
protected function expectCallableOnce()
83+
{
84+
$mock = $this->createCallableMock();
85+
$mock
86+
->expects($this->once())
87+
->method('__invoke');
88+
89+
return $mock;
90+
}
91+
92+
protected function createCallableMock()
93+
{
94+
return $this->getMock('React\Chatroulette\CallableStub');
95+
}
96+
}

0 commit comments

Comments
 (0)