Skip to content

Instantly share code, notes, and snippets.

@dakota
Created January 23, 2015 11:53
Show Gist options
  • Save dakota/274ae1422f938cbc4b80 to your computer and use it in GitHub Desktop.
Save dakota/274ae1422f938cbc4b80 to your computer and use it in GitHub Desktop.
<?php
class FeatureContext {
/**
* Reads the available fixtures
*
* @return array
*/
public static function readFixtures() {
$fixtures = [];
$fixturePath = TESTS . 'Fixture' . DS;
$fixtureFolder = new Folder($fixturePath);
$files = $fixtureFolder->find('.*Fixture\.php');
foreach ($files as $file) {
$fixtureName = Inflector::underscore(str_replace('Fixture.php', '', $file));
if ($fixtureName == 'job_report') {
continue;
}
$fixtures[] = 'app.' . $fixtureName;
}
return $fixtures;
}
/**
* Initialise the database
*
* @BeforeFeature
*
* @return void
*/
public static function createTables() {
ini_set('memory_limit', -1);
self::$_testCase = new BlankTestCase();
self::$_testCase->fixtures = self::readFixtures();
if (!self::$_FixtureManager) {
self::$_FixtureManager = new FixtureManager();
self::$_FixtureManager->fixturize(self::$_testCase);
}
self::$_FixtureManager->load(self::$_testCase);
self::$_FixtureManager->unload(self::$_testCase); //Truncates them
}
/**
* Destroy the database
*
* @AfterFeature
* @AfterSuite
*
* @return void
*/
public static function dropTables() {
if (self::$_FixtureManager) {
self::$_FixtureManager->shutdown();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment