diff --git a/docs/testing.md b/docs/testing.md index 06ab39dac4571ee09ebb9b9b1fa928ce50799988..14f7a85b8eafd769984cfd9d439191ac74f7ff40 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -11,8 +11,8 @@ This extension comes with two PHP Unit tests: Tests can be run most easily via an installation made through CiviCRM Buildkit (https://github.com/civicrm/civicrm-buildkit) by changing into the extension directory and running: - phpunit4 tests/phpunit/CRM/Stripe/IpnTest.php - phpunit4 tests/phpunit/CRM/Stripe/DirectTest.php + phpunit6 tests/phpunit/CRM/Stripe/IpnTest.php + phpunit6 tests/phpunit/CRM/Stripe/DirectTest.php ### Katalon Tests See the test/katalon folder for instructions on running full web-browser based automation tests. diff --git a/tests/phpunit/CRM/Stripe/BaseTest.php b/tests/phpunit/CRM/Stripe/BaseTest.php index b23d69f90bc051c1f2c1900bb08aa8d679312848..3f444739e4158b6bd104fe3f90975152bc778d23 100644 --- a/tests/phpunit/CRM/Stripe/BaseTest.php +++ b/tests/phpunit/CRM/Stripe/BaseTest.php @@ -20,7 +20,7 @@ define('STRIPE_PHPUNIT_TEST', 1); * * @group headless */ -class CRM_Stripe_BaseTest extends \PHPUnit_Framework_TestCase implements HeadlessInterface, HookInterface, TransactionalInterface { +class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface, TransactionalInterface { protected $_contributionID; protected $_invoiceID = 'in_19WvbKAwDouDdbFCkOnSwAN7'; diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index 9de4be632a1dd1cc8939f364f2e8d5ed9599444f..352e007050f2a100faafc6c95b15e38820286699 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -2,8 +2,17 @@ ini_set('memory_limit', '2G'); ini_set('safe_mode', 0); +// phpcs:ignore eval(cv('php:boot --level=classloader', 'phpcode')); +// Allow autoloading of PHPUnit helper classes in this extension. +$loader = new \Composer\Autoload\ClassLoader(); +$loader->add('CRM_', __DIR__); +$loader->add('Civi\\', __DIR__); +$loader->add('api_', __DIR__); +$loader->add('api\\', __DIR__); +$loader->register(); + /** * Call the "cv" command. * @@ -21,6 +30,11 @@ function cv($cmd, $decode = 'json') { $descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => STDERR); $oldOutput = getenv('CV_OUTPUT'); putenv("CV_OUTPUT=json"); + + // Execute `cv` in the original folder. This is a work-around for + // phpunit/codeception, which seem to manipulate PWD. + $cmd = sprintf('cd %s; %s', escapeshellarg(getenv('PWD')), $cmd); + $process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__); putenv("CV_OUTPUT=$oldOutput"); fclose($pipes[0]);