Skip to content
Snippets Groups Projects
Commit 59ec9009 authored by mattwire's avatar mattwire
Browse files

Update tests

parent 547ff4dc
Branches
Tags
No related merge requests found
......@@ -378,11 +378,6 @@ class CRM_Stripe_ApiTest extends CRM_Stripe_BaseTest {
->with($this->equalTo($eventData['id']))
->willReturn(new PropertySpy('events.retrieve', $mockEvent));
// Fetch the event
// Previously used the following - but see docblock of getEvent()
// $event = $this->getEvent($eventData['type']);
// $this->assertNotEmpty($event, "Failed to fetch event type $eventData[type]");
// Process it with the IPN/webhook
return $this->ipn($mockEvent, TRUE, $exceptionOnFailure);
}
......
......@@ -21,7 +21,7 @@ define('STRIPE_PHPUNIT_TEST', 1);
*
* @group headless
*/
abstract class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface, TransactionalInterface {
abstract class CRM_Stripe_BaseTest extends CiviUnitTestCase implements HeadlessInterface, HookInterface {
/** @var int */
protected $created_ts;
......@@ -92,6 +92,12 @@ abstract class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implement
$this->created_ts = time();
}
public function tearDown(): void {
$this->quickCleanUpFinancialEntities();
$this->quickCleanup(['civicrm_stripe_customers', 'civicrm_paymentprocessor_webhook']);
parent::tearDown();
}
/**
*
*/
......
......@@ -1174,39 +1174,6 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
]);
}
/**
* Retrieve the event with a matching subscription id
*
* This method is/was intended for use with the live Stripe API, however
* now we're using mocks we don't need it.
*/
public function getEvent($type) {
// If the type has subscription in it, then the id is the subscription id
if (preg_match('/\.subscription\./', $type)) {
$property = 'id';
}
else {
// Otherwise, we'll find the subscription id in the subscription property.
$property = 'subscription';
}
// Gather all events since this class was instantiated.
$params['created'] = ['gte' => $this->created_ts];
//$params['type'] = $type;
$params['ppid'] = $this->paymentProcessorID;
$params['output'] = 'raw';
// Now try to retrieve this transaction.
$transactions = civicrm_api3('Stripe', 'listevents', $params);
foreach($transactions['values']['data'] as $transaction) {
$_ = $transaction->data;
$_ = $_->object;
if ($transaction->data->object->$property == $this->processorID) {
return $transaction;
}
}
return NULL;
}
/**
* Run the webhook/ipn
*
......@@ -1581,11 +1548,6 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
->with($this->equalTo($eventData['id']))
->willReturn(new PropertySpy('events.retrieve', $mockEvent));
// Fetch the event
// Previously used the following - but see docblock of getEvent()
// $event = $this->getEvent($eventData['type']);
// $this->assertNotEmpty($event, "Failed to fetch event type $eventData[type]");
// Process it with the IPN/webhook
return $this->ipn($mockEvent, FALSE, $exceptionOnFailure);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment