forked from tempestphp/tempest-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tempestphp#413 from tempestphp/discovery-cache-com…
…mand Discovery cache command
- Loading branch information
Showing
9 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Tempest/Console/src/Commands/DiscoveryCacheCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Console\Commands; | ||
|
||
use Tempest\Console\Console; | ||
use Tempest\Console\ConsoleCommand; | ||
use Tempest\Console\HasConsole; | ||
use Tempest\Container\Container; | ||
use Tempest\Core\Discovery; | ||
use Tempest\Core\Kernel; | ||
|
||
final readonly class DiscoveryCacheCommand | ||
{ | ||
use HasConsole; | ||
|
||
public function __construct( | ||
private Container $container, | ||
private Console $console, | ||
private Kernel $kernel, | ||
) { | ||
} | ||
|
||
#[ConsoleCommand( | ||
name: 'discovery:cache', | ||
description: 'Generate and store the discovery cache', | ||
aliases: ['discovery:store', 'discovery:warm'], | ||
)] | ||
public function __invoke(): void | ||
{ | ||
foreach ($this->kernel->discoveryClasses as $discoveryClass) { | ||
/** @var Discovery $discovery */ | ||
$discovery = $this->container->get($discoveryClass); | ||
|
||
$discovery->storeCache(); | ||
|
||
$this->writeln(sprintf( | ||
'<em>%s</em> cached successful', | ||
$discoveryClass, | ||
)); | ||
} | ||
|
||
$this->console->success('Done'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/Integration/Framework/Commands/DiscoveryCacheCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Tempest\Integration\Framework\Commands; | ||
|
||
use Tests\Tempest\Integration\Console\Commands\MyDiscovery; | ||
use Tests\Tempest\Integration\FrameworkIntegrationTestCase; | ||
|
||
/** | ||
* @internal | ||
* @small | ||
*/ | ||
final class DiscoveryCacheCommandTest extends FrameworkIntegrationTestCase | ||
{ | ||
public function test_it_clears_discovery_cache(): void | ||
{ | ||
MyDiscovery::$cached = false; | ||
|
||
$this->kernel->discoveryClasses = [MyDiscovery::class]; | ||
|
||
$this->console->call('discovery:cache'); | ||
|
||
$this->assertTrue(MyDiscovery::$cached); | ||
} | ||
} |