PHPackages                             visithor/visithor-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. visithor/visithor-bundle

ActiveSymfony-bundle[Framework](/categories/framework)

visithor/visithor-bundle
========================

Visithor Bundle for Symfony

v0.2.1(9y ago)1620.2k3MITPHPPHP ^5.4|^7.0

Since May 3Pushed 9y ago3 watchersCompare

[ Source](https://github.com/Visithor/VisithorBundle)[ Packagist](https://packagist.org/packages/visithor/visithor-bundle)[ RSS](/packages/visithor-visithor-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (13)Used By (3)

Visithor Bundle for Symfony
===========================

[](#visithor-bundle-for-symfony)

[![Build Status](https://camo.githubusercontent.com/160191e9967064389a09176ef9806629697ca6c3d7040082d4cb630cb2a8bb9c/68747470733a2f2f7472617669732d63692e6f72672f5669736974686f722f5669736974686f7242756e646c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Visithor/VisithorBundle)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/386e5a176f1dd363c73b61ac37ce4b4e3a13c1e081da6818dcf41a9b6d49268c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5669736974686f722f5669736974686f7242756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Visithor/VisithorBundle/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/eabecea7d22026c58bdc065482b235ddf3bea15c36f59080eb0c3ee5d54bdd4f/68747470733a2f2f706f7365722e707567782e6f72672f7669736974686f722f7669736974686f722d62756e646c652f762f737461626c652e706e67)](https://packagist.org/packages/visithor/visithor-bundle)[![Latest Unstable Version](https://camo.githubusercontent.com/b9a739427020fd2ea75cab2da347d5939378bfc67e1b36437cbe41e7d8c4587e/68747470733a2f2f706f7365722e707567782e6f72672f7669736974686f722f7669736974686f722d62756e646c652f762f756e737461626c652e706e67)](https://packagist.org/packages/visithor/visithor-bundle)

Symfony Bundle for PHP Package [visithor](http://github.com/visithor/visithor), a library that provides you a simple and painless way of testing your application routes with specific HTTP Codes.

Please read [Visithor](http://github.com/visithor/visithor) documentation in order to understand the final purpose of this project and how you should create your config files.

Installation
------------

[](#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.

```
'require-dev':
    ...

    'visithor/visithor-bundle': '~0.1'
```

Then you have to update your dependencies.

```
php composer.phar update
```

Integration
-----------

[](#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.

```
php app/console visithor:go --env=test
```

Config
------

[](#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.

```
defaults:
    #
    # This value can be a simple HTTP Code or an array of acceptable HTTP Codes
    # - 200
    # - [200, 301]
    #
    http_codes: [200, 302]

urls:
    #
    # By default, is there is no specified HTTP Code, then default one is used
    # as the valid one
    #
    - http://google.es
    - http://elcodi.io

    #
    # There are some other formats available as well
    #
    - [http://shopery.com, 200]
    - [http://shopery.com, [200, 302]]

    #
    # This Bundle adds some extra formats
    #
    - [store_homepage, 200]
    - [[store_category_products_list, {'slug': 'women-shirts', 'id': 1}], 200]
    - [[store_category_products_list, {'slug': 'another-name', 'id': 1}], 302]
    - [[store_homepage, {_locale: es}]]
```

Environment
-----------

[](#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.

```
php app/console doctrine:database:create
php app/console doctrine:schema:update
```

It takes care as well of the destruction of your testing database once your test is finished.

```
php app/console doctrine:database:drop --force
```

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).

```
use Symfony\Component\HttpKernel\KernelInterface;
use Visithor\Bundle\Environment\Interfaces\EnvironmentBuilderInterface;

/**
 * Class EnvironmentBuilder
 */
class EnvironmentBuilder implements EnvironmentBuilderInterface
{
    /**
     * Set up environment
     *
     * @param KernelInterface $kernel Kernel
     *
     * @return $this Self object
     */
    public function setUp(KernelInterface $kernel)
    {
        //
    }

    /**
     * Tear down environment
     *
     * @param KernelInterface $kernel Kernel
     *
     * @return $this Self object
     */
    public function tearDown(KernelInterface $kernel)
    {
        //
    }

    /**
     * Get authenticated user
     *
     * @param string $role Role
     *
     * @return mixed User for authentication
     */
    public function getAuthenticationUser($role)
    {
        //
    }
}
```

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.

```
namespace Elcodi\Common\VisithorBridgeBundle\Visithor;

use Doctrine\DBAL\Connection;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\HttpKernel\KernelInterface;
use Visithor\Bundle\Environment\SymfonyEnvironmentBuilder;

/**
 * Class EnvironmentBuilder
 */
class EnvironmentBuilder extends SymfonyEnvironmentBuilder
{
    /**
     * Set up environment
     *
     * @param KernelInterface $kernel Kernel
     *
     * @return $this Self object
     */
    public function setUp(KernelInterface $kernel)
    {
        parent::setUp($kernel);

        $this
            ->executeCommand('doctrine:fixtures:load', [
                '--fixtures' => $kernel
                        ->getRootDir() . '/../src/Elcodi/Fixtures',
            ])
            ->executeCommand('elcodi:templates:load')
            ->executeCommand('elcodi:templates:enable', [
                'template' => 'StoreTemplateBundle',
            ])
            ->executeCommand('elcodi:plugins:load')
            ->executeCommand('assets:install')
            ->executeCommand('assetic:dump');
    }
}
```

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
-----

[](#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.

```
security:

    providers:
        in_memory:
            memory: ~

    firewalls:
        default:
            provider: in_memory
            http_basic: ~
            anonymous: ~

    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }
        - { path: ^/superadmin, roles: ROLE_SUPERADMIN }
```

Then, let's see our Visithor configuration.

```
urls:
    - ['/', 200]
    - ['/admin', 200, {'role': 'ROLE_ADMIN', 'firewall': 'default'}]
    - ['/superadmin', 403, {'role': 'ROLE_ADMIN', 'firewall': 'default'}]
```

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.

```
defaults:
    options:
        firewall: default
urls:
    - ['/', 200]
    - ['/admin', 200, {'role': 'ROLE_ADMIN'}]
    - ['/superadmin', 403, {'role': 'ROLE_ADMIN'}]
```

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.

```
/**
 * Get authenticated user
 *
 * @param string $role Role
 *
 * @return mixed User for authentication
 */
public function getAuthenticationUser($role)
{
    return 'ROLE_ADMIN' === $role
        ? $this
            ->adminUserRepository
            ->findOneBy([
                'email' => 'admin@admin.com'
            ])
        : null;
}
```

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.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~39 days

Recently: every ~98 days

Total

11

Last Release

3639d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.4

v0.2.0PHP ^5.4|^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e8cb88fa6413489c9cdb77288a06ff94b4553aa497d8fc0ee1891576053f1306?d=identicon)[mmoreram](/maintainers/mmoreram)

---

Top Contributors

[![mmoreram](https://avatars.githubusercontent.com/u/521409?v=4)](https://github.com/mmoreram "mmoreram (19 commits)")[![jverdeyen](https://avatars.githubusercontent.com/u/117409?v=4)](https://github.com/jverdeyen "jverdeyen (1 commits)")

---

Tags

phpsymfonypingvisithor

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/visithor-visithor-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/visithor-visithor-bundle/health.svg)](https://phpackages.com/packages/visithor-visithor-bundle)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[shopware/storefront

Storefront for Shopware

684.2M148](/packages/shopware-storefront)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
