命令行测试

更新时间: 2019-07-31 20:15

期望输入/输出

Laravel 允许你使用 expectsQuestion 方法轻松地为控制台命令「模拟」用户输入。此外,你可以使用 assertExitCodeexpectsOutput 方法指定控制台命令退出码和期望输出文本。举个例子,想想下面这个控制台命令:

Artisan::command('question', function () {
    $name = $this->ask('What is your name?');

    $language = $this->choice('Which language do you program in?', [
        'PHP',
        'Ruby',
        'Python',
    ]);

    $this->line('Your name is '.$name.' and you program in '.$language.'.');
});

你可以使用下面的测试代码来测试命令,其中使用了 expectsQuestionexpectsOutputassertExitCode 方法:

/**
 * 测试控制台命令。
 *
 * @return  void
 */
public function test_console_command()
{
    $this->artisan('laracon')
         ->expectsQuestion('What is your name?', 'Taylor Otwell')
         ->expectsQuestion('Which language do you program in?', 'PHP')
         ->expectsOutput('Your name is Taylor Otwell and you program in PHP.')
         ->assertExitCode(0);
}
Mastering Regular Expressions, Second Edition

Mastering Regular Expressions, Second Edition

Jeffrey E F Friedl / O'Reilly Media / 2002-07-15 / USD 39.95

Regular expressions are an extremely powerful tool for manipulating text and data. They have spread like wildfire in recent years, now offered as standard features in Perl, Java, VB.NET and C# (and an......一起来看看 《Mastering Regular Expressions, Second Edition》 这本书的介绍吧!

JS 压缩/解压工具

JS 压缩/解压工具

在线压缩/解压 JS 代码

URL 编码/解码

URL 编码/解码

URL 编码/解码

正则表达式在线测试

正则表达式在线测试

正则表达式在线测试