📜  Laravel-工匠命令

📅  最后修改于: 2020-10-23 08:11:27             🧑  作者: Mango


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包含两个属性。一个带问题,另一个带apiKeySecret 。在这里,技术人员验证apiKeySecret并验证用户发送的输入。

同样的情况适用于“请选择一个版本”问题,要求用户提及特定版本。