Replies: 4 comments 3 replies
-
|
See https://laravel.com/docs/12.x/console-tests#console-events |
Beta Was this translation helpful? Give feedback.
-
|
Of course I know about this BUT it also does not work. I have Illuminate\Foundation\Testing\WithConsoleEvents trait included in my test classes. You can run it? <?php
namespace Tests;
use Database\Seeders\TestsSeeders\TestDatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\WithConsoleEvents;
use Illuminate\Support\Facades\Log;
abstract class TestCase extends BaseTestCase
{
/** Clear the database */
use RefreshDatabase;
/** This is necessary because tests does not trigger CommandFinished event by default */
use WithConsoleEvents;
/**
* Indicates whether the default seeder should run before each test.
*
* With ParallelTestingExtendedServiceProvider, each parallel process gets its own
* isolated databases (resources_test_1.sqlite, resources_test_2.sqlite, etc.)
* Laravel will automatically seed these databases using the seeder below.
*/
protected $seed = true;
/**
* The seeder class to run before each test.
*/
protected $seeder = TestDatabaseSeeder::class;
/**
* @return void
*/
protected function tearDown(): void
{
// some custom logic....
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Hey there! This is actually expected behavior in Laravel - by default, The fix is simple - just add the For PHPUnit: <?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\WithConsoleEvents;
use Tests\TestCase;
class YourTest extends TestCase
{
use WithConsoleEvents;
// your test methods...
}For Pest: <?php
use Illuminate\Foundation\Testing\WithConsoleEvents;
pest()->use(WithConsoleEvents::class);Once you add this trait, your This is documented in the Console Tests documentation under the events section. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
Hmm this is little sad.... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
12.0
PHP Version
8.2.6
Database Driver & Version
No response
Description
I would like to use Illuminate\Console\Events\CommandFinished to handle all tests result as one bunch of data. So I decided to use CommandFinished which seems to fit perfectly my needs. BUT as I found out this event works fine with any other artisan commands but not with test command. I made some simple logs in listener handle method and as I said every artisan command works fine BUT test command does not trigger the event.
Steps To Reproduce
I have CommanfFinishedListener class which listen for CommandFinished event registered. I see the listener is registered properly. I also see the listern and event works fine with any other artisan commands but not with test command. This is my
Beta Was this translation helpful? Give feedback.
All reactions