From 9936ccfa5ed852a8f597378e1ac8949e427b9302 Mon Sep 17 00:00:00 2001 From: Matthew Wire <mjw@mjwconsult.co.uk> Date: Tue, 25 Jan 2022 22:13:44 +0000 Subject: [PATCH] Test fixes --- tests/phpunit/CRM/Stripe/BaseTest.php | 34 ++++++++++++++------------- tests/phpunit/CRM/Stripe/IpnTest.php | 5 ++-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/phpunit/CRM/Stripe/BaseTest.php b/tests/phpunit/CRM/Stripe/BaseTest.php index 32b7b22f..1f25b7cb 100644 --- a/tests/phpunit/CRM/Stripe/BaseTest.php +++ b/tests/phpunit/CRM/Stripe/BaseTest.php @@ -54,17 +54,26 @@ abstract class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implement ]; public function setUpHeadless() { - } - - public function setUp(): void { - parent::setUp(); - // we only need to do the shared library once + // Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile(). + // See: https://github.com/civicrm/org.civicrm.testapalooza/blob/master/civi-test.md + static $reInstallOnce = TRUE; + + $reInstall = FALSE; + if (!isset($reInstallOnce)) { + $reInstallOnce=TRUE; + $reInstall = TRUE; + } if (!is_dir(__DIR__ . '/../../../../../mjwshared')) { civicrm_api3('Extension', 'download', ['key' => 'mjwshared']); } - else { - civicrm_api3('Extension', 'install', ['keys' => 'mjwshared']); - } + + return \Civi\Test::headless() + ->installMe(__DIR__) + ->install('mjwshared') + ->apply($reInstall); + } + + public function setUp(): void { civicrm_api3('Extension', 'install', ['keys' => 'com.drastikbydesign.stripe']); require_once('vendor/stripe/stripe-php/init.php'); $this->createPaymentProcessor(); @@ -72,13 +81,6 @@ abstract class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implement $this->created_ts = time(); } - public function tearDown(): void { - civicrm_api3('PaymentProcessor', 'delete', ['id' => $this->paymentProcessorID]); - civicrm_api3('Extension', 'disable', ['keys' => 'com.drastikbydesign.stripe']); - civicrm_api3('Extension', 'uninstall', ['keys' => 'com.drastikbydesign.stripe']); - parent::tearDown(); - } - /** * */ @@ -515,7 +517,7 @@ class PropertySpy implements ArrayAccess, Iterator, Countable, JsonSerializable /** * Stubs a method by returning a value from a map. */ -class ValueMapOrDie implements \PHPUnit\Framework\MockObject\Stub { +class ValueMapOrDie implements \PHPUnit\Framework\MockObject\Stub\Stub { use \PHPUnit\Framework\MockObject\Api; diff --git a/tests/phpunit/CRM/Stripe/IpnTest.php b/tests/phpunit/CRM/Stripe/IpnTest.php index e824283e..130cddc2 100644 --- a/tests/phpunit/CRM/Stripe/IpnTest.php +++ b/tests/phpunit/CRM/Stripe/IpnTest.php @@ -50,7 +50,6 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest { * update it after creation. @todo The membership should also be updated. */ public function testNewRecurringInvoicePaymentSucceeded() { - $this->mockRecurringPaymentSetup(); $this->simulateEvent([ 'type' => 'invoice.payment_succeeded', @@ -940,7 +939,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest { ]); // - // Check the CotnributionRecur + // Check the ContributionRecur // // The subscription ID should be in both processor_id and trxn_id fields // We expect it to be pending @@ -954,7 +953,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest { /** * */ - protected function returnValueMapOrDie($map) :ValueMapOrDie { + protected function returnValueMapOrDie($map): ValueMapOrDie { return new ValueMapOrDie($map); } -- GitLab