From 72141f4474f0ad61c5336bbeed4ad3fb6f1cc7e6 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 9 Apr 2013 01:58:34 +0200 Subject: [PATCH] 3.1 compat --- .../Context/SilverStripeContext.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php index 934f3f2..f76d0d0 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php @@ -58,6 +58,11 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex */ protected $screenshotPath; + /** + * @var FixtureFactory + */ + protected $fixtureFactory; + protected $context; protected $fixtures; protected $fixturesLazy; @@ -264,7 +269,7 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex // Save fixtures into database $this->fixtures[$dataObject] = new \YamlFixture($fixture); $model = \DataModel::inst(); - $this->fixtures[$dataObject]->saveIntoDatabase($model); + $this->fixtures[$dataObject]->writeInto($this->getFixtureFactory()); // Lazy load fixtures into database // Loop is required for nested lazy fixtures foreach ($fixturesLazy[$dataObject] as $identifier => $fields) { @@ -276,7 +281,7 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex $fixture = Yaml::dump($fixture); $fixture = preg_replace_callback('/=>(\w+)\.([\w.]+)/', array($this, 'replaceFixtureReferences'), $fixture); $this->fixturesLazy[$dataObject][$identifier] = new \YamlFixture($fixture); - $this->fixturesLazy[$dataObject][$identifier]->saveIntoDatabase($model); + $this->fixturesLazy[$dataObject][$identifier]->writeInto($this->getFixtureFactory()); } } @@ -341,7 +346,7 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex protected function idFromFixture($className, $identifier) { - if (false !== ($id = $this->fixtures[$className]->idFromFixture($className, $identifier))) { + if (false !== ($id = $this->getFixtureFactory()->getId($className, $identifier))) { return $id; } if (isset($this->fixturesLazy[$className], $this->fixturesLazy[$className][$identifier]) && @@ -414,6 +419,15 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex return $this->getMinkParameter('base_url') ?: ''; } + /** + * @return FixtureFactory + */ + public function getFixtureFactory() + { + if(!$this->fixtureFactory) $this->fixtureFactory = \Injector::inst()->create('FixtureFactory'); + return $this->fixtureFactory; + } + /** * Joins URL parts into an URL using forward slash. * Forward slash usages are normalised to one between parts.