3

I'm developing a Zend Framework 2 application with a common folder structure, so that the folder /vendor contains all (project external) libraries. Setting up the unit testing environment I would like to be able to run all vendor tests. The folders structures are different depending on the library. Some packages have no tests at all.

A possible solution would be to create a test suite "vendor" and manually define there the paths to every single test folder, e.g.:

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit ...>
    <testsuites>
        <testsuite name="vendor">
            <directory>../vendor/lib-foo/path/to/tests</directory>
            <directory>../vendor/package-bar/path/to/tests</directory>
            ...
        </testsuite>
        ...
    </testsuites>
    ...
</phpunit>

I don't like this solution. First of all because then I'd have to handle every package manually.

Another solution would be to define /vendor as test folder:

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit ...>
    <testsuites>
        <testsuite name="vendor">
            <directory>../vendor</directory>
            ...
        </testsuite>
        ...
    </testsuites>
    ...
</phpunit>

Well, but then PHPUnit has to scan a lot of folders, that it doesn't need, and the tests will need much more time.

Is there a better solution, that would make possible to automate the process and avoid much manual configuration?

automatix
  • 14,018
  • 26
  • 105
  • 230
  • But why do this in the first place? Do you have a lot of unstable vendor packages (dev branches etc)? Most stable packages are tested by the vendors themselves and only released as a stable ver when all tests are passing. – guessimtoolate May 11 '15 at 15:55
  • Actually you are right -- external packages usually come tested. I only want to ensure this, for example if I update the dependencies (e.g. with `composer update`) and new versions of external libs are installed. Furthermore it might make sense, if not only well known and well tested open source packages like Zend Framework or Symfony, but also external libs with a lower "trust level" / QA level are used, e.g. libs provided by partners, other departments of the organization etc. – automatix May 11 '15 at 19:36

1 Answers1

1

It would probably be difficult to run all PHPUnit vendor test suites with a single test run. One issue is that each of the different test suites might ship its own configuration file or even require a custom bootstrap configuration file. You cannot cover that when running all test suites with a single command.

I'd probably use some shell magic for this. Note that this example relies on the presence of a phpunit.xml(.dist) file in each of your 3rd party packages (for most libraries that's a reasonable assumption). You could even integrate this into your continuous integration process to test this continuously:

for FILE in $(find . -name 'phpunit.xml*') ; do
    sh -c 'cd '$(dirname $FILE)' && composer install'
    vendor/bin/phpunit -c $FILE
done
helmbert
  • 35,797
  • 13
  • 82
  • 95
  • Thank you for your solution! You are right, it would be difficult to find an approach to test all external libs, that have different settings and `Bootstrap` classes, with one PHPUnit test run. Im not sure, whether it's a convenient way for my case, so I won't accept the answer (at least yet). But anyway it's an interesting approach and a possible solution. Thanks for it! +1 – automatix May 13 '15 at 21:53
  • Btw.: Why are you executing `composer install` on every run and for every library? – automatix May 13 '15 at 21:54
  • 2
    @automatix, I tested that on one of my own projects and noticed that many bootstrap files so sth. like `include "../vendor/autoload.php"` or otherwise rely on composer dependencies installed *locally*. Just doing a `composer install` for each library seemed like the easiest way to get around that. – helmbert May 14 '15 at 09:07