Browse Source

Going nuclear: All the fixtures process is done for each test method

Jose Lorenzo Rodriguez 12 years ago
parent
commit
ea6e6c56ea

+ 3 - 22
src/TestSuite/Fixture/FixtureInjector.php

@@ -14,7 +14,6 @@
  */
 namespace Cake\TestSuite\Fixture;
 
-use Cake\Datasource\ConnectionManager;
 use Cake\TestSuite\Fixture\FixtureManager;
 use Cake\TestSuite\TestCase;
 use Exception;
@@ -37,13 +36,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
  *
  * @param \Cake\TestSuite\Fixture\FixtureManager $manager
@@ -60,13 +52,6 @@ class FixtureInjector implements PHPUnit_Framework_TestListener {
  * @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;
-			}
-		}
 	}
 
 /**
@@ -77,13 +62,6 @@ class FixtureInjector implements PHPUnit_Framework_TestListener {
  * @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);
-		}
 	}
 
 /**
@@ -137,6 +115,8 @@ class FixtureInjector implements PHPUnit_Framework_TestListener {
  * @return void
  */
 	public function startTest(PHPUnit_Framework_Test $test) {
+		$this->_fixtureManager->fixturize($test);
+		$test->fixtureManager = $this->_fixtureManager;
 		$this->_fixtureManager->load($test);
 	}
 
@@ -149,6 +129,7 @@ class FixtureInjector implements PHPUnit_Framework_TestListener {
  */
 	public function endTest(PHPUnit_Framework_Test $test, $time) {
 		$this->_fixtureManager->unload($test);
+		$this->_fixtureManager->shutdown();
 	}
 
 /**

+ 2 - 0
tests/TestCase/Controller/Component/PaginatorComponentTest.php

@@ -448,6 +448,7 @@ class PaginatorComponentTest extends TestCase {
  * @return void
  */
 	public function testOutOfVeryBigPageNumberGetsClamped() {
+		$this->loadFixtures('Post');
 		$this->request->query = [
 			'page' => '3000000000000000000000000',
 		];
@@ -615,6 +616,7 @@ class PaginatorComponentTest extends TestCase {
  * @return void
  */
 	public function testPaginateMaxLimit() {
+		$this->loadFixtures('Post');
 		$table = TableRegistry::get('PaginatorPosts');
 
 		$settings = [

+ 1 - 7
tests/test_app/TestApp/Model/Table/PaginatorPostsTable.php

@@ -24,18 +24,12 @@ use Cake\Utility\Hash;
 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'
 		]);