mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Allow updating of fixtures in creation steps if they already exist
This commit is contained in:
parent
7e8eaae73a
commit
4297e36762
@ -139,7 +139,16 @@ class FixtureContext extends BehatContext
|
||||
$class,
|
||||
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'])
|
||||
);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user