Cómo Probar Comandos Artesanales en Laravel 5


Construyo un comando Artisan para recibir datos de un socket, y quiero escribir una prueba unitaria para este comando, pero no estoy seguro de cómo escribir tal prueba.

¿Alguien tiene una idea de cómo escribirlo?

Author: mnv, 2015-11-09

2 answers

Ahora es mucho más fácil:

<?php

class YourCommandTest extends TestCase
{

    public function testExample()
    {
        $this->artisan('command', ['param' => 'value']);
    }

}
 20
Author: Roma Rush,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-08 11:50:10

Ejemplo de prueba

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class YourCommandTest extends TestCase
{
    use DatabaseTransactions;

    public function testExample()
    {
        Artisan::call('your_command', [
            'command_parameter_1' => 'value1',
            'command_parameter_2' => 'value2',
        ]);

        // If you need result of console output
        $resultAsText = Artisan::output();

        $this->assertTrue(true);
    }

}
 34
Author: mnv,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-04 09:26:03