Download the PHP package anik/testbench-lumen without Composer
On this page you can find all versions of the php package anik/testbench-lumen. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download anik/testbench-lumen
More information about anik/testbench-lumen
Files in anik/testbench-lumen
Package testbench-lumen
Short Description Testing Helper for Lumen package development
License MIT
Informations about the package testbench-lumen
testbench-lumen
anik/testbench-lumen
is a package, highly inspired by
the orchestral/testbench. orchestral/testbench
that is a tool for testing
Laravel packages. Whereas the anik/testbench-lumen
can only be used with Lumen,
starting from Lumen 6.x
and afterwards.
Installation
Documentation
- The package uses the
phpunit.xml
. Set up your environment variables in thephpunit.xml
file.
NOTE: The package doesn't use the .env
file. You'll have to primarily set all your variables in
your phpunit.xml
file.
- Your testcases should extend the
\Anik\Testbench\TestCase
class. - Your testcases will have access to the Lumen testing APIs.
Bootstrapping
The package internally boots the Lumen application for the test cases. While bootstrapping, you can add some functionalities.
afterApplicationCreated($callback)
registers the callbacks that will be called after the application is created. If you register the callback after the application is created, it'll be fired immediately. The callback will access to theLaravel\Lumen\Application
instance.afterApplicationRefreshed($callback)
registers the callbacks that will be called after the application is refreshed. If you register the callback after the application is refreshed, it'll be fired immediately. The callback will have access to theLaravel\Lumen\Application
instance.beforeApplicationDestroyed($callback)
registers the callback that will be called before the application is getting destroyed. Will have access to theLaravel\Lumen\Application
instance.afterApplicationDestroyed($callback)
registers the callback that will be called after the application has been destroyed. Will have access to theLaravel\Lumen\Application
instance.
The application does not by default loads the facade
and eloquent
. If you need to enable
- Facade, the return
true
from thewithFacade
method. Default:false
. - Eloquent, the return
true
from thewithEloquent
method. Default:false
.
To load your required service providers, you can return an array of providers from the serviceProviders()
method.
Default is []
.
To add your middlewares, you can add both the global and route middlewares.
-
To add global middlewares, you have to return an array of middlewares from the
globalMiddlewares
method. The method has access to theLaravel\Lumen\Application
instance. - To add route middlewares, you have to return an associative array of middlewares from the
routeMiddlewares
. The method has access to theLaravel\Lumen\Application
instance.
By default, the application has the access to the/
endpoint returning the app()->version()
as the response. To
define your routes for the test purpose, you can use the routes
method. The method has access to
the Laravel\Lumen\Routing\Router
instance. Defining routes in this method is as same as writing methods in
the routes/web.php
or routes/api.php
If you don't want to report an Exception, you can use the dontReportExceptions
method. The defined exceptions will
not be reported. Default is []
.
If it's required to work with the $app
instance before the service providers are being registered,
then beforeServiceProviders
is the method to consider. It'll be called for each test methods.
Annotations
There are three types of annotations considered during the test run. All the annotated tasks are executed synchronously.
All the tasks will receive the \Laravel\Lumen\Application\Application
instance in their parameter.
@pre-service-register
- Annotated tasks will run before the service providers are being registered. Maybe useful for modifying values in config before the service provider gets registered.@post-service-register
- Annotated tasks will run after the service providers are being registered.@setup-before
- Annotated tasks will run after the application has boot properly and before running each testcases. If your tests need to perform some sort of actions before running it, i.e. changing environment values, binding something to the container, etc. then you can perform those actions with annotations. Only the method level annotations are executed.
See Annotation Test class to get the hang of it.
Examples
All the scenarios are covered with tests. You can use them as examples.
All versions of testbench-lumen with dependencies
laravel/lumen Version ^6.0|^7.0|^8.0|^9.0|^10.0
phpunit/phpunit Version ^8.0|^9.0|^10.0
mockery/mockery Version ^1.3