From fe77d1dacbd50a54d168ec7dc55e398e23da6ed3 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 31 Jan 2014 10:01:31 +1300 Subject: [PATCH] In stepCreateRecordWithTable, if a fixture already exists then update that record rather than create a new, identical fixture. --- .../BehatExtension/Context/FixtureContext.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/SilverStripe/BehatExtension/Context/FixtureContext.php b/src/SilverStripe/BehatExtension/Context/FixtureContext.php index ac4a357..99c3f50 100644 --- a/src/SilverStripe/BehatExtension/Context/FixtureContext.php +++ b/src/SilverStripe/BehatExtension/Context/FixtureContext.php @@ -183,7 +183,17 @@ class FixtureContext extends BehatContext if($class == 'File' || is_subclass_of($class, 'File')) { $fields = $this->prepareAsset($class, $id, $fields); } - $this->fixtureFactory->createObject($class, $id, $fields); + + // We should check if this fixture object already exists - if it does, we update it. If not, we create it + if($existingFixture = $this->fixtureFactory->get($class, $id)) { + // Merge existing data with new data, and create new object to replace existing object + foreach($fields as $k => $v) { + $existingFixture->$k = $v; + } + $existingFixture->write(); + } else { + $this->fixtureFactory->createObject($class, $id, $fields); + } } /**