From 8e2b2c78fc37783549cc346d2b35d84b73bbc7b7 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 12 Jul 2018 17:18:19 +0800 Subject: [PATCH] fix for tests --- app/Http/Controllers/UpdateController.php | 17 +++++++++++++++++ tests/UpdateControllerTest.php | 12 ++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/UpdateController.php b/app/Http/Controllers/UpdateController.php index 35e94044..7c0b6b48 100644 --- a/app/Http/Controllers/UpdateController.php +++ b/app/Http/Controllers/UpdateController.php @@ -32,6 +32,8 @@ class UpdateController extends Controller public function showUpdatePage() { + $this->refreshInfo(); + $info = [ 'latest_version' => '', 'current_version' => $this->currentVersion, @@ -87,6 +89,8 @@ class UpdateController extends Controller public function checkUpdates() { + $this->refreshInfo(); + return json([ 'latest' => $this->getUpdateInfo('latest_version'), 'available' => $this->newVersionAvailable() @@ -102,6 +106,8 @@ class UpdateController extends Controller public function download(Request $request) { + $this->refreshInfo(); + $action = $request->input('action'); if (! $this->newVersionAvailable()) return; @@ -243,4 +249,15 @@ class UpdateController extends Controller return Arr::get($this->getUpdateInfo('releases'), $version); } + /** + * Only used in testing. + */ + protected function refreshInfo() + { + if (config('app.env') == 'testing') { + $this->updateSource = option('update_source'); + $this->currentVersion = config('app.version'); + } + } + } diff --git a/tests/UpdateControllerTest.php b/tests/UpdateControllerTest.php index 0d85dd49..407b1194 100644 --- a/tests/UpdateControllerTest.php +++ b/tests/UpdateControllerTest.php @@ -60,6 +60,7 @@ class UpdateControllerTest extends TestCase { option(['update_source' => 'http://xxx.xx/']); $this->visit('/admin/update') + ->see(trans('admin.update.info.pre-release')) ->see(trans('admin.update.errors.connection')) ->see(config('app.version')) ->uncheck('check_update') @@ -71,18 +72,13 @@ class UpdateControllerTest extends TestCase option('update_source') ); + option(['update_source' => vfs\vfsStream::url('root/update.json')]); $time = $this->generateFakeUpdateInfo('4.0.0'); $this->visit('/admin/update') ->see(config('app.version')) ->see('4.0.0') ->see('test') ->see($time); - - file_put_contents(vfs\vfsStream::url('root/update.json'), json_encode([ - 'latest_version' => '4.0.0' - ])); - $this->visit('/admin/update') - ->see(trans('admin.update.info.pre-release')); } public function testCheckUpdates() @@ -117,12 +113,12 @@ class UpdateControllerTest extends TestCase Storage::disk('root')->deleteDirectory('storage/update_cache'); $this->generateFakeUpdateInfo('4.0.0'); Storage::shouldReceive('disk') - ->with('root') ->once() + ->with('root') ->andReturnSelf(); Storage::shouldReceive('makeDirectory') - ->with('storage/update_cache') ->once() + ->with('storage/update_cache') ->andReturn(false); $this->get('/admin/update/download?action=prepare-download') ->see(trans('admin.update.errors.write-permission'));