Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Replace Extension subclasses #281

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 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 @@ -692,18 +691,40 @@ public function stepGoToNamedRecord($type, $id)
}

/**
* Adds an extension and runs dev/build?flush
*
* @param $extension
* @param $class
*
* @Given I add an extension :extension to the :class class
*/
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 */
Expand Down Expand Up @@ -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');
Expand Down
Loading