D
D
dy_ma2021-09-06 20:03:31
PHPUnit
dy_ma, 2021-09-06 20:03:31

Why was the ::get method not found when creating a request inside a test unit?

I'm trying to make a GET request to an application inside a test, and I'm getting the following error:

Error: Call to undefined method App\Http\Controllers\StepsControllerTest::get()

The example is taken from the documentation for tests in Laravel, and here where namespace and use are, I don’t understand what’s going on.
It seems like other methods provided by the testing library are present, but for some reason the test class did not inherit get.

namespace Tests\Unit;
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use PHPUnit\Framework\TestCase;

class StepsControllerTest extends TestCase
{
    public function testIndex() {
        $response = $this->get('/');
        $this->assertTrue(true);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-09-06
@dy_ma

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Tests\TestCase;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question