1
votes

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

1
Did you find a solution? ā€“ luckydonald
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... ā€“ Shinsei Hasu

1 Answers

-1
votes

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