Skip to content

Commit

Permalink
Refactor project for compatibility with PHP 8+
Browse files Browse the repository at this point in the history
The changes promoted by this commit maintain compatibility with previous versions as well. A mix of valid return types with the annotation ReturnTypeWillChange was used to guarantee compatibility, e.g. mixed new type.

Ref
recurly#637
  • Loading branch information
Pablo Castro authored and pabloolvcastro committed Jul 4, 2023
1 parent d03abf6 commit 18f85ff
Show file tree
Hide file tree
Showing 35 changed files with 77 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Tests/Recurly/AccountAcquisition_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_AccountAcquisitionTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/accounts/abcdef1234567890/acquisition', 'account_acquisition/show-200.xml'),
array('PUT', '/accounts/abcdef1234567890/acquisition', 'account_acquisition/create-201.xml'),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/AccountBalance_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_AccountBalanceTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/accounts/abcdef1234567890/balance', 'balance/show-200.xml'),
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Account_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Recurly_AccountListTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/accounts', 'accounts/index-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Account_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Recurly_AccountTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/accounts/abcdef1234567890', 'accounts/show-200.xml')
);
Expand Down
6 changes: 3 additions & 3 deletions Tests/Recurly/Addon_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Recurly_AddonTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/plans/gold/add_ons/ipaddresses', 'addons/show-200.xml')
);
Expand Down Expand Up @@ -60,8 +60,8 @@ public function testCreateXmlTieredAddOn() {
$tier1->ending_quantity = 800;
$tier2 = new Recurly_Tier();
$tier2->unit_amount_in_cents->addCurrency('USD', 200);
$addon->tiers = array($tier1, $tier2);

$addon->tiers = array($tier1, $tier2);

$this->assertXmlStringEqualsXmlString("
<add_on>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Adjustment_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Recurly_AdjustmentTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/adjustments/abcdef1234567890', 'adjustments/show-200.xml')
);
Expand Down
10 changes: 5 additions & 5 deletions Tests/Recurly/Base_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@ public function testCheckIfResponseContainGetHeadersFunction() {
$this->client->addResponse('GET', 'accounts', 'accounts/index-200.xml');
$accounts = Recurly_Base::_get('accounts', $this->client);
$this->assertTrue(method_exists($accounts, 'getHeaders'),"Accounts Class does not have method getHeaders");
$this->assertInternalType('array', $accounts->getHeaders());
$this->assertIsArray($accounts->getHeaders());

$this->client->addResponse('GET', 'subscriptions', 'subscriptions/index-200.xml');
$subscriptions = Recurly_Base::_get('subscriptions', $this->client);
$this->assertTrue(method_exists($subscriptions, 'getHeaders'),'Subscriptions Class does not have method getHeaders');
$this->assertInternalType('array', $subscriptions->getHeaders());
$this->assertIsArray($subscriptions->getHeaders());

$this->client->addResponse('GET', 'abcdef1234567890', 'adjustments/show-200.xml');
$adjustment = Recurly_Base::_get('abcdef1234567890', $this->client);
$this->assertTrue(method_exists($adjustment, 'getHeaders'),'Adjustments Class does not have method getHeaders');
$this->assertInternalType('array', $adjustment->getHeaders());
$this->assertIsArray($adjustment->getHeaders());
}

public function testPassingEmptyResourceCode() {
$this->expectException(Recurly_Error::class);
$uri = Recurly_Base::_safeUri(
Recurly_Client::PATH_SUBSCRIPTIONS, "",
Recurly_Client::PATH_SUBSCRIPTIONS, "",
Recurly_Client::PATH_ADDONS, "marketing_emails",
Recurly_Client::PATH_USAGE, 123456
);
);
}

