diff --git a/dev/BehatFixtureFactory.php b/dev/BehatFixtureFactory.php new file mode 100644 index 000000000..b4ce190de --- /dev/null +++ b/dev/BehatFixtureFactory.php @@ -0,0 +1,23 @@ +hasField($fieldName) && !isset($data[$fieldName])) { + $data[$fieldName] = $identifier; + break; + } + } + } + + return parent::createObject($name, $identifier, $data); + } +} \ No newline at end of file diff --git a/dev/FixtureBlueprint.php b/dev/FixtureBlueprint.php index c3cc97c4e..95a3bfa58 100644 --- a/dev/FixtureBlueprint.php +++ b/dev/FixtureBlueprint.php @@ -115,6 +115,7 @@ class FixtureBlueprint { $this->setValue($obj, $fieldName, $fieldVal, $fixtures); } + $obj->write(); // Save to fixture before relationship processing in case of reflexive relationships diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php index 636306f8a..a9c4835d4 100644 --- a/tests/behat/features/bootstrap/FeatureContext.php +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -45,6 +45,14 @@ class FeatureContext extends SilverStripeContext $fixtureContext = new FixtureContext($parameters); $fixtureContext->setFixtureFactory($this->getFixtureFactory()); $this->useContext('FixtureContext', $fixtureContext); + + // Use blueprints to set user name from identifier + $factory = $fixtureContext->getFixtureFactory(); + $blueprint = \Injector::inst()->create('FixtureBlueprint', 'Member'); + $blueprint->addCallback('beforeCreate', function($identifier, &$data, &$fixtures) { + if(!isset($data['FirstName'])) $data['FirstName'] = $identifier; + }); + $factory->define('Member', $blueprint); } public function setMinkParameters(array $parameters) @@ -61,7 +69,7 @@ class FeatureContext extends SilverStripeContext */ public function getFixtureFactory() { if(!$this->fixtureFactory) { - $this->fixtureFactory = \Injector::inst()->get('FixtureFactory', 'FixtureContextFactory'); + $this->fixtureFactory = \Injector::inst()->create('BehatFixtureFactory'); } return $this->fixtureFactory; }