From ea6e6c56ead79d877972a7e2b3a8fb32255580cd Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 28 Mar 2014 10:18:09 +0100 Subject: [PATCH] Going nuclear: All the fixtures process is done for each test method --- src/TestSuite/Fixture/FixtureInjector.php | 25 +++---------------- .../Component/PaginatorComponentTest.php | 2 ++ .../Model/Table/PaginatorPostsTable.php | 8 +----- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/TestSuite/Fixture/FixtureInjector.php b/src/TestSuite/Fixture/FixtureInjector.php index af7b0ff8c6b..182b05e18d9 100644 --- a/src/TestSuite/Fixture/FixtureInjector.php +++ b/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; @@ -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 * @@ -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; - } - } } /** @@ -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); - } } /** @@ -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); } @@ -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(); } /** diff --git a/tests/TestCase/Controller/Component/PaginatorComponentTest.php b/tests/TestCase/Controller/Component/PaginatorComponentTest.php index a0152d770d9..b94b1bccc45 100644 --- a/tests/TestCase/Controller/Component/PaginatorComponentTest.php +++ b/tests/TestCase/Controller/Component/PaginatorComponentTest.php @@ -448,6 +448,7 @@ public function testOutOfRangePageNumberGetsClamped() { * @return void */ public function testOutOfVeryBigPageNumberGetsClamped() { + $this->loadFixtures('Post'); $this->request->query = [ 'page' => '3000000000000000000000000', ]; @@ -615,6 +616,7 @@ public function testCheckLimit() { * @return void */ public function testPaginateMaxLimit() { + $this->loadFixtures('Post'); $table = TableRegistry::get('PaginatorPosts'); $settings = [ diff --git a/tests/test_app/TestApp/Model/Table/PaginatorPostsTable.php b/tests/test_app/TestApp/Model/Table/PaginatorPostsTable.php index e64ce896bb4..f79436969d5 100644 --- a/tests/test_app/TestApp/Model/Table/PaginatorPostsTable.php +++ b/tests/test_app/TestApp/Model/Table/PaginatorPostsTable.php @@ -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' ]);