Skip to content

Commit

Permalink
Going nuclear: All the fixtures process is done for each test method
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 28, 2014
1 parent cb6f17d commit ea6e6c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
25 changes: 3 additions & 22 deletions src/TestSuite/Fixture/FixtureInjector.php
Expand Up @@ -14,7 +14,6 @@
*/
namespace Cake\TestSuite\Fixture;

use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\Fixture\FixtureManager;
use Cake\TestSuite\TestCase;
use Exception;
Expand All @@ -36,13 +35,6 @@ class FixtureInjector implements PHPUnit_Framework_TestListener {
*/
protected $_fixtureManager;

/**
* Indicates the current number of nested testsuites
*
* @var integer
*/
protected $_nesting = 0;

/**
* Constructor. Save internally the reference to the passed fixture manager
*
Expand All @@ -60,13 +52,6 @@ public function __construct(FixtureManager $manager) {
* @return void
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
$this->_nesting++;
foreach ($suite->getIterator() as $test) {
if ($test instanceof TestCase) {
$this->_fixtureManager->fixturize($test);
$test->fixtureManager = $this->_fixtureManager;
}
}
}

/**
Expand All @@ -77,13 +62,6 @@ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
* @return void
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
$this->_nesting--;
if (!$this->_nesting) {
$this->_fixtureManager->shutdown();
$config = ConnectionManager::config('test');
ConnectionManager::drop('test');
ConnectionManager::config('test', $config);
}
}

/**
Expand Down Expand Up @@ -137,6 +115,8 @@ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time
* @return void
*/
public function startTest(PHPUnit_Framework_Test $test) {
$this->_fixtureManager->fixturize($test);
$test->fixtureManager = $this->_fixtureManager;
$this->_fixtureManager->load($test);
}

Expand All @@ -149,6 +129,7 @@ public function startTest(PHPUnit_Framework_Test $test) {
*/
public function endTest(PHPUnit_Framework_Test $test, $time) {
$this->_fixtureManager->unload($test);
$this->_fixtureManager->shutdown();
}

/**
Expand Down
Expand Up @@ -448,6 +448,7 @@ public function testOutOfRangePageNumberGetsClamped() {
* @return void
*/
public function testOutOfVeryBigPageNumberGetsClamped() {
$this->loadFixtures('Post');
$this->request->query = [
'page' => '3000000000000000000000000',
];
Expand Down Expand Up @@ -615,6 +616,7 @@ public function testCheckLimit() {
* @return void
*/
public function testPaginateMaxLimit() {
$this->loadFixtures('Post');
$table = TableRegistry::get('PaginatorPosts');

$settings = [
Expand Down
8 changes: 1 addition & 7 deletions tests/test_app/TestApp/Model/Table/PaginatorPostsTable.php
Expand Up @@ -23,19 +23,13 @@
*/
class PaginatorPostsTable extends Table {

/**
* table property
*
* @var string
*/
protected $_table = 'posts';

/**
* initialize method
*
* @return void
*/
public function initialize(array $config) {
$this->table('posts');
$this->belongsTo('PaginatorAuthor', [
'foreignKey' => 'author_id'
]);
Expand Down

0 comments on commit ea6e6c5

Please sign in to comment.