Browse Source

Merge branch 'event-bug' into 3.next

Closes #14357
Mark Story 6 years ago
parent
commit
6ec5cfe384

+ 2 - 2
src/Event/EventManager.php

@@ -342,10 +342,10 @@ class EventManager implements EventManagerInterface
      * Calls a listener.
      *
      * @param callable $listener The listener to trigger.
-     * @param \Cake\Event\Event $event Event instance.
+     * @param \Cake\Event\EventInterface $event Event instance.
      * @return mixed The result of the $listener function.
      */
-    protected function _callListener(callable $listener, Event $event)
+    protected function _callListener(callable $listener, EventInterface $event)
     {
         $data = $event->getData();
 

+ 15 - 0
tests/TestCase/Event/EventManagerTest.php

@@ -19,6 +19,7 @@ use Cake\Event\EventList;
 use Cake\Event\EventListenerInterface;
 use Cake\Event\EventManager;
 use Cake\TestSuite\TestCase;
+use TestApp\Event\TestEvent;
 
 /**
  * Mock class used to test event dispatching
@@ -96,6 +97,20 @@ class EventManagerTest extends TestCase
 {
 
     /**
+     * @return void
+     */
+    public function testCustomEventImplementation()
+    {
+        $event = new TestEvent('fake.event');
+        $listener = new CustomTestEventListenerInterface();
+
+        $manager = new EventManager();
+        $manager->on($listener);
+        $manager->dispatch($event);
+        $this->assertCount(1, $manager->listeners('fake.event'));
+    }
+
+    /**
      * Tests the attach() method for a single event key in multiple queues
      *
      * @group deprecated

+ 84 - 0
tests/test_app/TestApp/Event/TestEvent.php

@@ -0,0 +1,84 @@
+<?php
+namespace TestApp\Event;
+
+use Cake\Event\EventInterface;
+
+/**
+ * TestEvent
+ */
+class TestEvent implements EventInterface
+{
+    /**
+     * @var string
+     */
+    protected $name;
+
+    /**
+     * @param string $name
+     */
+    public function __construct($name)
+    {
+        $this->name = $name;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getSubject()
+    {
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function stopPropagation()
+    {
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function isStopped()
+    {
+        return false;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getResult()
+    {
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function setResult($value = null)
+    {
+        return $this;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getData($key = null)
+    {
+        return [];
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function setData($key, $value = null)
+    {
+        return $this;
+    }
+}