Tweak path of options cache file

This commit is contained in:
Pig Fang 2019-12-23 23:28:46 +08:00
parent da422ab1e8
commit 0195b0fbd0
8 changed files with 11 additions and 11 deletions

1
.gitignore vendored
View File

@ -22,6 +22,7 @@ storage/*.sqlite
storage/oauth-public.key
storage/oauth-private.key
storage/install.lock
storage/options.php
.phpunit.result.cache
.php_cs.cache
resources/views/overrides

View File

@ -15,12 +15,13 @@ class OptionsCacheCommand extends Command
public function handle(Filesystem $filesystem, Application $app)
{
$path = storage_path('options/cache.php');
$path = storage_path('options.php');
$filesystem->delete($path);
$app->forgetInstance(Option::class);
$content = var_export(resolve(Option::class)->all(), true);
$content = '<?php'.PHP_EOL.'return '.$content.';';
$notice = '// This is auto-generated. DO NOT edit manually.'.PHP_EOL;
$content = '<?php'.PHP_EOL.$notice.'return '.$content.';';
$filesystem->put($path, $content);
$this->info('Options cached successfully.');
}

View File

@ -56,7 +56,7 @@ class UpdateController extends Controller
$package->download($this->info['url'], $path)->extract(base_path());
// Delete options cache. This allows us to update the version info which is recorded as an option.
$filesystem->delete(storage_path('options/cache.php'));
$filesystem->delete(storage_path('options.php'));
return json(trans('admin.update.complete'), 0);
} catch (Exception $e) {

View File

@ -13,7 +13,7 @@ class Option
public function __construct(Filesystem $filesystem)
{
$cachePath = storage_path('options/cache.php');
$cachePath = storage_path('options.php');
if ($filesystem->exists($cachePath)) {
$this->items = collect($filesystem->getRequire($cachePath));

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -11,11 +11,11 @@ class OptionsCacheCommandTest extends TestCase
{
$this->mock(Filesystem::class, function ($mock) {
$mock->shouldReceive('exists')->andReturn(false);
$mock->shouldReceive('delete')->with(storage_path('options/cache.php'))->once();
$mock->shouldReceive('delete')->with(storage_path('options.php'))->once();
$mock->shouldReceive('put')
->withArgs(function ($path, $content) {
$this->assertEquals(storage_path('options/cache.php'), $path);
$this->assertTrue(Str::startsWith($content, '<?php'.PHP_EOL.'return'));
$this->assertEquals(storage_path('options.php'), $path);
$this->assertTrue(Str::startsWith($content, '<?php'.PHP_EOL));
$this->assertTrue(Str::endsWith($content, ';'));
return true;

View File

@ -93,7 +93,7 @@ class UpdateControllerTest extends TestCase
$mock->shouldReceive('progress');
});
$this->mock(\Illuminate\Filesystem\Filesystem::class, function ($mock) {
$mock->shouldReceive('delete')->with(storage_path('options/cache.php'))->once();
$mock->shouldReceive('delete')->with(storage_path('options.php'))->once();
$mock->shouldReceive('exists')->with(storage_path('install.lock'))->andReturn(true);
});
$this->getJson('/admin/update/download?action=download')

View File

@ -31,7 +31,7 @@ class OptionTest extends TestCase
public function testReadFromCache()
{
$this->mock(\Illuminate\Filesystem\Filesystem::class, function ($mock) {
$path = storage_path('options/cache.php');
$path = storage_path('options.php');
$mock->shouldReceive('exists')->with($path)->once()->andReturn(true);
$mock->shouldReceive('getRequire')->with($path)->once()->andReturn(['k' => 'v']);
});