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

FIX Correctly clear extensions after each scenario #241

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
21 changes: 21 additions & 0 deletions src/Context/FixtureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class FixtureContext implements Context
*/
protected $activatedConfigFiles = array();

/**
* @var string[][] Tracks any extensions that have been added to classes
*/
protected $addedExtensions = array();

/**
* @var array Stores the asset tuples.
*/
Expand Down Expand Up @@ -660,6 +665,10 @@ class_exists($extension ?? '') && is_subclass_of($extension, Extension::class),
/** @var Extensible $targetClass */
$targetClass = $this->convertTypeToClass($class);
$targetClass::add_extension($extension);
if (!array_key_exists($targetClass, $this->addedExtensions)) {
$this->addedExtensions[$targetClass] = [];
}
$this->addedExtensions[$targetClass][] = $extension;

// Write config for this extension too...
$snakedExtension = strtolower(str_replace('\\', '-', $extension ?? '') ?? '');
Expand Down Expand Up @@ -793,6 +802,7 @@ public function aRecordWasLastEditedRelative($type, $id, $mod, $time)
public function afterResetConfig(AfterScenarioScope $event)
{
$this->clearConfigFiles();
$this->clearExtensions();
// Flush
$this->getMainContext()->visit('/?flush');
}
Expand Down Expand Up @@ -951,6 +961,17 @@ protected function joinPaths()
return join('/', $paths);
}

protected function clearExtensions()
{
foreach ($this->addedExtensions as $targetClass => $extensions) {
foreach ($extensions as $extension) {
/** @var Extensible $targetClass */
$targetClass::remove_extension($extension);
}
}
$this->addedExtensions = [];
}

protected function clearConfigFiles()
{
// No files to cleanup
Expand Down