6

where running all test php artisan test everything work as expected and all tests runs

enter image description here

now , when i run signle test php artisan test --filter test_get_profile i get this wired error

An error occurred inside PHPUnit.

Message:  Cannot find TestCase object on call stack
Location: D:\laragon\www\project\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:68

but some other tests still work, for example, test_login and test_register works , but when i create a new test sometimes it work sometimes i get this wired error

PS: i add the file path example php artisan test tests/Feature/AccountTest.php --filter test_get_profile i didnt get any error , but i dont what to always include the file path

please note that all tests are empty

public function test_get_profile(): void
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }

anyone know the issue ? i'm using laravel 10 and phpunit 10

phpunit.xml:

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         colors="true"
>
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <source>
        <include>
            <directory suffix=".php">./app</directory>
        </include>
    </source>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <!-- <env name="DB_CONNECTION" value="sqlite"/> -->
        <!-- <env name="DB_DATABASE" value=":memory:"/> -->
        <env name="MAIL_MAILER" value="array"/>
        <env name="QUEUE_CONNECTION" value="sync"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="TELESCOPE_ENABLED" value="false"/>
    </php>
</phpunit>

UserTest.php


namespace Tests\Feature;

use Tests\TestCase;

class UserTest extends TestCase
{
    public function test_login(): void
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }

    public function test_register(): void
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

AccountTest.php


namespace Tests\Feature;

use Tests\TestCase;

class AccountTest extends TestCase
{
    /**
     * A basic feature test example.
     */
    public function test_get_profile(): void
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}
4
  • Could you show us what tests\TestCase.php has? Did you modify the original file? Commented Jun 3, 2023 at 19:40
  • I also experiencing it now. I'm still looking for solution. Commented Jun 4, 2023 at 0:45
  • No, i didn't change any things , it's new f fresh Laravel 10 app Commented Jun 4, 2023 at 13:11
  • I am seeing the same thing too but on an existing application. Commented Jun 5, 2023 at 2:28

1 Answer 1

8

This was a bug in PHPUnit.

https://github.com/sebastianbergmann/phpunit/issues/5403

This is the fix -

https://github.com/sebastianbergmann/phpunit/commit/16166431bce84bb100d8e7fe867d612bdfe61776#diff-548ab8441af390a03ab9bf5e83a441aaa67c43de14b247a1426c2983b434bd89

Run a composer update to get the latest version.

Sign up to request clarification or add additional context in comments.

6 Comments

Downgrading to 10.1.3 fixed it for me. Thanks!
A fix has been released in PHPUnit 10.2.1, see github.com/sebastianbergmann/phpunit/blob/10.2/…
I still get this error after upgrading to 10.2.1 :(
Same problem here with phpunit 10.3.5. Did you find a solution @st-jan ?
If anyone else comes across this issue, I found the issue was with (at least for me) the .phpunit.result.caceh file. Once I deleted the original .phpunit.result.cache file and reran phpunit, it works as expected.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.