Ad
Missing TestCase::artisan() In Laravel 6.x Command Test
I've created a really basic console command test following the docs :
<?php
namespace Tests\Feature;
use PHPUnit\Framework\TestCase;
class QueueJobCommandTest extends TestCase
{
/**
* Test a job argument is requied
*
* @return void
*/
public function testNoArgumentsIsError()
{
$this->artisan('queue:job')
->expectsOutput('No job specified')
->assertExitCode(0);
}
}
but when I run phpunit i get the error:
Error: Call to undefined method Tests\Feature\QueueJobCommandTest::artisan()
Any help as to why TestCase::artisan()
is undefined woudl be greatly apprecated.
Ad
Answer
You have to extend the TestCase from Laravel which includes all the Laravel functions. The documentation is really good in that point.
https://laravel.com/docs/5.8/testing
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
}
That should solve your problem. Sometimes i make a class where i can add some special functions for authentication for example and extend from that class which extends from the Laravel TestCase class. Then you can add your custom functions in that class.
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad