2
votes

I have some problems with testing CakePHP2 applications via PHPUnit in a docker container.

The CakePHP2 testing guide states, that the last PHPUnit version that's compatible with CakePHP2 is 3.7.38.

I'm using this version but still I get the following errors:

Warning Error: include(PHPUnit/Autoload.php): failed to open stream: No such file or directory in [/builds/application_folder/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 162]

Warning Error: include(): Failed opening 'PHPUnit/Autoload.php' for inclusion (include_path='/builds/zb2/kswf/lib:.:/usr/local/lib/php') in [/builds/application_folder/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 162]

There was an issue related to this error, but it was solved by downgrading from PHPUnit 4 to PHPUnit 3.

Here is the Dockerfile for the image that I'm using for the GitLab Runner

FROM php:5
RUN apt-get update -y
RUN apt-get install -y wget
RUN sh -c 'wget -c https://phar.phpunit.de/phpunit-3.7.38.phar -O phpunit.phar && chmod +x phpunit.phar && mv phpunit.phar /usr/local/bin/phpunit'

In the before_script section of my .gitlab-ci.yml I print the PHPUnit version to verify that the correct version is installed and it prints 3.7.38.

I'd appreciate any help on this!

1
I have the same problem but no solution at the moment :-( - Ka Rl

1 Answers

1
votes

Well, the thing is that phpunit does not have autoload file for itself, starting from v4 (if I remember that correctly). All files that are packed in phpunit.phar are included via direct in-code require statements (e.g. for 5.3.4 phar such statements occupy lines 23 - 517 of the file if you look inside the file). Idea of this is your tests are launched via phpunit command in CLI, so the phar file makes all preparations and launches PHPUnit_TextUI_Command::main().

If you need to launch tests from php code (looks like that is just the case) you need to take care of all preparations by yourself. If mentioning only class loading you can either implement a mapper and spl_autoload_register it, or create a dump for classes and create some file that will include all files from phpunit (as in phar file). Another option (never tried but I consider it possible, though) might be using Composer for creating dump and autoloader for phpunit, it does have such capabilities.

I have implemented such a launcher for Komodo IDE and I chose the first option (my own dumper, mapper and autoloader) just not to include all the files right away and have being loaded only actually needed ones and also being able to have and run different versions of phpunit.

Well, this not really an answer since you can't just copy-paste and get stuff working, I've tried to put everything as a comment but did not manage to be short enough.