full tests

This commit is contained in:
Trismegiste 2013-05-12 22:20:12 +02:00
parent 71a43e2e93
commit f92be4efec
2 changed files with 46 additions and 3 deletions

View File

@ -51,6 +51,7 @@ abstract class Handler
*/
final public function handle(Request $req)
{
$req->forDebugOnly = get_called_class();
$processed = $this->processing($req);
if (!$processed) {
// the request has not been processed by this handler => see the next

View File

@ -23,14 +23,56 @@ class ChainTest extends \PHPUnit_Framework_TestCase
$this->chain->append(new Responsible\SlowStorage(array('bar' => 'baz', 'foo' => 'bar')));
}
public function testProcess()
public function makeRequest()
{
$request = new Request();
$request->verb = 'get';
$request->key = 'bar';
return array(
array($request)
);
}
/**
* @dataProvider makeRequest
*/
public function testFastStorage($request)
{
$request->key = 'bar';
$ret = $this->chain->handle($request);
print_r($request);
$this->assertTrue($ret);
$this->assertObjectHasAttribute('response', $request);
$this->assertEquals('baz', $request->response);
// despite both handle owns the 'bar' key, the FastStorage is responding first
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\FastStorage', $request->forDebugOnly);
}
/**
* @dataProvider makeRequest
*/
public function testSlowStorage($request)
{
$request->key = 'foo';
$ret = $this->chain->handle($request);
$this->assertTrue($ret);
$this->assertObjectHasAttribute('response', $request);
$this->assertEquals('bar', $request->response);
// FastStorage has no 'foo' key, the SlowStorage is responding
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly);
}
/**
* @dataProvider makeRequest
*/
public function testFailure($request)
{
$request->key = 'kurukuku';
$ret = $this->chain->handle($request);
$this->assertFalse($ret);
// the last rsponsible :
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly);
}
}