Download the PHP package visithor/visithor-bundle without Composer
On this page you can find all versions of the php package visithor/visithor-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package visithor-bundle
Visithor Bundle for Symfony
Symfony Bundle for PHP Package visithor, a library that provides you a simple and painless way of testing your application routes with specific HTTP Codes.
Please read Visithor documentation in order to understand the final purpose of this project and how you should create your config files.
Installation
All you need to do is add this package in your composer under require-dev
block and you will be able to test your application.
Then you have to update your dependencies.
Integration
This Bundle integrates the project in your Symfony project. This means that adds
all the commands in your project console, so when you do app/console
you will
see the visithor:*
commands.
Config
This Bundle provides you some extra features when defining your urls. Now you can define your routes using the route name and an array of parameters.
Environment
Maybe you need to prepare your environment before Visithor tests your routes, right? Prepare your database, load your fixtures, and whatever you need to make your test installation works.
By default, VisithorBundle has a simple implementation already working. This implementation takes care about building the database and creating your schema.
It takes care as well of the destruction of your testing database once your test is finished.
If you want to extend this behavior, for example for some fixtures load, then you need to do your own implementation, or extend this one.
To implement your own, you should define a service called
visitor.environment_builder
than implements the interface
Visithor\Bundle\Environment\Interfaces\EnvironmentBuilderInterface
.
If you take a look at this interface, you will se that you need to define two methods. The first one is intended to setUp your environment and will be called just once at the beginning of the suite. The second one will tear down such environment (for example removing database).
This is the way you can overwrite completely the default implementation, but if you just want to extend it, then is much simpler. Take a look at this example.
To call some commands you can use the protected method called executeCommand
,
but remember to call the parent method in order to initialize the application
and call the already existing code.
Roles
You will, for sure, have the need to test your private routes. Of course, this is a common need and this bundle satisfies it :)
Let's check our simple security file.
Then, let's see our Visithor configuration.
In this case, all routes are under the default firewall, called default
.
Route admin_route
is protected by the access role ROLE_ADMIN
, and because we
are testing against this role, then we'll receive a 200.
Route superadmin_route
is protected by the access role ROLE_SUPERADMIN
, but
in this case we are testing again using role ROLE_ADMIN
, so we'll receive a
403 code.
Of course, you can define your firewall as a global option. Your routes will apply security only if both role and firewall options are defined.
Because you need to authenticate a real user in order to make it work, in your own EnvironmentBuilder implementation you will be able to return this user. Make sure that your testing environment is prepared to be tested.
Let's see a real example about an implementation of this method.
As you can see, the parameter received is the role you are intended to test, so you can switch between users depending on that value.
All versions of visithor-bundle with dependencies
symfony/config Version ^2.7|^3.0
symfony/dependency-injection Version ^2.7|^3.0
symfony/console Version ^2.7|^3.0
symfony/routing Version ^2.7|^3.0
symfony/http-foundation Version ^2.7|^3.0
symfony/security Version ^2.7|^3.0
symfony/framework-bundle Version ^2.7|^3.0
visithor/visithor Version ^0.2.0