Skip to content

Commit

Permalink
Merge pull request #10029 from robertpustulka/revert-typehint
Browse files Browse the repository at this point in the history
Revert array typehint from Event
  • Loading branch information
dereuromark committed Jan 13, 2017
2 parents fcf7c07 + 180432b commit ec7f590
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions tests/TestCase/Event/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
namespace Cake\Test\TestCase\Event;

use ArrayObject;
use Cake\Event\Event;
use Cake\TestSuite\TestCase;

Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit ec7f590

Please sign in to comment.