Documentation for integration tests with Slim handlers/controllers
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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