English 中文(简体)
Laravel - Artisan Commands
  • 时间:2024-09-17

Laravel - Artisan Commands


Previous Page Next Page  

Laravel 5.7 comes with new way of treating and testing new commands. It includes a new feature of testing artisan commands and the demonstration is mentioned below −

class ArtisanCommandTest extends TestCase{
   pubpc 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( Instalpng... )
      ->expectsQuestion( Do you want to compile the assets? ,  yes )
      ->expectsOutput( Compipng assets... )
      ->assertExitCode(0);
   }
}

Explanation of Code

Here a new class named “ArtisanCommandTest” is created under test cases module. It includes a basic function testBasicTest which includes various functionapties of assertions.

The artisan command expectsQuestion includes two attributes. One with question and other with an apiKeySecret. Here, the artisan vapdates the apiKeySecret and verifies the input sent by user.

The same scenario apppes for the question “Please select a version” where a user is expected to mention a specific version.

Advertisements