From 388ba0c743486deec2784ef3956c67e354777562 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 29 Aug 2024 13:54:30 +1200 Subject: [PATCH] API Replace Extension subclasses --- src/Context/FixtureContext.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Context/FixtureContext.php b/src/Context/FixtureContext.php index cafbb138..0b6add0d 100644 --- a/src/Context/FixtureContext.php +++ b/src/Context/FixtureContext.php @@ -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; @@ -692,6 +691,8 @@ public function stepGoToNamedRecord($type, $id) } /** + * Adds an extension and runs dev/build?flush + * * @param $extension * @param $class * @@ -699,11 +700,31 @@ public function stepGoToNamedRecord($type, $id) */ public function iAddAnExtensionToTheClass($extension, $class) { + $this->iAddAnExtensionToTheClassInner($extension, $class, false); + } + + /** + * Adds an extension, but doesn't run dev/build afterwards. Will still run ?flush + * + * @param $extension + * @param $class + * + * @Given I add an extension :extension to the :class class without dev-build + */ + public function iAddAnExtensionToTheClassWithoutDevBuild(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 */ @@ -741,8 +762,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');