Symfony2: How to handle PHP Unit bootstrap file for uploaded package?

What am I using as the startup file for my PHP module config file for my package?

I'm writing unit tests for my first Symfony 2 package. I'm not sure how to handle the XML configuration file phpunit.xml.dist

for a PHP module. I know I should write my own config file (instead of relying on the one provided by the Symfony Framework), but I've seen several different ways people handle the bootstrap file that uses config.

Symfony Framework apps have a PHP Unit config file in the folder app/

and it uses it bootstrap.php.cache

as an autoloader which really just puts the composer loader in the vendor directory.

Several packages I've looked at have their own bootstrap file, but try to find a different startup file in the filesystem, making assumptions about where it might be. This doesn't seem right to me, but maybe it is?

best practices don't fit here.

+3


source to share


1 answer


Unit testing best practices are testing a small block of functionality at a time, this apparatus should not rely on external influences and does not make sense to use bootstrap.php.cache

as it is designed to load the entire symfony infrastructure.

Your tests inside a package should be done on their own, if someone needs to test your kit and contribute to it, they should be able to run tests there with only your code and dependencies. The ideal scenario would be that no loading is required to set up a test suite, all you need is an autoloader. This is why many packages have a boot script file that the autoloader loads.



There are two scripts in the autoloader location versus the bundle, either your bundle is installed standalone and it will be in vendor/autoload.php

, or your bundle is installed as a dependency, which in standard configuration you would fall back to the project autoloader if one exists.

This is a variable depending on your installation and target directory usage ... you will need to go through at least two levels to account for the vendor name and name, and if you have a target directory configuration you will need to go up the number of directories in your target path ...

0


source







All Articles