Testing Symfony reusable packages with PHPUnit Bridge

I recently came across PHPUnit Bridge and used it in any of my standalone Symfony applications. However, I noticed some deprecation notifications that you can use to reuse package bindings that we support.

To diagnose, I opened the reusable package project and installed symfony/phpunit-bridge , but after running phpunit noticed that there were no failure notifications, etc. that are displayed for the project.

So how do you use the symfony/phpunit-bridge package with reusable packages?

+6
source share
1 answer

I noticed some deprecation notices that you can use to support the multiple packet bindings that we support.

To diagnose, I opened a reusable package project and installed symfony/phpunit-bridge , but after running phpunit noticed that there were no failure notifications for the project, etc.

The fact that the same code does not always cause the same warnings may indicate that the tests are different.

If this comes from PHP code, you can see the checked and unverified code using PHP_CodeCoverage . When you use PHPUnit, you can add an option to generate a code coverage report, for example. phpunit … --coverage-html cov/ will generate an HTML report in the cov/ directory. By comparing the outputs, you can see if the tests from Symfony run the same code as the tests running from the Bundle.

If the tests are different, you can configure the Symfony environment for your package :

Create TestKernel

 <?php // Tests/Controller/App/AppKernel.php use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // Dependencies new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), [...] // My Bundle to test new Beberlei\WorkflowBundle\BeberleiWorkflowBundle(), ); return $bundles; } public function registerContainerConfiguration(LoaderInterface $loader) { // We don't need that Environment stuff, just one config $loader->load(__DIR__.'/config.yml'); } } 

Creating config.yml

 # Tests/Controller/App/config.yml framework: secret: secret charset: UTF-8 test: ~ router: { resource: "%kernel.root_dir%/routing.yml" } form: true csrf_protection: true validation: { enable_annotations: true } templating: { engines: ['twig'] } session: auto_start: false storage_id: session.storage.filesystem monolog: handlers: main: type: fingers_crossed action_level: error handler: nested nested: type: stream path: %kernel.logs_dir%/%kernel.environment%.log level: debug 

Creating routing.yml

 # Tests/Controller/App/routing.yml BeberleiWorkflowBundle: resource: "@BeberleiWorkflowBundle/Controller/" type: annotation prefix: / 

Modifying phpunit.xml.dist

 <!-- phpunit.xml.dist --> <phpunit bootstrap="Tests/bootstrap.php"> <php> <server name="KERNEL_DIR" value="Tests/Controller/App" /> </php> </phpunit> 

Then you can add "symfony/symfony": "~2.3" to the required packages in composer.json and install the packages. Future tests will download this AppKernel and run tests in the full Symfony environment.

+1
source

All Articles