Skip to content

Commit

Permalink
Add working directory to runtime configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
DZunke committed May 17, 2024
1 parent 7d3793e commit 7b65a93
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions panaly
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ include $_composer_autoload_path ?? __DIR__ . '/vendor/autoload.php';

$runtimeConfiguration = new Configuration\RuntimeConfiguration();
$runtimeConfiguration->setLogger(new ConsoleLogger($io));
$runtimeConfiguration->getLogger()->debug(
'The working directory registered is "{workingDirectory}"',
['workingDirectory' => $runtimeConfiguration->getWorkingDirectory()],
);

$configurationFile = (new Configuration\ConfigurationFileLoader())->loadFromFile(
$runtimeConfiguration->getFileProvider(),
Expand Down
14 changes: 11 additions & 3 deletions src/Configuration/RuntimeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

use function array_key_exists;
use function getcwd;

class RuntimeConfiguration
{
private EventDispatcherInterface $eventDispatcher;
private FileProvider $fileProvider;
private LoggerInterface $logger;
private string $workingDirectory;

/** @var list<Plugin> */
private array $loadedPlugins = [];
Expand All @@ -34,9 +36,10 @@ class RuntimeConfiguration

public function __construct()
{
$this->eventDispatcher = new EventDispatcher();
$this->fileProvider = new FileProvider();
$this->logger = new NullLogger();
$this->eventDispatcher = new EventDispatcher();
$this->fileProvider = new FileProvider();
$this->logger = new NullLogger();
$this->workingDirectory = (string) getcwd();
}

public function setLogger(LoggerInterface $logger): void
Expand All @@ -59,6 +62,11 @@ public function getFileProvider(): FileProvider
return $this->fileProvider;
}

public function getWorkingDirectory(): string
{
return $this->workingDirectory;
}

public function addPlugin(Plugin $plugin): void
{
$this->loadedPlugins[] = $plugin;
Expand Down
12 changes: 12 additions & 0 deletions tests/Configuration/RuntimeConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@
use Panaly\Plugin\Plugin\Storage;
use PHPUnit\Framework\TestCase;

use function getcwd;

class RuntimeConfigurationTest extends TestCase
{
public function testThatTheWorkingDirectoryIsCorrectlyInitialized(): void
{
$configuration = new RuntimeConfiguration();

self::assertSame(
getcwd(),
$configuration->getWorkingDirectory(),
);
}

public function testThatAddingMetricIsWorking(): void
{
$metric = self::createStub(Metric::class);
Expand Down

0 comments on commit 7b65a93

Please sign in to comment.