From e59fdbcf6e3493f55c7df9e52a982493c6c9f119 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Tue, 4 Feb 2020 17:16:40 -0500 Subject: [PATCH] initial steps to modernize the testing infrastructure. --- docs/testing.md | 4 ++-- tests/phpunit/CRM/Stripe/BaseTest.php | 2 +- tests/phpunit/bootstrap.php | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/testing.md b/docs/testing.md index 06ab39d..14f7a85 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 b23d69f..3f44473 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 9de4be6..352e007 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]); -- GitLab