Browse Source

Throwing assertion error if no event list is configured

Jeremy Harris 9 years ago
parent
commit
92d871e2ff

+ 5 - 0
src/TestSuite/Constraint/EventFired.php

@@ -2,6 +2,7 @@
 namespace Cake\TestSuite\Constraint;
 
 use Cake\Event\EventManager;
+use PHPUnit_Framework_AssertionFailedError;
 use PHPUnit_Framework_Constraint;
 
 /**
@@ -25,6 +26,10 @@ class EventFired extends PHPUnit_Framework_Constraint
     {
         parent::__construct();
         $this->_eventManager = $eventManager;
+
+        if ($this->_eventManager->getEventList() === null) {
+            throw new PHPUnit_Framework_AssertionFailedError('The event manager you are asserting against is not configured to track events.');
+        }
     }
 
     /**

+ 4 - 0
src/TestSuite/Constraint/EventFiredWith.php

@@ -47,6 +47,10 @@ class EventFiredWith extends PHPUnit_Framework_Constraint
         $this->_eventManager = $eventManager;
         $this->_dataKey = $dataKey;
         $this->_dataValue = $dataValue;
+
+        if ($this->_eventManager->getEventList() === null) {
+            throw new PHPUnit_Framework_AssertionFailedError('The event manager you are asserting against is not configured to track events.');
+        }
     }
 
     /**

+ 22 - 0
tests/TestCase/TestSuite/TestCaseTest.php

@@ -49,6 +49,28 @@ class TestCaseTest extends TestCase
 {
 
     /**
+     * tests trying to assertEventFired without configuring an event list
+     *
+     * @expectedException \PHPUnit_Framework_AssertionFailedError
+     */
+    public function testEventFiredMisconfiguredEventList()
+    {
+        $manager = EventManager::instance();
+        $this->assertEventFired('my.event', $manager);
+    }
+
+    /**
+     * tests trying to assertEventFired without configuring an event list
+     *
+     * @expectedException \PHPUnit_Framework_AssertionFailedError
+     */
+    public function testEventFiredWithMisconfiguredEventList()
+    {
+        $manager = EventManager::instance();
+        $this->assertEventFiredWith('my.event', 'some', 'data', $manager);
+    }
+
+    /**
      * tests assertEventFiredWith
      *
      * @return void