Laravel-artisan-commands

提供:Dev Guides
移動先:案内検索

Laravel-アーティザンコマンド

Laravel 5.7には、新しいコマンドを処理およびテストする新しい方法が付属しています。 それは職人のコマンドをテストする新機能が含まれており、デモは以下に記載されています-

class ArtisanCommandTest extends TestCase{
   public function testBasicTest() {
      $this->artisan('nova:create', [
         'name' => 'My New Admin panel'
      ])
      ->expectsQuestion('Please enter your API key', 'apiKeySecret')
      ->expectsOutput('Authenticating...')
      ->expectsQuestion('Please select a version', 'v1.0')
      ->expectsOutput('Installing...')
      ->expectsQuestion('Do you want to compile the assets?', 'yes')
      ->expectsOutput('Compiling assets...')
      ->assertExitCode(0);
   }
}

コードの説明

ここでは、「ArtisanCommandTest」という名前の新しいクラスがテストケースモジュールの下に作成されます。 アサーションのさまざまな機能を含む基本機能 testBasicTest が含まれています。

アーティザンコマンド expectsQuestion には2つの属性が含まれています。 1つは質問あり、もう1つは apiKeySecret です。 ここで、職人はapiKeySecretを検証し、ユーザーから送信された入力を検証します。

ユーザーが特定のバージョンに言及することが予想される「バージョンを選択してください」という質問にも同じシナリオが適用されます。