i want to run phpunit test in controller for
adding some data in database and testing api of project both
PostAddTest класс
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class PostAddTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$api = "/post/add";
$request = [
'title' => "xyz form....",
'content' => 'post add by xyz user.'
];
$response = $this->postJson($api,$request);
info("daa : ".print_r($response->getContent(),true));
$this->assertTrue(true);
}
}
если я использую phpunit, то успешно работаю
vendor/phpunit/bin --filter testExample
PHPUnit 6.5.5 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 6.84 seconds, Memory: 28.00MB
OK (1 test, 1 assertion)
я добился успеха, но
если я запускаю с использованием контроллера, то получаю ошибку, подобную этой
Вызов функции-члена make () для null {"exception": "[object]
(Symfony \ Component \ Debug \ Exception \ FatalThrowableError (код: 0):
Вызов функции-члена make () для null в
PostProject / поставщик / Laravel / рамки / SRC / Осветите / Foundation / Тестирование / вопросы / MakesHttpRequests.php: 335
MainController
public function index() {
(new PostAddTest)->testExample()
}