Smoke test your Symfony bundle
Clone or download
Nyholm Make aliases public in compiler pass (#20)
* Make aliases public as wll

* Added changelog

* Removed HHVM
Latest commit c0299a5 Mar 26, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Make aliases public in compiler pass (#20) Mar 26, 2018
tests/Functional Apply fixes from StyleCI Dec 21, 2016
.editorconfig Init Dec 21, 2016
.gitattributes Init Dec 21, 2016
.gitignore Init Dec 21, 2016
.php_cs Init Dec 21, 2016
.scrutinizer.yml Init Dec 21, 2016
.styleci.yml Init Dec 21, 2016
.travis.yml Make aliases public in compiler pass (#20) Mar 26, 2018 Make aliases public in compiler pass (#20) Mar 26, 2018
LICENSE Add LICENSE file Nov 30, 2017 Adding a better travis file Feb 2, 2018
composer.json Require symfony/yaml Feb 2, 2018
phpunit.xml.dist Init Dec 21, 2016

Symfony Bundle Test

Latest Version Build Status Code Coverage Quality Score Total Downloads

Test if your bundle is compatible with different Symfony versions

When you want to make sure that your bundle works with different versions of Symfony you need to create a custom AppKernel and load your bundle and configuration.

Using this bundle test together with Matthias Nobacks's SymfonyDependencyInjectionTest will give you a good base for testing a Symfony bundle.


Via Composer

$ composer require --dev nyholm/symfony-bundle-test

Write a test

use Nyholm\BundleTest\BaseBundleTestCase;
use Acme\AcmeFooBundle;
use Acme\Service\Foo;

class BundleInitializationTest extends BaseBundleTestCase
    protected function getBundleClass()
        return AcmeFooBundle::class;

    public function testInitBundle()
        // Boot the kernel.
        // Get the container
        $container = $this->getContainer();

        // Test if you services exists
        $service = $container->get('');
        $this->assertInstanceOf(Foo::class, $service);
    public function testBundleWithDifferentConfiguration()
        // Create a new Kernel
        $kernel = $this->createKernel();
        // Add some configuration
        // Add some other bundles we depend on

        // Boot the kernel as normal ...
        // ... 

Private services in Symfony 4

In Symfony 4 services are private by default. This is a good thing, but in order to test them properly we need to make them public when we are running the tests. This can easily be done with a compiler pass.

class BundleInitializationTest extends BaseBundleTestCase
    protected function setUp()
        // Make all services public
        $this->addCompilerPass(new PublicServicePass());
        // Make services public that have an idea that matches a regex
        $this->addCompilerPass(new PublicServicePass('|my_bundle.*|'));

    // ...

Configure Travis

You want Travis to run against each currently supported LTS version of Symfony (since there would be only one per major version), plus the current if it's not an LTS too. There is no need for testing against version in between because Symfony follows Semantic Versioning.

language: php
sudo: false
        - $HOME/.composer/cache/files
        - $HOME/symfony-bridge/.phpunit

        - PHPUNIT_FLAGS=""
        - SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"

    fast_finish: true
          # Minimum supported dependencies with the latest and oldest PHP version
        - php: 7.2
          env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
        - php: 5.5
          env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"

          # Test the latest stable release
        - php: 5.5
        - php: 5.6
        - php: 7.0
        - php: 7.1
        - php: 7.2
          env: COVERAGE=true PHPUNIT_FLAGS="-v --testsuite main --coverage-text --coverage-clover=build/coverage.xml"

        - php: 7.1
          env: DEPENDENCIES="dunglas/symfony-lock:^2"
        - php: 7.1
          env: DEPENDENCIES="dunglas/symfony-lock:^3"
        - php: 7.1
          env: DEPENDENCIES="dunglas/symfony-lock:^4"

          # Latest commit to master
        - php: 7.2
          env: STABILITY="dev"

          # Dev-master is allowed to fail.
        - env: STABILITY="dev"

    - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
    - if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
    - composer require --no-update symfony/phpunit-bridge:^4.0 ${DEPENDENCIES}

    # To be removed when this issue will be resolved:
    - if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
    - composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
    - ./vendor/bin/simple-phpunit install

    - composer validate --strict --no-check-lock
    - ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS