Hello,
I run a php7 project with phpunit 5, my tests have been passing for many months, but since a few days my tests always fail (they pass on my computer). It seems like circleci does not load automatically phpunit/dbunit anymore :
Failing command: phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml
Exit code: 255
Output:
PHP Fatal error: Class 'PHPUnit_Extensions_Database_TestCase' not found in /home/ubuntu/mywebsite.com/tests/UnitTest.class.inc on line 6
PHP Stack trace:
PHP 1. {main}() /usr/local/bin/phpunit:0
PHP 2. PHPUnit\TextUI\Command::main() /usr/local/bin/phpunit:536
PHP 3. PHPUnit\TextUI\Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:140
PHP 4. PHPUnit\TextUI\Command->handleArguments() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:151
PHP 5. PHPUnit\TextUI\Command->handleBootstrap() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:730
PHP 6. PHPUnit\Util\Fileloader::checkAndLoad() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:908
PHP 7. PHPUnit\Util\Fileloader::load() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:45
PHP 8. include_once() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:61
PHP 9. require_once() /home/ubuntu/mywebsite.com/tests/init.php:130
Fatal error: Class 'PHPUnit_Extensions_Database_TestCase' not found in /home/ubuntu/mywebsite.com/tests/UnitTest.class.inc on line 6
Call Stack:
0.0046 495336 1. {main}() /usr/local/bin/phpunit:0
0.0635 7946816 2. PHPUnit\TextUI\Command::main() /usr/local/bin/phpunit:536
0.0635 7946928 3. PHPUnit\TextUI\Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:140
0.0635 7946928 4. PHPUnit\TextUI\Command->handleArguments() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:151
0.0643 7951800 5. PHPUnit\TextUI\Command->handleBootstrap() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:730
0.0643 7951800 6. PHPUnit\Util\Fileloader::checkAndLoad() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:908
0.0643 7951976 7. PHPUnit\Util\Fileloader::load() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:45
0.0645 7983536 8. include_once('/home/ubuntu/mywebsite.com/tests/init.php') phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:61
0.0656 8102888 9. require_once('/home/ubuntu/mywebsite.com/tests/UnitTest.class.inc') /home/ubuntu/mywebsite.com/tests/init.php:130
phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml returned exit code 255
My circle.yml file :
machine:
php:
version: 7.0.4
hosts:
localhost: 127.0.0.1
test.mywebsite.com: 127.0.0.1
services:
- mysql
checkout:
post:
- cd vendor && git clone https://github.com/runkit7/runkit7.git && cd runkit7 && phpize && ./configure && make && make install && (echo "extension=runkit.so" && echo "runkit.internal_override=1") > /opt/circleci/php/7.0.4/etc/conf.d/runkit.ini
database:
override:
- mysql -u ubuntu -e "CREATE DATABASE mywebsite_test;SET @@global.sql_mode='';"
- mysql -u ubuntu mywebsite_test < tests/fixtures/schema.sql
test:
override:
- ./chenv test
- mkdir etc/cache
- php init.php build
- php init.php build
- mkdir -p $CIRCLE_TEST_REPORTS/phpunit
- phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml
- phpunit --coverage-html $CIRCLE_ARTIFACTS
I have made no modifications on my project neither on circle.yml. Could anyone tell me please how to tell circleci to install phpunit/dbunit before running tests ?
My project uses composer.json for some minor libs, but I would like if possible to avoid loading phpunit and phpunit/dbunit with composer. Currently I use composer like this in my project :
require 'vendor/autoload.php';
I guess I could add phpunit/dbunit to the require-dev in composer.json, but I don’t want to autoload phpunit classes in production, so how can I tell composer which env I’m in (say I have a $env variable) ? One more time if there is another way I would prefer not to use composer for this…
Thank you