Skip to content

Commit

Permalink
[TASK] Use ConfigurationManager to read and write configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
eliashaeussler committed Mar 11, 2024
1 parent 3d6c630 commit 7d00332
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 45 deletions.
52 changes: 7 additions & 45 deletions Tests/Acceptance/Support/Helper/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

namespace EliasHaeussler\Typo3Warming\Tests\Acceptance\Support\Helper;

use Codeception\Module;
use EliasHaeussler\Typo3CodeceptionHelper;
use TYPO3\CMS\Core;

/**
* ExtensionConfiguration
Expand All @@ -34,60 +33,23 @@
*/
final class ExtensionConfiguration
{
/**
* @var non-empty-string
*/
private readonly string $scriptPath;
private readonly Core\Configuration\ConfigurationManager $configurationManager;

public function __construct(
private readonly Module\Asserts $asserts,
private readonly Module\Cli $cli,
) {
$this->scriptPath = $this->determineScriptPath();
public function __construct()
{
$this->configurationManager = Core\Utility\GeneralUtility::makeInstance(Core\Configuration\ConfigurationManager::class);
}

public function read(string $path): mixed
{
$command = $this->buildCommand(['configuration:showactive', 'EXTENSIONS/warming/' . $path, '--json']);

$this->cli->runShellCommand($command);

$output = $this->cli->grabShellOutput();

$this->asserts->assertJson($output);

return json_decode($output, true);
return $this->configurationManager->getConfigurationValueByPath('EXTENSIONS/warming/' . $path);
}

/**
* @param non-empty-string $path
*/
public function write(string $path, mixed $value): void
{
$command = $this->buildCommand(['configuration:set', 'EXTENSIONS/warming/' . $path, $value]);

$this->cli->runShellCommand($command);
}

/**
* @param non-empty-list<scalar> $command
* @return non-empty-string
*/
private function buildCommand(array $command): string
{
$fullCommand = [$this->scriptPath, ...$command];
$fullCommand = array_map('strval', $fullCommand);

return implode(' ', array_map('escapeshellarg', $fullCommand));
}

/**
* @return non-empty-string
*/
private function determineScriptPath(): string
{
$buildDir = \dirname(Typo3CodeceptionHelper\Helper\PathHelper::getVendorDirectory());

return $buildDir . '/bin/typo3';
$this->configurationManager->setLocalConfigurationValueByPath('EXTENSIONS/warming/' . $path, $value);
}
}
1 change: 1 addition & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ suites:
editor.3: password

actor_suffix: Tester
bootstrap: /var/www/html/.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php
extensions:
enabled:
- Codeception\Extension\RunFailed
Expand Down

0 comments on commit 7d00332

Please sign in to comment.