Permalink
Browse files

Add unit tests for PairApp

  • Loading branch information...
1 parent 06e9f3a commit 446126b28c771f3c49974b59d26df37a8c0cf81c @igorw igorw committed Nov 4, 2012
Showing with 106 additions and 0 deletions.
  1. +10 −0 tests/React/Chatroulette/CallableStub.php
  2. +96 −0 tests/React/Chatroulette/PairAppTest.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace React\Chatroulette;
+
+class CallableStub
+{
+ public function __invoke()
+ {
+ }
+}
@@ -0,0 +1,96 @@
+<?php
+
+namespace React\Chatroulette;
+
+use React\Socket\ConnectionInterface;
+
+class PairAppTest extends \PHPUnit_Framework_TestCase
+{
+ private $app;
+
+ public function setUp()
+ {
+ $this->app = new PairApp();
+ }
+
+ /** @test */
+ public function connectingOneUserShouldMakeHimWait()
+ {
+ $alice = new ConnectionStub();
+ $alice->id = 'Alice';
+ $alice->on('wait', $this->expectCallableOnce());
+
+ $this->app->connect($alice);
+ }
+
+ /** @test */
+ public function connectingTwoUsersShouldPairThemUp()
+ {
+ $alice = new ConnectionStub();
+ $alice->id = 'Alice';
+ $alice->on('pipe', $this->expectCallableOnce());
+
+ $bob = new ConnectionStub();
+ $bob->id = 'Bob';
+ $bob->on('pipe', $this->expectCallableOnce());
+
+ $this->app->connect($alice);
+ $this->app->connect($bob);
+ }
+
+ /** @test */
+ public function connectingThreeUsersShouldMakeTheThirdOneWait()
+ {
+ $alice = new ConnectionStub();
+ $alice->id = 'Alice';
+
+ $bob = new ConnectionStub();
+ $bob->id = 'Bob';
+
+ $carol = new ConnectionStub();
+ $carol->id = 'Carol';
+ $carol->on('wait', $this->expectCallableOnce());
+
+ $this->app->connect($alice);
+ $this->app->connect($bob);
+ $this->app->connect($carol);
+ }
+
+ /** @test */
+ public function connectingFourUsersShouldPairThemUpInPairs()
+ {
+ $alice = new ConnectionStub();
+ $alice->id = 'Alice';
+
+ $bob = new ConnectionStub();
+ $bob->id = 'Bob';
+
+ $carol = new ConnectionStub();
+ $carol->id = 'Carol';
+ $carol->on('pipe', $this->expectCallableOnce());
+
+ $dan = new ConnectionStub();
+ $dan->id = 'Dan';
+ $dan->on('pipe', $this->expectCallableOnce());
+
+ $this->app->connect($alice);
+ $this->app->connect($bob);
+ $this->app->connect($carol);
+ $this->app->connect($dan);
+ }
+
+ protected function expectCallableOnce()
+ {
+ $mock = $this->createCallableMock();
+ $mock
+ ->expects($this->once())
+ ->method('__invoke');
+
+ return $mock;
+ }
+
+ protected function createCallableMock()
+ {
+ return $this->getMock('React\Chatroulette\CallableStub');
+ }
+}

0 comments on commit 446126b

Please sign in to comment.