Changes required for persisting state directly on disk

applyState() used to persist in memory, which could lead
to outdated state depending on execution flow between CLI
and web requests. Since state is now in a JSON object,
it also fixes the array access.
This commit is contained in:
Ingo Schommer 2014-03-01 18:26:21 +13:00
parent 7df2fab1bc
commit ca455423ef
3 changed files with 11 additions and 11 deletions

View File

@ -88,7 +88,7 @@ class EmailContext extends BehatContext
$from = ($direction == 'from') ? $email : null;
$match = $this->mailer->findEmail($to, $from, $subject);
$allMails = $this->mailer->findEmails($to, $from);
$allTitles = $allMails ? '"' . implode('","', array_map(function($email) {return $email['Subject'];}, $allMails)) . '"' : null;
$allTitles = $allMails ? '"' . implode('","', array_map(function($email) {return $email->Subject;}, $allMails)) . '"' : null;
if(trim($negate)) {
assertNull($match);
} else {
@ -120,10 +120,10 @@ class EmailContext extends BehatContext
}
$email = $this->lastMatchedEmail;
if($email['Content']) {
assertContains($content, $email['Content']);
if($email->Content) {
assertContains($content, $email->Content);
} else {
assertContains($content, $email['PlainContent']);
assertContains($content, $email->PlainContent);
}
}
@ -137,7 +137,7 @@ class EmailContext extends BehatContext
$match = $this->mailer->findEmail($to, $from);
assertNotNull($match);
$crawler = new Crawler($match['Content']);
$crawler = new Crawler($match->Content);
$linkEl = $crawler->selectLink($linkSelector);
assertNotNull($linkEl);
$link = $linkEl->attr('href');
@ -159,7 +159,7 @@ class EmailContext extends BehatContext
}
$match = $this->lastMatchedEmail;
$crawler = new Crawler($match['Content']);
$crawler = new Crawler($match->Content);
$linkEl = $crawler->selectLink($linkSelector);
assertNotNull($linkEl);
$link = $linkEl->attr('href');

View File

@ -67,7 +67,6 @@ class SilverStripeAwareInitializer implements InitializerInterface
file_put_contents('php://stdout', "Creating test session environment" . PHP_EOL);
$testEnv = \Injector::inst()->get('TestSessionEnvironment');
$testEnv->startTestSession(array(
'createDatabase' => true
));

View File

@ -64,7 +64,7 @@ class TestMailer extends \Mailer {
public function clearEmails() {
$state = $this->testSessionEnvironment->getState();
if(isset($state->emails)) unset($state->emails);
$this->testSessionEnvironment->persistState();
$this->testSessionEnvironment->applyState($state);
}
/**
@ -103,10 +103,11 @@ class TestMailer extends \Mailer {
$matched = true;
foreach(array('To','From','Subject','Content') as $i => $field) {
if(!isset($email->$field)) continue;
$value = (isset($args[$i])) ? $args[$i] : null;
if($value) {
if($value[0] == '/') $matched = preg_match($value, $email[$field]);
else $matched = ($value == $email[$field]);
if($value[0] == '/') $matched = preg_match($value, $email->$field);
else $matched = ($value == $email->$field);
if(!$matched) break;
}
}
@ -120,7 +121,7 @@ class TestMailer extends \Mailer {
$state = $this->testSessionEnvironment->getState();
if(!isset($state->emails)) $state->emails = array();
$state->emails[] = array_filter($data);
$this->testSessionEnvironment->persistState();
$this->testSessionEnvironment->applyState($state);
}
}