Improve UX of plugin-related Artisan commands

This commit is contained in:
Pig Fang 2019-08-16 17:35:13 +08:00
parent bf778e9405
commit eeec2e0435
4 changed files with 36 additions and 4 deletions

View File

@ -28,6 +28,12 @@ class PluginDisableCommand extends Command
*/
public function handle(PluginManager $plugins)
{
$plugins->disable($this->argument('name'));
$plugin = $plugins->get($this->argument('name'));
if ($plugin) {
$plugins->disable($this->argument('name'));
$this->info(trans('admin.plugins.operations.disabled', ['plugin' => $plugin->title]));
} else {
$this->warn(trans('admin.plugins.operations.not-found'));
}
}
}

View File

@ -28,6 +28,12 @@ class PluginEnableCommand extends Command
*/
public function handle(PluginManager $plugins)
{
$plugins->enable($this->argument('name'));
$plugin = $plugins->get($this->argument('name'));
if ($plugin) {
$plugins->enable($this->argument('name'));
$this->info(trans('admin.plugins.operations.enabled', ['plugin' => $plugin->title]));
} else {
$this->warn(trans('admin.plugins.operations.not-found'));
}
}
}

View File

@ -2,6 +2,7 @@
namespace Tests;
use App\Services\Plugin;
use App\Services\PluginManager;
class PluginDisableCommandTest extends TestCase
@ -9,8 +10,17 @@ class PluginDisableCommandTest extends TestCase
public function testDisablePlugin()
{
$this->mock(PluginManager::class, function ($mock) {
$mock->shouldReceive('get')->with('nope')->once()->andReturn(null);
$mock->shouldReceive('get')
->with('my-plugin')
->once()
->andReturn(new Plugin('', ['title' => 'My Plugin']));
$mock->shouldReceive('disable')->with('my-plugin')->once();
});
$this->artisan('plugin:disable my-plugin');
$this->artisan('plugin:disable nope')
->expectsOutput(trans('admin.plugins.operations.not-found'));
$this->artisan('plugin:disable my-plugin')
->expectsOutput(trans('admin.plugins.operations.disabled', ['plugin' => 'My Plugin']));
}
}

View File

@ -2,6 +2,7 @@
namespace Tests;
use App\Services\Plugin;
use App\Services\PluginManager;
class PluginEnableCommandTest extends TestCase
@ -9,8 +10,17 @@ class PluginEnableCommandTest extends TestCase
public function testEnablePlugin()
{
$this->mock(PluginManager::class, function ($mock) {
$mock->shouldReceive('get')->with('nope')->once()->andReturn(null);
$mock->shouldReceive('get')
->with('my-plugin')
->once()
->andReturn(new Plugin('', ['title' => 'My Plugin']));
$mock->shouldReceive('enable')->with('my-plugin')->once();
});
$this->artisan('plugin:enable my-plugin');
$this->artisan('plugin:enable nope')
->expectsOutput(trans('admin.plugins.operations.not-found'));
$this->artisan('plugin:enable my-plugin')
->expectsOutput(trans('admin.plugins.operations.enabled', ['plugin' => 'My Plugin']));
}
}