Skip to content

Commit f92be4e

Browse files
author
Trismegiste
committed
full tests
1 parent 71a43e2 commit f92be4e

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

ChainOfResponsibilities/Handler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ final public function append(Handler $handler)
5151
*/
5252
final public function handle(Request $req)
5353
{
54+
$req->forDebugOnly = get_called_class();
5455
$processed = $this->processing($req);
5556
if (!$processed) {
5657
// the request has not been processed by this handler => see the next

Tests/ChainOfResponsibilities/ChainTest.php

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,56 @@ protected function setUp()
2323
$this->chain->append(new Responsible\SlowStorage(array('bar' => 'baz', 'foo' => 'bar')));
2424
}
2525

26-
public function testProcess()
26+
public function makeRequest()
2727
{
2828
$request = new Request();
2929
$request->verb = 'get';
30+
return array(
31+
array($request)
32+
);
33+
}
34+
35+
/**
36+
* @dataProvider makeRequest
37+
*/
38+
public function testFastStorage($request)
39+
{
3040
$request->key = 'bar';
41+
$ret = $this->chain->handle($request);
3142

43+
$this->assertTrue($ret);
44+
$this->assertObjectHasAttribute('response', $request);
45+
$this->assertEquals('baz', $request->response);
46+
// despite both handle owns the 'bar' key, the FastStorage is responding first
47+
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\FastStorage', $request->forDebugOnly);
48+
}
49+
50+
/**
51+
* @dataProvider makeRequest
52+
*/
53+
public function testSlowStorage($request)
54+
{
55+
$request->key = 'foo';
3256
$ret = $this->chain->handle($request);
33-
print_r($request);
57+
58+
$this->assertTrue($ret);
59+
$this->assertObjectHasAttribute('response', $request);
60+
$this->assertEquals('bar', $request->response);
61+
// FastStorage has no 'foo' key, the SlowStorage is responding
62+
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly);
63+
}
64+
65+
/**
66+
* @dataProvider makeRequest
67+
*/
68+
public function testFailure($request)
69+
{
70+
$request->key = 'kurukuku';
71+
$ret = $this->chain->handle($request);
72+
73+
$this->assertFalse($ret);
74+
// the last rsponsible :
75+
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\SlowStorage', $request->forDebugOnly);
3476
}
3577

3678
}

0 commit comments

Comments
 (0)