1

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

2
  • Did you find a solution? Commented Sep 11, 2019 at 15:32
  • Hello. Yes, I find it yesterday. I have to stop this project to work in another. Yesterday I came back and the problem was I'm trying to execute in wrong directory. But now I have another problem when I try to execute a teste file with more than one function... Commented Sep 12, 2019 at 12:02

2 Answers 2

0

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.*.

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

Comments

-1

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

1 Comment

Thanks. The problem was I trying to execute phpunit in the wrong directory. Thanks for the help.

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.