Skip to content
Permalink
Browse files

Adding another test for the ConditionDecorator

  • Loading branch information...
burzum committed Jun 28, 2016
1 parent 6a661b2 commit 52c311ef53b7598497e2ed0596dcc23f3ddcb7bb
@@ -31,7 +31,7 @@ public function __invoke()
{
$args = func_get_args();
if (!$this->canTrigger($args[0])) {
return false;
return;
}
return $this->_call($args);
}
@@ -20,6 +20,7 @@
use Cake\Event\Decorator\ConditionDecorator;
use Cake\Event\Event;
use Cake\Event\EventManager;
use Cake\TestSuite\TestCase;
/**
@@ -49,7 +50,7 @@ public function testCanTriggerIf()
$this->assertFalse($decorator->canTrigger($event));
$result = $decorator($event);
$this->assertFalse($result);
$this->assertNull($result);
$event = new Event('decorator.test', $this, ['canTrigger' => true]);
$this->assertTrue($decorator->canTrigger($event));
@@ -58,6 +59,40 @@ public function testCanTriggerIf()
$this->assertEquals('success', $result);
}
/**
* testCascadingEvents
*
* @return void
*/
public function testCascadingEvents()
{
$callable = function (Event $event) {
$event->data['counter']++;
return $event;
};
$listener1 = new ConditionDecorator($callable, [
'if' => function (Event $event) {
return false;
}
]);
$listener2 = function(Event $event) {
$event->data['counter']++;
return $event;
};
EventManager::instance()->on('decorator.test2', $listener1);
EventManager::instance()->on('decorator.test2', $listener2);
$event = new Event('decorator.test2', $this, [
'counter' => 1
]);
EventManager::instance()->dispatch($event);
$this->assertEquals(2, $event->data['counter']);
}
/**
* testCallableRuntimeException
*

0 comments on commit 52c311e

Please sign in to comment.
You can’t perform that action at this time.