Home > PHP Framework > Laravel > body text

Laravel - Artisan Commands

WBOY
Release: 2024-08-27 11:46:34
Original
898 people have browsed it

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{
   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);
   }
}
Copy after login

Explanation of Code

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

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

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

The above is the detailed content of Laravel - Artisan Commands. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template