Browse Source

Add additional test coverage.

Mark Story 8 years ago
parent
commit
214d2b2633
2 changed files with 64 additions and 1 deletions
  1. 4 1
      src/Event/EventManager.php
  2. 60 0
      tests/TestCase/Event/EventManagerTest.php

+ 4 - 1
src/Event/EventManager.php

@@ -189,7 +189,10 @@ class EventManager
 
             return $this;
         }
-        throw new InvalidArgumentException('Invalid arguments for EventManager::on().');
+        throw new InvalidArgumentException(
+            'Invalid arguments for EventManager::on(). ' .
+            "Expected 1, 2 or 3 arguments. Got {$argCount} arguments."
+        );
     }
 
     /**

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

@@ -132,6 +132,25 @@ class EventManagerTest extends TestCase
     }
 
     /**
+     * Test attach() with a listener interface.
+     *
+     * @group deprecated
+     * @return void
+     */
+    public function testAttachListener()
+    {
+        $this->deprecated(function () {
+            $manager = new EventManager();
+            $listener = new CustomTestEventListenerInterface();
+            $manager->on($listener);
+            $expected = [
+                ['callable' => [$listener, 'listenerFunction']],
+            ];
+            $this->assertEquals($expected, $manager->listeners('fake.event'));
+        });
+    }
+
+    /**
      * Tests the attach() method for multiple event key in multiple queues
      *
      * @group deprecated
@@ -257,6 +276,19 @@ class EventManagerTest extends TestCase
     }
 
     /**
+     * Test the on() with invalid arguments
+     *
+     * @expectedException InvalidArgumentException
+     * @expectedExceptionMessage Invalid arguments for EventManager::on(). Expected 1, 2 or 3 arguments.
+     * @return void
+     */
+    public function testOnInvalidArgument()
+    {
+        $manager = new EventManager();
+        $manager->on();
+    }
+
+    /**
      * Tests off'ing an event from a event key queue
      *
      * @return void
@@ -888,6 +920,34 @@ class EventManagerTest extends TestCase
     }
 
     /**
+     * test debugInfo with an event list.
+     *
+     * @return void
+     */
+    public function testDebubInfoEventList()
+    {
+        $eventList = new EventList();
+        $eventManager = new EventManager();
+        $eventManager->setEventList($eventList);
+        $eventManager->on('example', function () {
+        });
+        $eventManager->dispatch('example');
+
+        $this->assertSame(
+            [
+                '_listeners' => [
+                    'example' => '1 listener(s)',
+                ],
+                '_isGlobal' => false,
+                '_eventList' => $eventList,
+                '_trackEvents' => true,
+                '_generalManager' => '(object) EventManager',
+            ],
+            $eventManager->__debugInfo()
+        );
+    }
+
+    /**
      * Test that chainable methods return correct values.
      *
      * @return void