I have a simple console command that prints ‘Hello, World!’ into the terminal. It’s like this:
<?php
namespace AppConsoleCommands;
use IlluminateConsoleCommand;
class SimpleCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:simple-command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle()
{
$this->line('Hello, World!');
}
}
and I want to write a unit test for this command
<?php
namespace TestsUnitConsoleCommands;
use PHPUnitFrameworkTestCase;
class SimpleCommandTest extends TestCase
{
/**
* Test a console command.
*/
public function test_console_example(): void
{
$this->artisan();
}
}
But after I ran the test, I got an error says:
Call to undefined method TestsUnitConsoleCommandsSimpleCommandTest::artisan()
I’ve copied codes mostly from the documentation and suprised that they’re not working. Is there anything I’m missing? Or do I need to install some package? Or am I in the wrong namespace or something?