Strange error in phpunit when I add RefreshDatabase to any test
Hi all,
I was running tests with artisan test and they were working fine. Then I tried phpunit and got the following error
1) Tests\Feature\ExampleTest::test_the_application_returns_a_successful_response
Error: Call to undefined function Illuminate\Console\View\Components\Mutators\str()
I actually got that same error on all tests so then trying to narrow down the issue I decided to run only the example feature test that comes with laravel. If I add use RefreshDatabase to the test class and run phpunit I get the above error. But it works and passes if I run php artisan test.
Anyone else run into this? This is on Laravel 9.28
@sinnbeck Yes I just created a new laravel app with "laravel new footest", deleted the example unit test and left only the example feature test. artisan test works and phpunit works until I add "use RefreshDatabase"
Failing test
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
use RefreshDatabase;
/**
* A basic test example.
*
* @return void
*/
public function test_the_application_returns_a_successful_response()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
Tests/TestCase;
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
}
I just noticed those last 2 lines in the stacktrace are paths to a completely different laravel project.
I could not find reference to that path anywhere in phpstorm settings, system env's , or composer files.
When I specifically ran a projects local vendor/bin/phpunit the problem disappeared.
Somehow some reference to that project got stored somewhere in my global install of phpunit so even though the "which" and "where" commands were showing phpunit as coming from the global composer directory, composer was then running phpunit out of that other project.
I ended up having to remove global phpunit and reinstall it to get the problem fixed.