I'm extending Laravel's base TestCase
class to include my own assertion. Something like this:
<?php
namespace Tests\Mine;
use Tests\TestCase;
class SomeTest extends TestCase {
public function testSomethingIsWorking(): void {
$this->assertSomething("foo", "bar");
}
}
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
class TestCase extends BaseTestCase {
public function assertSomething($foo, $bar): void {
$this->assertSomethingElse($foo, $bar);
}
public function assertSomethingElse($foo, $bar): void {
if ($foo !== $bar) {
$this->fail("Some message here");
}
}
}
This works fine, but when I run artisan test
, a failure is triggered it shows the context of TestCase::assertSomethingElse()
. So I don't get to see where in the test the failure occurs; the output looks something like this:
FAILED Tests\Mine > something is working AssertionFailedError
Some message here
at tests/TestCase.php:10
9 | if ($foo !== bar)
➜ 10 | $this->fail("Some message here");
11 | }
1 tests/TestCase.php:10
2 tests/TestCase.php:5
This is Laravel-specific behaviour; if I just run vendor/bin/phpunit
no context is shown, and the stack trace does go back as far as the original test.
Is there a way I can get artisan test
to show the contextual lines from SomeTest::testSomethingIsWorking()
instead? Failing that, is there some way I can at least get the stack trace at the bottom to go back to the original test?