Skip to content

Commit b75c045

Browse files
committed
fix: tests relating to errors
1 parent e14b9f6 commit b75c045

16 files changed

+39
-35
lines changed

lib/EasyPost/Constant/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ abstract class Constants
3333
const NO_ID_URL_ERROR = "Could not determine which URL to request: %s instance has invalid ID: %s";
3434
const NO_RATES_ERROR = 'No rates found.';
3535
const NO_RESPONSE_ERROR = 'Did not receive a response from %s.';
36-
const SEND_STIPE_DETAILS_ERROR = 'Could not send card details to Stripe, please try again later.';
36+
const SEND_STRIPE_DETAILS_ERROR = 'Could not send card details to Stripe, please try again later.';
3737
const UNDEFINED_PROPERTY_ERROR = "EasyPost Notice: Undefined property of %s instance: %s";
3838
}

lib/EasyPost/Exception/Api/ApiException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getHttpBody()
8383
*/
8484
public function prettyPrint()
8585
{
86-
print($this->ecode . ' (' . $this->getHttpStatus() . '): ' .
86+
print($this->code . ' (' . $this->getHttpStatus() . '): ' .
8787
$this->getMessage() . "\n");
8888
if (!empty($this->errors)) {
8989
print("Field errors:\n");

lib/EasyPost/Service/CarrierAccountService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function create($params = null)
7878
throw new MissingParameterException(sprintf(Constants::MISSING_PARAMETER_ERROR, 'type'));
7979
}
8080

81-
$url = self::selectCarrierAccountCreationEndpoint(!isset($params['carrier_account']['type']));
81+
$url = self::selectCarrierAccountCreationEndpoint($params['carrier_account']['type']);
8282
$response = Requestor::request($this->client, 'post', $url, $params);
8383

8484
return InternalUtil::convertToEasyPostObject($this->client, $response);

lib/EasyPost/Service/ReferralCustomerService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function addCreditCard($referralApiKey, $number, $expirationMonth, $expir
8484
try {
8585
$stripeToken = self::createStripeToken($number, $expirationMonth, $expirationYear, $cvc, $easypostStripeApiKey);
8686
} catch (\Exception $error) {
87-
throw new ExternalApiException(Constants::SEND_STIPE_DETAILS_ERROR);
87+
throw new ExternalApiException(Constants::SEND_STRIPE_DETAILS_ERROR);
8888
}
8989

9090
$stripeToken = $stripeToken['id'] ?? '';

test/EasyPost/AddressTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace EasyPost\Test;
44

55
use EasyPost\EasyPostClient;
6-
use EasyPost\Exception\EasyPostException;
6+
use EasyPost\Exception\Api\ApiException;
77

88
class AddressTest extends \PHPUnit\Framework\TestCase
99
{
@@ -174,7 +174,7 @@ public function testVerifyInvalid()
174174
try {
175175
$address = self::$client->address->create(['street1' => 'invalid']);
176176
self::$client->address->verify($address->id);
177-
} catch (EasyPostException $error) {
177+
} catch (ApiException $error) {
178178
$this->assertEquals('Unable to verify address.', $error->getMessage());
179179
}
180180
}

test/EasyPost/BatchTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace EasyPost\Test;
44

55
use EasyPost\EasyPostClient;
6-
use EasyPost\Shipment;
76

87
class BatchTest extends \PHPUnit\Framework\TestCase
98
{

test/EasyPost/CarrierAccountTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace EasyPost\Test;
44

55
use EasyPost\EasyPostClient;
6-
use EasyPost\Exception\EasyPostException;
7-
use EasyPost\Exception\MissingParameterError;
6+
use EasyPost\Exception\Api\ApiException;
7+
use EasyPost\Exception\General\MissingParameterException;
88

99
class CarrierAccountTest extends \PHPUnit\Framework\TestCase
1010
{
@@ -56,8 +56,11 @@ public function testCreateWithoutType()
5656
unset($params['type']);
5757

5858
try {
59-
self::$client->carrierAccount->create($params);
60-
} catch (MissingParameterError $error) {
59+
$carrierAccount = self::$client->carrierAccount->create($params);
60+
61+
// Delete the carrier account once it's done being tested (should not be reached).
62+
self::$client->carrierAccount->delete($carrierAccount->id);
63+
} catch (MissingParameterException $error) {
6164
$this->assertEquals('type is required.', $error->getMessage());
6265
}
6366
}
@@ -83,7 +86,7 @@ public function testCreateWithCustomWorkflow()
8386
$carrierAccount = self::$client->carrierAccount->create($data);
8487
// Delete the carrier account once it's done being tested (should not be reached).
8588
self::$client->carrierAccount->delete($carrierAccount->id);
86-
} catch (EasyPostException $error) {
89+
} catch (ApiException $error) {
8790
$this->assertEquals(422, $error->getHttpStatus());
8891
$errorFound = false;
8992
$errors = $error->errors;
@@ -93,8 +96,9 @@ public function testCreateWithCustomWorkflow()
9396
break;
9497
}
9598
}
96-
$this->assertTrue($errorFound);
9799
}
100+
101+
$this->assertTrue($errorFound);
98102
}
99103

100104
/**

test/EasyPost/EasyPostClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace EasyPost\Test;
44

55
use EasyPost\EasyPostClient;
6-
use EasyPost\Exception\MissingParameterError;
6+
use EasyPost\Exception\General\MissingParameterException;
77

88
class EasyPostClientTest extends \PHPUnit\Framework\TestCase
99
{
@@ -57,7 +57,7 @@ public function testNoApiKey()
5757
{
5858
try {
5959
new EasyPostClient(null);
60-
} catch (MissingParameterError $error) {
60+
} catch (MissingParameterException $error) {
6161
$this->assertEquals('No API key provided. See https://www.easypost.com/docs for details, or contact support@easypost.com for assistance.', $error->getMessage());
6262
}
6363
}

test/EasyPost/ErrorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace EasyPost\Test;
44

55
use EasyPost\EasyPostClient;
6-
use EasyPost\Exception\EasyPostException;
6+
use EasyPost\Exception\Api\ApiException;
77

88
class ErrorTest extends \PHPUnit\Framework\TestCase
99
{
@@ -36,7 +36,7 @@ public function testError()
3636
// Create a bad shipment so we can work with errors
3737
try {
3838
self::$client->shipment->create();
39-
} catch (EasyPostException $error) {
39+
} catch (ApiException $error) {
4040
$this->assertEquals(422, $error->getHttpStatus());
4141
$this->assertEquals('PARAMETER.REQUIRED', $error->code);
4242
$this->assertEquals('Missing required parameter.', $error->getMessage());

test/EasyPost/EventTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace EasyPost\Test;
44

55
use EasyPost\EasyPostClient;
6-
use EasyPost\Exception\EasyPostException;
6+
use EasyPost\Exception\General\EasyPostException;
77
use EasyPost\Util\Util;
88

99
class EventTest extends \PHPUnit\Framework\TestCase

0 commit comments

Comments
 (0)