Allow updating of fixtures in creation steps if they already exist

This commit is contained in:
Ingo Schommer 2015-02-15 12:08:05 +13:00
parent 7e8eaae73a
commit 4297e36762

View File

@ -139,7 +139,16 @@ class FixtureContext extends BehatContext
$class, $class,
array($field => $value) array($field => $value)
); );
$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);
}
} }
/** /**
@ -160,7 +169,16 @@ class FixtureContext extends BehatContext
array_combine($matches['key'], $matches['value']) array_combine($matches['key'], $matches['value'])
); );
$fields = $this->prepareFixture($class, $id, $fields); $fields = $this->prepareFixture($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);
}
} }
/** /**