Skip to content

Commit 1113831

Browse files
authored
Merge pull request #214 from EasyPost/fix_event_require_test
fix: fixture and require tests
2 parents bc71007 + 48878cb commit 1113831

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

test/EasyPost/Fixture.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,19 @@ public static function basicOrder()
147147

148148
public static function eventJson()
149149
{
150-
return json_encode(self::readFixtureData()['event_body']);
150+
$currentDir = getcwd();
151+
$data = file_get_contents("$currentDir/examples/official/fixtures/event-body.json");
152+
153+
return json_encode(json_decode($data, true));
151154
}
152155

153156
public static function eventBytes()
154157
{
155-
return utf8_encode(json_encode(self::readFixtureData()['event_body']));
158+
$currentDir = getcwd();
159+
$eventBytesFilepath = file("$currentDir/examples/official/fixtures/event-body.json");
160+
$data = $eventBytesFilepath[0];
161+
162+
return utf8_encode(json_encode(json_decode($data, true)));
156163
}
157164

158165
// The credit card details below are for a valid proxy card usable

test/EasyPost/RequireTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
namespace EasyPost\Test;
44

5+
// Manually require the library to ensure there are no import errors (eg: when the autoloader is not used)
56
require 'lib/easypost.php';
67

78
class RequireTest extends \PHPUnit\Framework\TestCase
89
{
910
/**
1011
* Tests that no errors are thrown when we import the library without using the autoloader.
1112
* Things like missing or extra imports should be caught by this. The actual assertion here
12-
* doesn't matter, only that an import/require error isn't thrown.
13+
* doesn't matter, only that an import/require error isn't thrown when the test suite runs.
1314
*/
1415
public function testRequireLibrary()
1516
{
16-
$apiBase = \EasyPost\EasyPost::getApiBase();
17-
$this->assertEquals('https://api.easypost.com/v2', $apiBase);
17+
$this->expectNotToPerformAssertions();
1818
}
1919
}

test/EasyPost/WebhookTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function testValidateWebhookInvalidSecret()
147147
];
148148

149149
try {
150-
$response = Webhook::validateWebhook(Fixture::eventBytes(), $headers, $webhookSecret);
150+
Webhook::validateWebhook(Fixture::eventBytes(), $headers, $webhookSecret);
151151
} catch (Error $error) {
152152
$this->assertEquals('Webhook received did not originate from EasyPost or had a webhook secret mismatch.', $error->getMessage());
153153
}
@@ -164,7 +164,7 @@ public function testValidateWebhookMissingSecret()
164164
];
165165

166166
try {
167-
$response = Webhook::validateWebhook(Fixture::eventBytes(), $headers, $webhookSecret);
167+
Webhook::validateWebhook(Fixture::eventBytes(), $headers, $webhookSecret);
168168
} catch (Error $error) {
169169
$this->assertEquals('Webhook received does not contain an HMAC signature.', $error->getMessage());
170170
}

0 commit comments

Comments
 (0)