This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from cakephp/split-helper
Split helper
- Loading branch information
Showing
3 changed files
with
138 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
namespace Cake\Codeception; | ||
|
||
use Cake\Codeception\Helper\ConfigTrait; | ||
use Cake\Codeception\Helper\DbTrait; | ||
use Cake\Core\Configure; | ||
use Cake\Event\EventManager; | ||
use Cake\TestSuite\Fixture\FixtureManager; | ||
use Codeception\TestCase; | ||
|
||
class Framework extends \Codeception\Lib\Framework | ||
{ | ||
|
||
use ConfigTrait; | ||
use DbTrait; | ||
|
||
/** | ||
* Module's default configuration. | ||
* | ||
* @var array | ||
*/ | ||
public $config = [ | ||
'autoFixtures' => true, | ||
'dropTables' => false, | ||
]; | ||
|
||
/** | ||
* The class responsible for managing the creation, loading and removing of fixtures | ||
* | ||
* @var \Cake\TestSuite\Fixture\FixtureManager | ||
*/ | ||
protected $fixtureManager = null; | ||
|
||
/** | ||
* Configure values to restore at end of test. | ||
* | ||
* @var array | ||
*/ | ||
protected $configure = []; | ||
|
||
protected $testCase = null; | ||
|
||
// @codingStandardsIgnoreStart | ||
public function _before(TestCase $test) // @codingStandardsIgnoreEnd | ||
{ | ||
if (method_exists($test, 'getTestClass')) { | ||
$this->testCase = $test->getTestClass(); | ||
} else { | ||
$this->testCase = $test; | ||
} | ||
|
||
if (!isset($this->testCase->autoFixtures)) { | ||
$this->testCase->autoFixtures = $this->config['autoFixtures']; | ||
} | ||
|
||
if (!isset($this->testCase->dropTables)) { | ||
$this->testCase->dropTables = $this->config['dropTables']; | ||
} | ||
|
||
EventManager::instance(new EventManager()); | ||
$this->fixtureManager = new FixtureManager(); | ||
|
||
if ($this->testCase->autoFixtures) { | ||
if (!isset($this->testCase->fixtures)) { | ||
$this->testCase->fixtures = []; | ||
} | ||
$this->loadFixtures($this->testCase->fixtures); | ||
} | ||
|
||
$this->snapshotApplication(); | ||
} | ||
|
||
// @codingStandardsIgnoreStart | ||
public function _after(TestCase $test) // @codingStandardsIgnoreEnd | ||
{ | ||
$this->resetApplication(); | ||
$this->fixtureManager->unload($this->testCase); | ||
if ($this->testCase->dropTables) { | ||
$this->fixtureManager->shutDown(); | ||
} | ||
} | ||
|
||
/** | ||
* Chooses which fixtures to load for a given test | ||
* | ||
* @return void | ||
*/ | ||
public function loadFixtures($fixtures) | ||
{ | ||
if (func_num_args() > 1) { | ||
$fixtures = func_get_args(); | ||
} | ||
$this->testCase->fixtures = $fixtures; | ||
$this->fixtureManager->fixturize($this->testCase); | ||
$this->fixtureManager->load($this->testCase); | ||
} | ||
|
||
/** | ||
* Asserts the expected CakePHP version. | ||
* | ||
* @param string $ver Expected version. | ||
* @param string $operator Comparison to run, defaults to greater or equal. | ||
* @ | ||
*/ | ||
public function expectedCakePHPVersion($ver, $operator = 'ge') | ||
{ | ||
$this->assertTrue(version_compare($ver, Configure::version(), $operator)); | ||
} | ||
|
||
/** | ||
* Resets the application's configuration. | ||
* | ||
* @return void | ||
*/ | ||
protected function resetApplication() | ||
{ | ||
if (!empty($this->configure)) { | ||
Configure::clear(); | ||
Configure::write($this->configure); | ||
} | ||
} | ||
|
||
/** | ||
* Snapshots the application's configuration. | ||
* | ||
* @return void | ||
*/ | ||
protected function snapshotApplication() | ||
{ | ||
if (empty($this->configure)) { | ||
$this->configure = Configure::read(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters