I am trying to run a PHPunit test for my extension but I keep getting the following error:
Fatal error: Class 'PHPUnit_Framework_BaseTestListener' not found in C:\xampp\htdocs\myDrupalsite\sites\all\modules\civicrm\Civi\Test\CiviTestListener.php on line 17
Any ideas on how I can fix this?
I am using CiviCRM 4.7
CMS is Drupal 7
My system OS is Windows 10.
My extension is placed in <Drupal root>sites/default/files/civicrm/ext
My test directory was created using civix generate:test
on the Windows command prompt.
I run the tests using PHPUnit via the command prompt in the root directory of my extension.
-
Hi Fanan, welcome to CiviCRM Stack Exchange. It helps if you add more detail to your question. Standard is the used CiviCRM version and the accompanying CMS. For this question, you can add how you run the test and more details about your development environment.– Kainuk - CiviCooPCommented Mar 3, 2018 at 14:54
-
Hi Fanan, impressive that you have it running on Windows.– Kainuk - CiviCooPCommented Mar 7, 2018 at 10:22
Add a comment
|
2 Answers
I run tests the following way
- I test in a CiviCRM instance that is generated with buildkit (the toolchain provided for CiviCRM developers see https://docs.civicrm.org/dev/en/latest/tools/buildkit/ .
- My tests are generated with
civix generate:test
. Remarks that this generator also creates the filetests/phpunit/bootstrap.php
that takes care of the class loading. - I run the test from the extension directory by executing
phpunit4
(This version is installed with buildkit).
-
1This worked fine although when I use
phpunit
instead ofphpunit4
I still get the errorFatal error: Class 'PHPUnit_Framework_BaseTestListener' not found in ...
Commented Mar 6, 2018 at 15:34
This sounds like a mismatch in the phpunit versions:
- Currently, most of the Civi testing runs against the PHAR build of
phpunit
v4. phpunit
v6 renames every class to use\
instead of_
, which means that all the base-classes disappear if you run on a newer build of phpunit.
-
Thanks Tim, this gives a good motivation why phpunit4 is used. Commented Mar 7, 2018 at 10:20