Shinsei Hasu
Shinsei Hasu

Reputation: 11

How to fix 'PHP Fatal error: Uncaught TypeError: getTest() parameter' error in PHPUnit

I’m setting up the PHP Unit in my Laravel project, but I'm receiving Fatal Error in my first run. Can someone give a help?

I'm running in my Laravel Project, using Laravel 5.2.45, PHP 7.3.2 and PHPUnit 7.2.19. This is my first time trying to do some tests, but I always receive error, when I execute my test.

I expect when I run the phpunit receive the asset true, but I'm receiving the follow error:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to PHPUnit\Runner\BaseTestRunner::getTest() must be of the type string, object given, called in /usr/share/php/PHPUnit/TextUI/Command.php on line 180 and defined in /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:59 Stack trace:

0 /usr/share/php/PHPUnit/TextUI/Command.php(180): PHPUnit\Runner\BaseTestRunner->getTest(Object(PHPUnit\Framework\TestSuite), '', Array)

1 /usr/share/php/PHPUnit/TextUI/Command.php(159): PHPUnit\TextUI\Command->run(Array, true)

2 /usr/bin/phpunit(34): PHPUnit\TextUI\Command::main()

3 {main} thrown in /usr/share/php/PHPUnit/Runner/BaseTestRunner.php on line 59


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);
    }
}

Upvotes: 1

Views: 3351

Answers (2)

Yousha Aleayoub
Yousha Aleayoub

Reputation: 5618

For those pep who maintaining old Laravel projects:
When maintaining old projects, you should keep the ecosystem as it is... So:

Laravel 5.2 requires PHP 5.6 and PHPUnit 4.0 https://raw.githubusercontent.com/laravel/laravel/refs/heads/5.2/composer.json

This error typically happens when there’s a compatibility issue between PHPUnit versions and your Laravel/PHP setup. In this case, PHPUnit 7 is not fully compatible with PHP 7.3, especially when working with an older version of Laravel (like Laravel 5.2), which expects PHPUnit 6 or earlier.

So use PHP 5.6 and install PHPUnit 4 with the following command: composer require phpunit/phpunit:4.*.

Upvotes: 0

Konorlevich
Konorlevich

Reputation: 65

See documentation

You have to create your test by command

// Create a test in the Unit directory...
php artisan make:test UserTest --unit

If you already did so, check your Tests\TestCase, run composer dump-autoload and try again

Also you can use Codeception with Laravel5 module for your tests

Upvotes: -1

Related Questions