Skip to content

Commit

Permalink
tests; added for PR #62
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Heckmann committed Oct 7, 2013
1 parent ee25c64 commit 3ee5fec
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/recurly/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function assertValidResponse()

private function parseErrorXml($xml) {
$dom = new DOMDocument();
if (!$dom->loadXML($xml)) return null;
if (empty($xml) || !$dom->loadXML($xml)) return null;

$rootNode = $dom->documentElement;
if ($rootNode->nodeName == 'error')
Expand Down
1 change: 1 addition & 0 deletions test/all_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ function __construct()
$this->addFile(__DIR__ . '/recurly/plan_test.php');
$this->addFile(__DIR__ . '/recurly/subscription_test.php');
$this->addFile(__DIR__ . '/recurly/transaction_test.php');
$this->addFile(__DIR__ . '/recurly/base_test.php');
}
}
3 changes: 3 additions & 0 deletions test/fixtures/accounts/empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

4 changes: 4 additions & 0 deletions test/fixtures/transactions/empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8


34 changes: 34 additions & 0 deletions test/recurly/base_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

<?php

class Recurly_BaseTest extends UnitTestCase {
// __parseXmlToNewObject($xml, $client)
// __parseXmlToUpdateObject($xml)

function setUp() {
$this->client = new MockRecurly_Client();
mockRequest($this->client, 'accounts/empty.xml', array('GET', '/accounts/abcdef1234567890'));
}

public function testParsingXMLToNewObject() {
try {
$account = Recurly_Account::get('abcdef1234567890', $this->client);
}
catch (Exception $e) {
$this->fail("Could not parse empty XML string");
}

$this->assertEqual($account, null);
}

public function testParsingXMLToUpdateObject() {
//try {

This comment has been minimized.

Copy link
@drewish

drewish Oct 7, 2013

any reason for leaving this commented out?

This comment has been minimized.

Copy link
@aheckmann

aheckmann Oct 7, 2013

accident. i followed with a commit that cleans it up already.

//$out = Recurly_Resource::__parseXmlToUpdateObject('');
//}
//catch (Exception $e) {
//$this->fail("Could not parse empty XML string");
//}

//$this->assertEqual($out, null);
}
}
11 changes: 11 additions & 0 deletions test/recurly/transaction_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public function testCreateTransactionFailed()
}
}

public function testCreateTransactionWithEmptyXMLResponse()
{
$responseFixture = loadFixture(__DIR__ . '/../fixtures/transactions/empty.xml');

$client = new MockRecurly_Client();
$client->returns('request', $responseFixture);

$transaction = new Recurly_Transaction(null, $client);
$transaction->create();
}

public function testRefundTransactionPartial()
{
mockRequest($this->client,
Expand Down

0 comments on commit 3ee5fec

Please sign in to comment.