Skip to content

Commit

Permalink
API Replace Extension subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 23, 2024
1 parent 13186bb commit 8344439
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Context/FixtureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use SilverStripe\Dev\FixtureFactory;
use SilverStripe\Dev\YamlFixture;
use SilverStripe\ORM\Connect\TempDatabase;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\Security\Group;
Expand Down Expand Up @@ -699,11 +698,29 @@ public function stepGoToNamedRecord($type, $id)
*/
public function iAddAnExtensionToTheClass($extension, $class)
{
$this->iAddAnExtensionToTheClassInner($extension, $class, false);
}

/**
* @param $extension
* @param $class
*
* @Given I add an extension :extension to the :class class and flush only
*/
public function iAddAnExtensionToTheClassAndFlushOnly(string $extension, string $class): void
{
$this->iAddAnExtensionToTheClassInner($extension, $class, true);
}

private function iAddAnExtensionToTheClassInner(string $extension, string $class, bool $flushOnly)
{

// Validate the extension
Assert::assertTrue(
class_exists($extension ?? '') && is_subclass_of($extension, Extension::class),
'Given extension does not extend Extension'
);
/** @var Extension $extension */

// Add the extension to the CLI context
/** @var Extensible $targetClass */
Expand Down Expand Up @@ -741,8 +758,8 @@ class_exists($extension ?? '') && is_subclass_of($extension, Extension::class),
// Remember to cleanup...
$this->activatedConfigFiles[] = $destPath;

// Flush website. We'll need to dev/build too if it's a DataExtension
if (is_subclass_of($extension, DataExtension::class)) {
// Flush website. We'll need to dev/build too if it's a DataObject
if (is_subclass_of($targetClass, DataObject::class) && !$flushOnly) {
$this->getMainContext()->visit('/dev/build?flush');
} else {
$this->getMainContext()->visit('/?flush');
Expand Down

0 comments on commit 8344439

Please sign in to comment.