ソースを参照

Fix phpstan warnings and actual mistakes.

Mark Story 8 年 前
コミット
40fe576bd7

+ 6 - 5
src/Console/CommandRunner.php

@@ -207,13 +207,14 @@ class CommandRunner implements EventDispatcherInterface
      * If the application does not support events and this method is used as
      * a setter, an exception will be raised.
      *
-     * @param \Cake\Event\EventManagerInterface $events The event manager to set.
-     * @return \Cake\Event\EventManagerInterface|$this
-     * @deprecated Will be removed in 4.0
+     * @param \Cake\Event\EventManager|null $events The event manager to set.
+     * @return \Cake\Event\EventManager|$this
+     * @deprecated 3.6.0 Will be removed in 4.0
      */
     public function eventManager(EventManager $events = null)
     {
-        if ($eventManager === null) {
+        deprecationWarning('eventManager() is deprecated. Use getEventManager()/setEventManager() instead.');
+        if ($events === null) {
             return $this->getEventManager();
         }
 
@@ -226,7 +227,7 @@ class CommandRunner implements EventDispatcherInterface
      * If the application does not support events and this method is used as
      * a setter, an exception will be raised.
      *
-     * @param \Cake\Event\EventManagerInterface $events The event manager to set.
+     * @param \Cake\Event\EventManager $events The event manager to set.
      * @return $this
      */
     public function setEventManager(EventManager $events)

+ 6 - 5
src/Http/Server.php

@@ -184,13 +184,14 @@ class Server implements EventDispatcherInterface
      * If the application does not support events and this method is used as
      * a setter, an exception will be raised.
      *
-     * @param \Cake\Event\EventManagerInterface $events The event manager to set.
-     * @return \Cake\Event\EventManagerInterface|$this
-     * @deprecated Will be removed in 4.0
+     * @param \Cake\Event\EventManager|null $events The event manager to set.
+     * @return \Cake\Event\EventManager|$this
+     * @deprecated 3.6.0 Will be removed in 4.0
      */
     public function eventManager(EventManager $events = null)
     {
-        if ($eventManager === null) {
+        deprecationWarning('eventManager() is deprecated. Use getEventManager()/setEventManager() instead.');
+        if ($events === null) {
             return $this->getEventManager();
         }
 
@@ -203,7 +204,7 @@ class Server implements EventDispatcherInterface
      * If the application does not support events and this method is used as
      * a setter, an exception will be raised.
      *
-     * @param \Cake\Event\EventManagerInterface $events The event manager to set.
+     * @param \Cake\Event\EventManager $events The event manager to set.
      * @return $this
      */
     public function setEventManager(EventManager $events)

+ 15 - 0
tests/TestCase/Console/CommandRunnerTest.php

@@ -99,6 +99,21 @@ class CommandRunnerTest extends TestCase
     }
 
     /**
+     * test deprecated method defined in interface
+     *
+     * @return void
+     */
+    public function testEventManagerCompat()
+    {
+        $this->deprecated(function () {
+            $app = $this->createMock(ConsoleApplicationInterface::class);
+
+            $runner = new CommandRunner($app);
+            $this->assertSame(EventManager::instance(), $runner->eventManager());
+        });
+    }
+
+    /**
      * Test that the console hook not returning a command collection
      * raises an error.
      *

+ 15 - 0
tests/TestCase/Http/ServerTest.php

@@ -324,4 +324,19 @@ class ServerTest extends TestCase
         $server = new Server($app);
         $server->setEventManager($events);
     }
+
+    /**
+     * test deprecated method defined in interface
+     *
+     * @return void
+     */
+    public function testEventManagerCompat()
+    {
+        $this->deprecated(function () {
+            $app = $this->createMock(HttpApplicationInterface::class);
+
+            $server = new Server($app);
+            $this->assertSame(EventManager::instance(), $server->eventManager());
+        });
+    }
 }