public function testUrlEncodingReplacement() {
Expand Down
6 changes: 3 additions & 3 deletions Tests/Recurly/Billing_Info_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Recurly_BillingInfoTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/accounts/venmo1234567890/billing_info', 'billing_info/show-venmo-200.xml'),
array('GET', '/accounts/abcdef1234567890/billing_info', 'billing_info/show-200.xml'),
Expand Down Expand Up @@ -117,7 +117,7 @@ public function testGetBecsBillingInfo() {
public function testVerifyBillingInfoCreditCard() {
$billing_info = Recurly_BillingInfo::get('abcdef1234567890', $this->client);
$this->client->addResponse('POST', 'https://api.recurly.com/v2/accounts/abcdef1234567890/billing_info/verify', 'billing_info/verify-200.xml');

$verified = $billing_info->verify();
$this->assertEquals($verified->origin, 'api_verify_card');

Expand All @@ -128,7 +128,7 @@ public function testVerifyBillingInfoCreditCard() {
public function testVerifyCvvBillingInfoCreditCard() {
$billing_info = Recurly_BillingInfo::get('abcdef1234567890', $this->client);
$this->client->addResponse('POST', 'https://api.recurly.com/v2/accounts/abcdef1234567890/billing_info/verify_cvv', 'billing_info/verify-cvv-200.xml');

$verified = $billing_info->verifyCvv('988');
$this->assertInstanceOf('Recurly_BillingInfo', $billing_info);
$this->assertEquals($verified->year, 2015);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Coupon_Redemption_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Recurly_CouponRedemptionTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/accounts/abcdef1234567890/redemption', 'accounts/redemption/show-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Coupon_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_CouponTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/coupons/special', 'coupons/show-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/CreditPaymentList_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_CreditPaymentListTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/credit_payments', 'credit_payments/index-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/DunningCampaign_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class RecurlyDunningCampaignListTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/dunning_campaigns', 'dunning_campaigns/index-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/DunningCampaign_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_DunningCampaignTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/dunning_campaigns/1234abcd', 'dunning_campaigns/show-200.xml'),
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Entitlement_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class RecurlyEntitlementListTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/accounts/abcdef1234567890/entitlements', 'accounts/entitlements/index-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/ExportDate_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_ExportDateList_Test extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/export_dates', 'export_dates/index-200.xml'),
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/ExportFile_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_ExportFileList_Test extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/export_dates/2016-08-01/export_files', 'export_files/index-200.xml'),
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/ExportFile_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_ExportFile_Test extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/export_dates/2016-08-01/export_files/revenue_schedules_full.csv', 'export_files/show-200.xml'),
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/GiftCard_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class RecurlyGiftCardListTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/gift_cards', 'gift_cards/index-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/GiftCard_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_GiftCardTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/gift_cards/1988596967980562362', 'gift_cards/show-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/InvoiceTemplate_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class RecurlyInvoiceTemplateListTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/invoice_templates', 'invoice_templates/index-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/InvoiceTemplate_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_InvoiceTemplateTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/invoice_templates/q0tzf7o7fpbl', 'invoice_templates/show-200.xml'),
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Invoice_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Recurly_InvoiceTest extends Recurly_TestCase
{

function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/invoices/1001', 'invoices/show-200.xml'),
array('GET', '/invoices/1002', 'invoices/show-with-prefix-200.xml'),
Expand Down
4 changes: 2 additions & 2 deletions Tests/Recurly/Item_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_ItemTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/items/plastic_gloves', 'items/show-200.xml'),
);
Expand All @@ -17,7 +17,7 @@ public function testConstructor() {

$this->assertSame($client, $prop->getValue($item));
}

public function testGetItem() {
$item = Recurly_Item::get('plastic_gloves', $this->client);

Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Plan_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Recurly_PlanTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/plans/silver', 'plans/show-200.xml'),
array('GET', '/plans/ramp-priced-plan', 'plans/show-ramps-200.xml'),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Purchase_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_PurchaseTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('POST', '/purchases', 'purchases/create-201.xml'),
array('POST', '/purchases/preview', 'purchases/preview-200.xml'),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/ShippingAddress_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Recurly_ShippingAddressTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/accounts/abcdef1234567890', 'accounts/show-200.xml')
);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Transaction_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Recurly_TransactionTest extends Recurly_TestCase
{
function defaultResponses() {
function defaultResponses(): array {
return array(
array('GET', '/transactions/012345678901234567890123456789ab', 'transactions/show-200.xml'),
array('GET', '/invoices/1001', 'invoices/show-200.xml'),
Expand Down
22 changes: 14 additions & 8 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@

/**
* Base class for our tests that sets up a mock client.
*
* @property Recurly_MockClient $client
*/
abstract class Recurly_TestCase extends TestCase {
function setUp() {
protected Recurly_MockClient $client;
function setUp(): void {
$this->client = new Recurly_MockClient();
foreach ($this->defaultResponses() as $request) {
call_user_func_array(array($this->client, 'addResponse'), $request);
Expand All @@ -27,7 +26,8 @@ function setUp() {
/**
* Return an array of responses that will be added to the mock client.
*/
function defaultResponses() {
function defaultResponses(): array
{
return array();
}
}
Expand All @@ -36,18 +36,22 @@ function defaultResponses() {
* Return canned client responses.
*/
class Recurly_MockClient {
private array $_responses;

public function __construct() {
$this->_responses = array();
}

public function addResponse($method, $uri, $fixture_filename) {
public function addResponse($method, $uri, $fixture_filename): void
{
if (!isset($this->_responses[$method])) {
$this->_responses[$method] = array();
}
$this->_responses[$method][$uri] = $fixture_filename;
}

public function request($method, $uri, $data = null) {
public function request($method, $uri, $data = null): Recurly_ClientResponse
{
if (isset($this->_responses[$method][$uri])) {
$fixture_filename = $this->_responses[$method][$uri];
}
Expand All @@ -58,11 +62,13 @@ public function request($method, $uri, $data = null) {
return $this->responseFromFixture($fixture_filename);
}

public function getPdf($uri, $locale = null) {
public function getPdf($uri, $locale = null): array
{
return array($uri, $locale);
}

protected function responseFromFixture($filename) {
protected function responseFromFixture($filename): Recurly_ClientResponse
{
$statusCode = 200;
$headers = array();
$body = null;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": ">=5.7,<8"
"phpunit/phpunit": "9.*"
},
"autoload": {
"classmap": ["lib"]
Expand Down
4 changes: 3 additions & 1 deletion lib/recurly/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public static function disableXmlEntityLoading()
$disable = (bool)$disable;
}

libxml_disable_entity_loader($disable);
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader($disable);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/recurly/coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function createUpdateXML() {
$val = $val->format('c');
}

$root->appendChild($doc->createElement($attr, $val));
$root->appendChild($doc->createElement($attr, $val ?? ''));
}

return XmlTools::renderXML($doc);
Expand Down
Loading

0 comments on commit 18f85ff

Please sign in to comment.