Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for integration tests with Slim handlers/controllers #3338

Open
davisenra opened this issue Jul 24, 2024 · 0 comments
Open

Documentation for integration tests with Slim handlers/controllers #3338

davisenra opened this issue Jul 24, 2024 · 0 comments
Labels

Comments

@davisenra
Copy link

davisenra commented Jul 24, 2024

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.

@odan odan added the Slim 5 label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants