Skip to content
Permalink
Browse files

fix usage of data and result on some event objects

  • Loading branch information...
thinkingmedia
thinkingmedia committed Aug 30, 2016
1 parent 246682d commit 9e06527bee808a8fb15d60c28d27519d346d83c1
@@ -59,7 +59,7 @@ public function checkRules(EntityInterface $entity, $operation = RulesChecker::C
compact('entity', 'options', 'operation')
);
if ($event->isStopped()) {
return $event->result;
return $event->result();
}
}
@@ -72,7 +72,7 @@ public function checkRules(EntityInterface $entity, $operation = RulesChecker::C
);
if ($event->isStopped()) {
return $event->result;
return $event->result();
}
}
@@ -78,6 +78,9 @@ public function matches($other)
return false;
}
/**
* @var Event[] $events
*/
$events = $eventGroup[$other];
if (count($events) > 1) {
@@ -86,7 +89,7 @@ public function matches($other)
$event = $events[0];
if (array_key_exists($this->_dataKey, $event->data) === false) {
if (array_key_exists($this->_dataKey, $event->data()) === false) {
return false;
}
@@ -14,6 +14,7 @@
namespace Cake\Test\TestCase\Event;
use Cake\Event\EventDispatcherTrait;
use Cake\Event\EventManager;
use Cake\TestSuite\TestCase;
@@ -22,6 +23,10 @@
*/
class EventDispatcherTraitTest extends TestCase
{
/**
* @var EventDispatcherTrait
*/
public $subject;
/**
* setup
@@ -70,8 +75,8 @@ public function testDispatchEvent()
$event = $this->subject->dispatchEvent('some.event', ['foo' => 'bar']);
$this->assertInstanceOf('Cake\Event\Event', $event);
$this->assertSame($this->subject, $event->subject);
$this->assertEquals('some.event', $event->name);
$this->assertEquals(['foo' => 'bar'], $event->data);
$this->assertSame($this->subject, $event->subject());
$this->assertEquals('some.event', $event->name());
$this->assertEquals(['foo' => 'bar'], $event->data());
}
}
@@ -684,10 +684,12 @@ public function testDispatchGlobalBeforeLocal()
/**
* test callback
*
* @param Event $event
*/
public function onMyEvent($event)
public function onMyEvent(Event $event)
{
$event->data['callback'] = 'ok';
$event->setData('callback', 'ok');
}
/**
@@ -698,7 +700,7 @@ public function onMyEvent($event)
public function testDispatchLocalHandledByGlobal()
{
$callback = [$this, 'onMyEvent'];
EventManager::instance()->attach($callback, 'my_event');
EventManager::instance()->on('my_event', $callback);
$manager = new EventManager();
$event = new Event('my_event', $manager);
$manager->dispatch($event);
@@ -715,10 +717,10 @@ public function testDispatchLocalHandledByGlobal()
public function testDispatchWithGlobalAndLocalEvents()
{
$listener = new CustomTestEventListenerInterface();
EventManager::instance()->attach($listener);
EventManager::instance()->on($listener);
$listener2 = new EventTestListener();
$manager = new EventManager();
$manager->attach([$listener2, 'listenerFunction'], 'fake.event');
$manager->on('fake.event', [$listener2, 'listenerFunction']);
$manager->dispatch(new Event('fake.event', $this));
$this->assertEquals(['listenerFunction'], $listener->callList);
@@ -16,6 +16,7 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Datasource\ConnectionManager;
use Cake\Event\Event;
use Cake\ORM\Association\BelongsToMany;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;

0 comments on commit 9e06527

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