Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed May 30, 2024
1 parent 6b5e97b commit b3b0b46
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Tests">
Expand Down
42 changes: 42 additions & 0 deletions src/Commands/DiscoveryClearCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Tempest\Console\Commands;

use Tempest\AppConfig;
use Tempest\Console\Console;
use Tempest\Console\ConsoleCommand;
use Tempest\Container\Container;
use Tempest\Discovery\Discovery;

final readonly class DiscoveryClearCommand
{
public function __construct(
private Container $container,
private Console $console,
private AppConfig $appConfig,
) {
}

#[ConsoleCommand(
name: 'discovery:clear',
description: 'Clear all cached discovery files',
)]
public function __invoke(): void
{
foreach ($this->appConfig->discoveryClasses as $discoveryClass) {
/** @var Discovery $discovery */
$discovery = $this->container->get($discoveryClass);

$discovery->destroyCache();

$this->console->writeln(implode('', [
"<em>{$discoveryClass}</em>",
' cleared successful',
]));
}

$this->console->writeln('Done');
}
}
39 changes: 39 additions & 0 deletions src/Commands/DiscoveryStatusCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Tempest\Console\Commands;

use Tempest\AppConfig;
use Tempest\Console\Console;
use Tempest\Console\ConsoleCommand;

final readonly class DiscoveryStatusCommand
{
public function __construct(
private Console $console,
private AppConfig $appConfig,
) {
}

#[ConsoleCommand(
name: 'discovery:status',
description: 'List all discovery locations and discovery classes'
)]
public function __invoke(): void
{
$this->console->info('Loaded Discovery classes');

foreach ($this->appConfig->discoveryClasses as $discoveryClass) {
$this->console->writeln('- ' . $discoveryClass);
}

$this->console->writeln();

$this->console->info('Folders included in Tempest');

foreach ($this->appConfig->discoveryLocations as $discoveryLocation) {
$this->console->writeln('- '. $discoveryLocation->path);
}
}
}
6 changes: 6 additions & 0 deletions src/ConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function __serialize(): array
'handler_method' => $this->handler->getName(),
'aliases' => $this->aliases,
'help' => $this->help,
'middleware' => $this->middleware,
'hidden' => $this->hidden,
'complete' => $this->complete,
];
}

Expand All @@ -70,6 +73,9 @@ public function __unserialize(array $data): void
);
$this->aliases = $data['aliases'];
$this->help = $data['help'];
$this->middleware = $data['middleware'];
$this->hidden = $data['hidden'];
$this->complete = $data['complete'];
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected function setUp(): void
$appConfig = new AppConfig(
root: getcwd(),
enableExceptionHandling: true,
discoveryCache: true,
discoveryLocations: [
new DiscoveryLocation('Tests\\Tempest\\Console\\', __DIR__),
],
Expand Down
7 changes: 7 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

require_once __DIR__ . '/../vendor/autoload.php';

passthru('./tempest discovery:clear');

0 comments on commit b3b0b46

Please sign in to comment.