You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 useApp::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 extendsTestCase
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.The text was updated successfully, but these errors were encountered: