diff --git a/src/Event/Event.php b/src/Event/Event.php index 62f206290a1..5e0495806d7 100644 --- a/src/Event/Event.php +++ b/src/Event/Event.php @@ -74,9 +74,9 @@ class Event * * @param string $name Name of the event * @param object|null $subject the object that this event applies to (usually the object that is generating the event) - * @param array|null $data any value you wish to be transported with this event to it can be read by listeners + * @param array|\ArrayAccess|null $data any value you wish to be transported with this event to it can be read by listeners */ - public function __construct($name, $subject = null, array $data = null) + public function __construct($name, $subject = null, $data = null) { $this->_name = $name; $this->_data = (array)$data; diff --git a/tests/TestCase/Event/EventTest.php b/tests/TestCase/Event/EventTest.php index bfdf3370233..05bd9414314 100644 --- a/tests/TestCase/Event/EventTest.php +++ b/tests/TestCase/Event/EventTest.php @@ -18,6 +18,7 @@ */ namespace Cake\Test\TestCase\Event; +use ArrayObject; use Cake\Event\Event; use Cake\TestSuite\TestCase; @@ -87,6 +88,23 @@ public function testEventData() $this->assertNull($event->getData('undef')); } + /** + * Tests that it is possible to get/set custom data in a event + * + * @return void + * @triggers fake.event $this, array('some' => 'data') + */ + public function testEventDataObject() + { + $data = new ArrayObject(['some' => 'data']); + $event = new Event('fake.event', $this, $data); + $this->assertEquals(['some' => 'data'], $event->data()); + $this->assertEquals(['some' => 'data'], $event->getData()); + + $this->assertEquals('data', $event->getData('some')); + $this->assertNull($event->getData('undef')); + } + /** * Tests that it is possible to get the name and subject directly *