End-to-end means: start from the real page and test the visible behavior. This is the closest to what a user experiences.
Summary: Test the app like a user sees it.
Here is the user-facing flow, which we want to test:
$home = $client->request('GET', $server['url'] . '/');
$lesson = $client->request('GET', $server['url'] . '/api/lessons/api-testing');Now we can create a test like this:
$lessonData = json_decode($lesson['body'], true);
$this->assertSame(200, $home['status']);
$this->assertStringContains('A4D Learning', $home['body']);
$this->assertSame('Integration Test (API)', $lessonData['title']);Why this test works
- Do not start with this type if you are a beginner. Start with unit tests first.
- This test goes through the public page, so it hides the inside classes from you on purpose.
- That is fine, because the goal here is user behavior, not class details.
- Put this file in tests/http/E2ETest.php because it behaves like a user over HTTP.
- We start from the page, not from one class.
- Then we check page text and one lesson response.
- Simple rule: open page, check output, assert the main path works.
Real-life examples
- Example: on an online shop, open the product page, click Add to cart, then check that the cart page shows the product.
- Example: on a content website, open the home page, click Search, submit a keyword, then check that the results section shows matching articles.
Remember this
- Learn unit test first
- Then come back to e2e
- Put file in tests/http
- Start from /
- Run with php tests/run.php e2e