Skip to content

Commit

Permalink
Throwing assertion error if no event list is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyharris committed Jun 15, 2016
1 parent 8de073a commit 92d871e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/TestSuite/Constraint/EventFired.php
Expand Up @@ -2,6 +2,7 @@
namespace Cake\TestSuite\Constraint;

use Cake\Event\EventManager;
use PHPUnit_Framework_AssertionFailedError;
use PHPUnit_Framework_Constraint;

/**
Expand All @@ -25,6 +26,10 @@ public function __construct($eventManager)
{
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.');
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/TestSuite/Constraint/EventFiredWith.php
Expand Up @@ -47,6 +47,10 @@ public function __construct($eventManager, $dataKey, $dataValue)
$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.');
}
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/TestCase/TestSuite/TestCaseTest.php
Expand Up @@ -48,6 +48,28 @@ public static function defaultConnectionName()
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
*
Expand Down

0 comments on commit 92d871e

Please sign in to comment.