Tweak options:cache command

This commit is contained in:
Pig Fang 2019-08-22 08:50:59 +08:00
parent e01f034ffd
commit 197c3d8333
2 changed files with 8 additions and 21 deletions

View File

@ -12,25 +12,11 @@ class OptionsCacheCommand extends Command
protected $description = 'Cache Blessing Skin options'; protected $description = 'Cache Blessing Skin options';
/** @var Filesystem */ public function handle(Filesystem $filesystem, Option $options)
protected $filesystem;
/** @var Option */
protected $options;
public function __construct(Filesystem $filesystem, Option $options)
{ {
parent::__construct(); $content = var_export($options->all(), true);
$this->filesystem = $filesystem;
$this->options = $options;
}
public function handle()
{
$content = var_export($this->options->all(), true);
$content = '<?php'.PHP_EOL.'return '.$content.';'; $content = '<?php'.PHP_EOL.'return '.$content.';';
$this->filesystem->put(storage_path('options/cache.php'), $content); $filesystem->put(storage_path('options/cache.php'), $content);
$this->info('Options cached successfully.'); $this->info('Options cached successfully.');
} }
} }

View File

@ -9,16 +9,17 @@ class OptionsCacheCommandTest extends TestCase
{ {
public function testRun() public function testRun()
{ {
/*$this->mock(Filesystem::class, function ($mock) { $this->mock(Filesystem::class, function ($mock) {
$mock->shouldReceive('put') $mock->shouldReceive('put')
/*->withArgs(function ($path, $content) { ->withArgs(function ($path, $content) {
$this->assertEquals(storage_path('options/cache.php'), $path); $this->assertEquals(storage_path('options/cache.php'), $path);
$this->assertTrue(Str::startsWith($content), '<?php'); $this->assertTrue(Str::startsWith($content, '<?php'.PHP_EOL.'return'));
$this->assertTrue(Str::endsWith($content, ';'));
return true; return true;
}) })
->once(); ->once();
});*/ });
$this->artisan('options:cache')->expectsOutput('Options cached successfully.'); $this->artisan('options:cache')->expectsOutput('Options cached successfully.');
} }