Skip to content
Permalink
Browse files

Minor improvements and fixes to the event decorators

  • Loading branch information...
burzum committed May 18, 2016
1 parent b607b02 commit c76c36072aa95f0af394957a12714ee02162e3a9
@@ -25,6 +25,7 @@ class ConditionDecorator extends BaseDecorator
/**
* @inheritdoc
* @return mixed
*/
public function __invoke()
{
@@ -25,6 +25,7 @@ class SubjectFilterDecorator extends BaseDecorator
/**
* @inheritdoc
* @return mixed
*/
public function __invoke()
{
@@ -14,7 +14,7 @@
*/
namespace Cake\Event;
use Cake\Event\Decorator\FilterDecorator;
use Cake\Event\Decorator\ConditionDecorator;
use InvalidArgumentException;
/**
@@ -158,14 +158,14 @@ public function on($eventKey = null, $options = [], $callable = null)
$argCount = func_num_args();
if ($argCount === 2) {
$this->_listeners[$eventKey][static::$defaultPriority][] = [
'callable' => new FilterDecorator($options),
'callable' => is_callable($options) ? new ConditionDecorator($options) : $options,
];
return;
}
if ($argCount === 3) {
$priority = isset($options['priority']) ? $options['priority'] : static::$defaultPriority;
$this->_listeners[$eventKey][$priority][] = [
'callable' => new FilterDecorator($callable, $options)
'callable' => is_callable($callable) ? new ConditionDecorator($callable, $options) : $callable
];
return;
}
@@ -35,16 +35,13 @@ class ConditionDecoratorTest extends TestCase
*/
public function testCanTriggerIf()
{
$callable = function(Event $event) {
$callable = function (Event $event) {
return 'success';
};
$decorator = new ConditionDecorator($callable, [
'if' => function(Event $event) {
if (isset($event->data['canTrigger'])) {
return true;
}
return false;
'if' => function (Event $event) {
return $event->data['canTrigger'];
}
]);
@@ -65,10 +62,11 @@ public function testCanTriggerIf()
* testCallableRuntimeException
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Cake\Event\Decorator\ConditionDecorator the `if` condition is not a callable!
*/
public function testCallableRuntimeException()
{
$callable = function(Event $event) {
$callable = function (Event $event) {
return 'success';
};
@@ -18,8 +18,8 @@
*/
namespace Cake\Test\TestCase\Event;
use Cake\Event\Event;
use Cake\Event\Decorator\SubjectFilterDecorator;
use Cake\Event\Event;
use Cake\TestSuite\TestCase;
/**
@@ -36,7 +36,7 @@ class SubjectFilterDecoratorTest extends TestCase
public function testCanTrigger()
{
$event = new Event('decorator.test', $this);
$callable = function(Event $event) {
$callable = function (Event $event) {
return 'success';
};

0 comments on commit c76c360

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