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,8 +139,17 @@ class FixtureContext extends BehatContext
|
||||
$class,
|
||||
array($field => $value)
|
||||
);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: Given a "page" "Page 1" with "URL"="page-1" and "Content"="my page 1"
|
||||
@ -160,8 +169,17 @@ class FixtureContext extends BehatContext
|
||||
array_combine($matches['key'], $matches['value'])
|
||||
);
|
||||
$fields = $this->prepareFixture($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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Example: And the "page" "Page 2" has the following data
|
||||
|
Loading…
Reference in New Issue
Block a user