Refactor
This commit is contained in:
parent
6aa28f88e7
commit
65d82fba64
|
|
@ -10,7 +10,6 @@ use Illuminate\Database\Connection;
|
|||
use Illuminate\Filesystem\Filesystem;
|
||||
use App\Exceptions\PrettyPageException;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use Illuminate\Contracts\Console\Kernel as Artisan;
|
||||
|
||||
class SetupController extends Controller
|
||||
|
|
@ -165,24 +164,4 @@ class SetupController extends Controller
|
|||
'email' => $request->input('email'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Filesystem $filesystem, Artisan $artisan)
|
||||
{
|
||||
collect($filesystem->files(database_path('update_scripts')))
|
||||
->filter(function (SplFileInfo $file) {
|
||||
$name = $file->getFilenameWithoutExtension();
|
||||
|
||||
return preg_match('/^\d+\.\d+\.\d+$/', $name) > 0
|
||||
&& Comparator::greaterThanOrEqualTo($name, option('version'));
|
||||
})
|
||||
->each(function (SplFileInfo $file) use ($filesystem) {
|
||||
$filesystem->getRequire($file->getPathname());
|
||||
});
|
||||
|
||||
option(['version' => config('app.version')]);
|
||||
$artisan->call('view:clear');
|
||||
$filesystem->put(storage_path('install.lock'), '');
|
||||
|
||||
return view('setup.updates.success');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ use Illuminate\Http\Request;
|
|||
use Composer\Semver\Comparator;
|
||||
use App\Services\PackageManager;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use Illuminate\Contracts\Console\Kernel as Artisan;
|
||||
|
||||
class UpdateController extends Controller
|
||||
{
|
||||
|
|
@ -69,6 +71,27 @@ class UpdateController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
public function update(Filesystem $filesystem, Artisan $artisan)
|
||||
{
|
||||
collect($filesystem->files(database_path('update_scripts')))
|
||||
->filter(function (SplFileInfo $file) {
|
||||
$name = $file->getFilenameWithoutExtension();
|
||||
|
||||
return preg_match('/^\d+\.\d+\.\d+$/', $name) > 0
|
||||
&& Comparator::greaterThanOrEqualTo($name, option('version'));
|
||||
})
|
||||
->each(function (SplFileInfo $file) use ($filesystem) {
|
||||
$filesystem->getRequire($file->getPathname());
|
||||
});
|
||||
|
||||
option(['version' => config('app.version')]);
|
||||
$artisan->call('migrate', ['--force' => true]);
|
||||
$artisan->call('view:clear');
|
||||
$filesystem->put(storage_path('install.lock'), '');
|
||||
|
||||
return view('setup.updates.success');
|
||||
}
|
||||
|
||||
protected function getUpdateInfo()
|
||||
{
|
||||
$acceptableSpec = 2;
|
||||
|
|
|
|||
|
|
@ -179,6 +179,6 @@ Route::group(['prefix' => 'setup'], function () {
|
|||
|
||||
Route::group(['middleware' => 'authorize'], function () {
|
||||
Route::view('/update', 'setup.updates.welcome')->middleware('setup');
|
||||
Route::any('/exec-update', 'SetupController@update')->middleware('setup');
|
||||
Route::any('/exec-update', 'UpdateController@update')->middleware('setup');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ namespace Tests;
|
|||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use Illuminate\Contracts\Console\Kernel as Artisan;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
|
|
@ -192,46 +191,4 @@ class SetupControllerTest extends TestCase
|
|||
$this->assertEquals('nickname', $superAdmin->nickname);
|
||||
$this->assertEquals('bs', option('site_name'));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$this->mock(Filesystem::class, function ($mock) {
|
||||
$mock->shouldReceive('exists')
|
||||
->with(storage_path('install.lock'))
|
||||
->andReturn(true);
|
||||
|
||||
$mock->shouldReceive('put')
|
||||
->with(storage_path('install.lock'), '')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
|
||||
$mock->shouldReceive('files')
|
||||
->with(database_path('update_scripts'))
|
||||
->once()
|
||||
->andReturn([
|
||||
new SplFileInfo('/1.0.0.php', '', ''),
|
||||
new SplFileInfo('/99.0.0.php', '', ''),
|
||||
new SplFileInfo('/100.0.0.php', '', ''),
|
||||
]);
|
||||
|
||||
$mock->shouldNotReceive('getRequire')->with('/1.0.0.php');
|
||||
|
||||
$mock->shouldReceive('getRequire')
|
||||
->with('/99.0.0.php')
|
||||
->once();
|
||||
|
||||
$mock->shouldReceive('getRequire')
|
||||
->with('/100.0.0.php')
|
||||
->once();
|
||||
});
|
||||
$this->spy(Artisan::class, function ($spy) {
|
||||
$spy->shouldReceive('call')->with('view:clear')->once();
|
||||
});
|
||||
config(['app.version' => '100.0.0']);
|
||||
|
||||
$this->actAs('superAdmin')
|
||||
->get('/setup/exec-update')
|
||||
->assertViewIs('setup.updates.success');
|
||||
$this->assertEquals('100.0.0', option('version'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,11 @@ namespace Tests;
|
|||
use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use App\Services\PackageManager;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Tests\Concerns\MocksGuzzleClient;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Contracts\Console\Kernel as Artisan;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class UpdateControllerTest extends TestCase
|
||||
|
|
@ -109,6 +112,51 @@ class UpdateControllerTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$this->mock(Filesystem::class, function ($mock) {
|
||||
$mock->shouldReceive('exists')
|
||||
->with(storage_path('install.lock'))
|
||||
->andReturn(true);
|
||||
|
||||
$mock->shouldReceive('put')
|
||||
->with(storage_path('install.lock'), '')
|
||||
->once()
|
||||
->andReturn(true);
|
||||
|
||||
$mock->shouldReceive('files')
|
||||
->with(database_path('update_scripts'))
|
||||
->once()
|
||||
->andReturn([
|
||||
new SplFileInfo('/1.0.0.php', '', ''),
|
||||
new SplFileInfo('/99.0.0.php', '', ''),
|
||||
new SplFileInfo('/100.0.0.php', '', ''),
|
||||
]);
|
||||
|
||||
$mock->shouldNotReceive('getRequire')->with('/1.0.0.php');
|
||||
|
||||
$mock->shouldReceive('getRequire')
|
||||
->with('/99.0.0.php')
|
||||
->once();
|
||||
|
||||
$mock->shouldReceive('getRequire')
|
||||
->with('/100.0.0.php')
|
||||
->once();
|
||||
});
|
||||
$this->spy(Artisan::class, function ($spy) {
|
||||
$spy->shouldReceive('call')
|
||||
->with('migrate', ['--force' => true])
|
||||
->once();
|
||||
$spy->shouldReceive('call')->with('view:clear')->once();
|
||||
});
|
||||
config(['app.version' => '100.0.0']);
|
||||
|
||||
$this->actAs('superAdmin')
|
||||
->get('/setup/exec-update')
|
||||
->assertViewIs('setup.updates.success');
|
||||
$this->assertEquals('100.0.0', option('version'));
|
||||
}
|
||||
|
||||
protected function mockFakeUpdateInfo(string $version, $extra = [])
|
||||
{
|
||||
return json_encode(array_merge([
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user