slimphp / slimphp/Slim

Documentation for integration tests with Slim handlers/controllers

Open
#3,338 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Slim 5
Dominant language
PHP
Stars
12.3k
Forks
2k
Avg merge
3d 2h
Merged PRs (30d)
6

Description

Hey, I noticed that a new roadmap is being drafted for Slim 5 and I would like to suggest a new section on how to test Slim apps in the official docs.

A pain I had in the past was figuring out how to test my Slim handlers/controllers. The App::run method is responsible for both handling the request and emitting the response. Most users don't really dabble with library code (I didn't back then) and might not realize that Slim handlers are perfectly testable if you instead use App::handle when testing.

Of course, just calling a different method is not everything. You have to make sure your Slim instance definition and configuration are not called in the same place. Sometimes this means a file structure like:

  • bootstrap/app.php (returns a factory function that returns a new App instance when called)
  • public/index.php (where you call the above-mentioned function and then $app->run())

There are also other difficulties involved, such as creating fake ServerRequest objects and dealing with PSR-11 Containers. Usually, this means creating an ApplicationTest class which extends TestCase and defining a couple helper methods in it.

Anyway, I think this would be a really good addition to the docs. I'm willing to contribute, but if this doesn't sound like a good idea or is too much effort, I think a simple link to the slimphp/Slim-Skeleton repository would also be fine. Most users should be able to reverse engineer the tests directory.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Slim-Skeleton tests directory and the proposed bootstrap/app.php and public/index.php structure. Document how to test handlers with App::handle, including fake ServerRequest objects and PSR-11 containers, and make the guidance clear enough for users to reproduce the integration-test setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation, testing
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.