Skip to content

Commit

Permalink
Make components' tests run on their own and from main repo.
Browse files Browse the repository at this point in the history
Each component has dedicated test config and bootstrap.
Duplication of parts of the skeleton is not ideal, but helps to reduce
dependencies between each test suite. Also, this eases the future
subtree split.
  • Loading branch information
clue committed May 7, 2014
1 parent c91fcd7 commit 5631171
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 6 deletions.
25 changes: 25 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
10 changes: 10 additions & 0 deletions tests/CallableStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace React\Tests\Http;

class CallableStub
{
public function __invoke()
{
}
}
63 changes: 63 additions & 0 deletions tests/ConnectionStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace React\Tests\Http;

use Evenement\EventEmitter;
use React\Socket\ConnectionInterface;
use React\Stream\WritableStreamInterface;
use React\Stream\Util;

class ConnectionStub extends EventEmitter implements ConnectionInterface
{
private $data = '';

public function isReadable()
{
return true;
}

public function isWritable()
{
return true;
}

public function pause()
{
}

public function resume()
{
}

public function pipe(WritableStreamInterface $dest, array $options = array())
{
Util::pipe($this, $dest, $options);

return $dest;
}

public function write($data)
{
$this->data .= $data;

return true;
}

public function end($data = null)
{
}

public function close()
{
}

public function getData()
{
return $this->data;
}

public function getRemoteAddress()
{
return '127.0.0.1';
}
}
1 change: 0 additions & 1 deletion tests/RequestHeaderParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace React\Tests\Http;

use React\Http\RequestHeaderParser;
use React\Tests\Socket\TestCase;

class RequestHeaderParserTest extends TestCase
{
Expand Down
1 change: 0 additions & 1 deletion tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace React\Tests\Http;

use React\Http\Request;
use React\Tests\Socket\TestCase;

class RequestTest extends TestCase
{
Expand Down
1 change: 0 additions & 1 deletion tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace React\Tests\Http;

use React\Http\Response;
use React\Tests\Socket\TestCase;

class ResponseTest extends TestCase
{
Expand Down
22 changes: 22 additions & 0 deletions tests/ServerStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace React\Tests\Http;

use Evenement\EventEmitter;
use React\Socket\ServerInterface;

class ServerStub extends EventEmitter implements ServerInterface
{
public function listen($port, $host = '127.0.0.1')
{
}

public function getPort()
{
return 80;
}

public function shutdown()
{
}
}
3 changes: 0 additions & 3 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace React\Tests\Http;

use React\Http\Server;
use React\Tests\Socket\TestCase;
use React\Tests\Socket\Stub\ServerStub;
use React\Tests\Socket\Stub\ConnectionStub;

class ServerTest extends TestCase
{
Expand Down
41 changes: 41 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace React\Tests\Http;

class TestCase extends \PHPUnit_Framework_TestCase
{
protected function expectCallableExactly($amount)
{
$mock = $this->createCallableMock();
$mock
->expects($this->exactly($amount))
->method('__invoke');

return $mock;
}

protected function expectCallableOnce()
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke');

return $mock;
}

protected function expectCallableNever()
{
$mock = $this->createCallableMock();
$mock
->expects($this->never())
->method('__invoke');

return $mock;
}

protected function createCallableMock()
{
return $this->getMock('React\Tests\Http\CallableStub');
}
}
7 changes: 7 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

$loader = @include __DIR__ . '/../vendor/autoload.php';
if (!$loader) {
$loader = require __DIR__ . '/../../../vendor/autoload.php';
}
$loader->addPsr4('React\\Tests\\Http\\', __DIR__);

0 comments on commit 5631171

Please sign in to comment.