Permalink
Browse files

API change database session selection to setdb endpoint

  • Loading branch information...
1 parent e48151a commit 30f4babfaeda778a15aab35ece4f4463dfa5ba7e @michalochman committed Aug 7, 2012
@@ -26,7 +26,7 @@
*/
class SilverStripeContext extends MinkContext implements SilverStripeAwareContextInterface
{
- private $session_key;
+ private $database_name;
protected $context;
protected $fixtures;
@@ -46,9 +46,9 @@ public function __construct(array $parameters)
$this->context = $parameters;
}
- public function setSessionKey($session_key)
+ public function setDatabase($database_name)
{
- $this->session_key = $session_key;
+ $this->database_name = $database_name;
}
public function getFixture($data_object)
@@ -70,15 +70,13 @@ public function getFixtures()
*/
public function before(ScenarioEvent $event)
{
- if (!isset($this->session_key)) {
- throw new \LogicException('Context\'s $session_key has to be set when implementing SilverStripeAwareContextInterface.');
+ if (!isset($this->database_name)) {
+ throw new \LogicException('Context\'s $database_name has to be set when implementing SilverStripeAwareContextInterface.');
}
- $selectsession_url = $this->joinUrlParts($this->context['base_url'], '/dev/tests/selectsession');
- $this->getSession()->visit($selectsession_url);
- $page = $this->getSession()->getPage();
- $page->find('css', '#testSessionKey')->setValue($this->session_key);
- $page->find('css', '#select-session')->click();
+ $setdb_url = $this->joinUrlParts($this->context['base_url'], '/dev/tests/setdb');
+ $setdb_url = sprintf('%s?database=%s', $setdb_url, $this->database_name);
+ $this->getSession()->visit($setdb_url);
}
/**
@@ -24,25 +24,20 @@
*/
class SilverStripeAwareInitializer implements InitializerInterface
{
- private $session_key;
- private $session_file;
+ private $database_name;
/**
* Initializes initializer.
*/
public function __construct($framework_path, $framework_host)
{
$this->bootstrap($framework_path, $framework_host);
- $database_config = $this->initializeTempDb();
-
- $this->session_key = $this->generateSessionKey($database_config);
- $this->session_file = $this->persistSession($database_config, $this->session_key);
+ $this->database_name = $this->initializeTempDb();
}
public function __destruct()
{
$this->deleteTempDb();
- $this->forgetSession();
}
/**
@@ -64,7 +59,7 @@ public function supports(ContextInterface $context)
*/
public function initialize(ContextInterface $context)
{
- $context->setSessionKey($this->session_key);
+ $context->setDatabase($this->database_name);
}
protected function bootstrap($framework_path, $framework_host)
@@ -87,13 +82,8 @@ protected function initializeTempDb()
file_put_contents('php://stderr', 'Creating temp DB' . PHP_EOL);
$dbname = \SapphireTest::create_temp_db();
\DB::set_alternative_database_name($dbname);
- $database_config = array(
- 'databaseConfig' => array(
- 'database' => $dbname,
- ),
- );
- return json_encode($database_config);
+ return $dbname;
}
protected function deleteTempDb()
@@ -102,31 +92,4 @@ protected function deleteTempDb()
\SapphireTest::kill_temp_db();
\DB::set_alternative_database_name(null);
}
-
- protected function generateSessionKey($database_config)
- {
- return sha1(sprintf('%s%s', $database_config, microtime(true)));
- }
-
- protected function persistSession($database_config, $session_key)
- {
- file_put_contents('php://stderr', 'Saving testSessionKey file' . PHP_EOL);
- $temp_dir = '/tmp';
- $test_sessions_dir = $temp_dir . DIRECTORY_SEPARATOR . 'testsessions';
- if (!file_exists($test_sessions_dir)) {
- mkdir($test_sessions_dir);
- }
- $test_session_file = $test_sessions_dir . DIRECTORY_SEPARATOR . $session_key;
- file_put_contents($test_session_file, $database_config);
-
- return $test_session_file;
- }
-
- protected function forgetSession()
- {
- file_put_contents('php://stderr', 'Removing testSessionKey file' . PHP_EOL);
- if (file_exists($this->session_file)) {
- unlink($this->session_file);
- }
- }
}
@@ -21,7 +21,7 @@
/**
* Sets SilverStripe instance.
*
- * @param String $session_key testSessionKey used in TEMP_FOLDER/testsessions/<testSessionKey> file
+ * @param String $database_name Temp database name
*/
- public function setSessionKey($session_key);
+ public function setDatabase($database_name);
}

0 comments on commit 30f4bab

Please sign in to comment.