mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Using the CakeTesSuite in TestManager and calling accordingly the load and unload of fixtures using the variable
$sharedFixture
This commit is contained in:
parent
ec9c8b4d49
commit
5d041c58b7
2 changed files with 31 additions and 12 deletions
|
@ -63,12 +63,6 @@ class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
*/
|
||||
private $__savedGetData = array();
|
||||
|
||||
public function __construct($name = null, array $data = array(), $dataName = '') {
|
||||
parent::__construct($name, $data, $dataName);
|
||||
if (!empty($this->fixtures)) {
|
||||
CakeFixtureManager::fixturize($this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Called when a test case (group of methods) is about to start (to be overriden when needed.)
|
||||
*
|
||||
|
@ -127,7 +121,9 @@ class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
*/
|
||||
protected function assertPreConditions() {
|
||||
parent::assertPreConditions();
|
||||
CakeFixtureManager::load($this);
|
||||
if (!empty($this->sharedFixture)) {
|
||||
$this->sharedFixture->load($this);
|
||||
}
|
||||
if (!in_array(strtolower($this->getName()), $this->methods)) {
|
||||
$this->startTest($this->getName());
|
||||
}
|
||||
|
@ -162,7 +158,9 @@ class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
*/
|
||||
protected function assertPostConditions() {
|
||||
parent::assertPostConditions();
|
||||
CakeFixtureManager::unload($this);
|
||||
if (!empty($this->sharedFixture)) {
|
||||
$this->sharedFixture->unload($this);
|
||||
}
|
||||
if (!in_array(strtolower($this->getName()), $this->methods)) {
|
||||
$this->endTest($this->getName());
|
||||
}
|
||||
|
@ -192,9 +190,14 @@ class CakeTestCase extends PHPUnit_Framework_TestCase {
|
|||
* @see CakeTestCase::$autoFixtures
|
||||
*/
|
||||
function loadFixtures() {
|
||||
if (empty($this->sharedFixture)) {
|
||||
throw new Exception(__('No fixture manager to load the test fixture'));
|
||||
}
|
||||
$args = func_get_args();
|
||||
foreach ($args as $class) {
|
||||
CakeFixtureManager::loadSingle($class);
|
||||
if (!empty($this->sharedFixture)) {
|
||||
$this->sharedFixture->unload($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups'
|
|||
define('APP_TEST_CASES', TESTS . 'cases');
|
||||
define('APP_TEST_GROUPS', TESTS . 'groups');
|
||||
|
||||
require_once CAKE_TESTS_LIB . 'cake_test_suite.php';
|
||||
/**
|
||||
* TestManager is the base class that handles loading and initiating the running
|
||||
* of TestCase and TestSuite classes that the user has selected.
|
||||
|
@ -61,10 +62,17 @@ class TestManager {
|
|||
/**
|
||||
* TestSuite container for single or grouped test files
|
||||
*
|
||||
* @var PHPUnit_Framework_TestSuiteboolean
|
||||
* @var PHPUnit_Framework_TestSuite
|
||||
*/
|
||||
protected $_testSuit = null;
|
||||
|
||||
/**
|
||||
* Object instance responsible for managing the test fixtures
|
||||
*
|
||||
* @var CakeFixtureManager
|
||||
*/
|
||||
protected $_fixtureManager = null;
|
||||
|
||||
/**
|
||||
* Constructor for the TestManager class
|
||||
*
|
||||
|
@ -162,7 +170,9 @@ class TestManager {
|
|||
$result = new PHPUnit_Framework_TestResult;
|
||||
$result->addListener($reporter);
|
||||
$reporter->paintHeader();
|
||||
$this->getTestSuite()->run($result);
|
||||
$testSuite = $this->getTestSuite();
|
||||
$testSuite->setFixtureManager($this->getFixtureManager());
|
||||
$testSuite->run($result);
|
||||
$reporter->paintResult($result);
|
||||
return $result;
|
||||
}
|
||||
|
@ -395,9 +405,15 @@ class TestManager {
|
|||
if (!empty($this->_testSuite)) {
|
||||
return $this->_testSuite;
|
||||
}
|
||||
return $this->_testSuite = new PHPUnit_Framework_TestSuite($name);
|
||||
return $this->_testSuite = new CakeTestSuite($name);
|
||||
}
|
||||
|
||||
protected function getFixtureManager() {
|
||||
if (!empty($this->_fixtureManager)) {
|
||||
return $this->_fixtureManager;
|
||||
}
|
||||
return $this->_fixtureManager = new CakeFixtureManager;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue