jeudi 28 mars 2019

Laravel Testing/phpunit, Too few arguments passed when using dependency injection

I'm trying to create a simple test with Laravel. My test code is as below;

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Http\Controllers\Abc\AbcController;

class AbcTest extends TestCase
{

 /**
 * A basic test example.
 *
 * @return void
 */

private $abcController;

public function __construct (AbcController $abcController) {
    $this->abcController = $abcController;
}

public function testExample()
{
    $this->assertTrue(true);
}

However, when i run the test, i'm hitting this error,

PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Tests\Feature\abc::__construct(), 0 passed in /var/www/nex/backend/vendor/phpunit/phpunit/src/Framework/TestSuite.php on line 151 and exactly 1 expected in /var/www/nex/backend/tests/Feature/abc.php:28

I've been using this method of performing dependency injections for the rest of my project. I'm not sure why its not working on this particular code.

All help is appreciated.

Thanks!

Aucun commentaire:

Enregistrer un commentaire