HTTP Tests - gricob/functional-test-bundle GitHub Wiki

Making HTTP Requests

Request with GET method

$response = $this->get('/uri');

Request with POST method

$response = $this->post('/uri');

Request with logged user

$this->loadFixtures([LoadUserData::class]);

$user = $this->getReference(LoadUserData::USER);

$response = $this->loginAs($user)->get('/uri');

Getting the Crawler

$crawler = $response->getCrawler();

Assertions

assertOk

Assert that the response has a 200 status code

$response->assertOk();

assertNotFound

Assert that the response has a not found status code

$response->assertNotFound();

assertForbidden

Assert that the response has a forbidden status code

$response->assertForbidden();

assertUnauthorized

Assert that the response has a forbidden status code

$response->assertUnauthorized();

assertRedirect

Assert that the response is a redirect. If a redirect url is provided assert that the redirect location match that url.

$response->assertRedirect();

$response->assertRedirect('/your-url');

assertSee

Assert that the given string is contained within the response

$response->assertSee('Assert that response content has this text');

assertSeeAll

Assert that the given strings are contained within the response

$response->assertSeeAll(['First needle', 'Second needle']);

assertDontSee

Assert that the given string is not contained within the response

$response->assertDontSee('Assert that response content does not have this text');

assertDontSeeAny

Assert that the given strings are not contained within the response

$response->assertDontSeeAny(['First needle', 'Second needle']);

assertExactJson

Assert that the response contains an exact match of the given JSON data

$response->assertExactJson(['id' => 30, 'name' => 'dummy']);

assertViewIs

Assert that the given view was returned by the route

$response->assertViewIs('expected_view.html.twig);