Skip to content

Commit

Permalink
Always use a fresh EventManager for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert Noordzij committed Jun 9, 2015
1 parent 7a783cb commit dfab29b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
12 changes: 0 additions & 12 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -14,7 +14,6 @@
namespace Cake\TestSuite;

use Cake\Core\Configure;
use Cake\Event\EventManager;
use Cake\Network\Request;
use Cake\Network\Session;
use Cake\Routing\DispatcherFactory;
Expand Down Expand Up @@ -99,17 +98,6 @@ abstract class IntegrationTestCase extends TestCase
*/
protected $_requestSession;

/**
* Resets the EventManager for before each test.
*
* @return void
*/
public function setUp()
{
parent::setUp();
EventManager::instance(new EventManager());
}

/**
* Clears the state used for requests.
*
Expand Down
3 changes: 3 additions & 0 deletions src/TestSuite/TestCase.php
Expand Up @@ -16,6 +16,7 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use Cake\Event\EventManager;
use Cake\ORM\Exception\MissingTableClassException;
use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
Expand Down Expand Up @@ -100,6 +101,8 @@ public function setUp()
if (class_exists('Cake\Routing\Router', false)) {
Router::reload();
}

EventManager::instance(new EventManager());
}

/**
Expand Down
26 changes: 26 additions & 0 deletions tests/TestCase/BasicsTest.php
Expand Up @@ -19,6 +19,7 @@
use Cake\Cache\Cache;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Event\EventManager;
use Cake\Filesystem\Folder;
use Cake\Log\Log;
use Cake\Network\Response;
Expand Down Expand Up @@ -560,4 +561,29 @@ public function testCollection()
$this->assertInstanceOf('Cake\Collection\Collection', $collection);
$this->assertSame($items, $collection->toArray());
}

/**
* Test that works in tandem with testEventManagerReset2 to
* test the EventManager reset.
*
* The return value is passed to testEventManagerReset2 as
* an arguments.
*
* @return \Cake\Event\EventManager
*/
public function testEventManagerReset1()
{
return EventManager::instance();
}

/**
* Test if the EventManager is reset between tests.
*
* @depends testEventManagerReset1
* @return void
*/
public function testEventManagerReset2($prevEventManager)
{
$this->assertNotSame($prevEventManager, EventManager::instance());
}
}

0 comments on commit dfab29b

Please sign in to comment.