Skip to content

Commit b3c7229

Browse files
committed
Added basic unit test
1 parent 0b47395 commit b3c7229

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
"psr-4": {
3535
"Tests\\": "tests"
3636
}
37+
},
38+
"scripts": {
39+
"test": "./vendor/bin/phpunit tests"
3740
}
3841
}

phpunit.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<phpunit colors="true"
3+
bootstrap="./vendor/autoload.php">
4+
<php>
5+
<ini name="display_errors" value="stderr"/>
6+
<ini name="error_log" value="/dev/null"/>
7+
</php>
8+
<testsuite name="Unit tests">
9+
<directory>.tests/</directory>
10+
</testsuite>
11+
<filter>
12+
<whitelist processUncoveredFilesFromWhitelist="true">
13+
<directory suffix=".php">src/</directory>
14+
</whitelist>
15+
</filter>
16+
</phpunit>

tests/ApiClientTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Tests\SendCloud;
4+
5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\ClientInterface;
7+
use GuzzleHttp\Psr7\Response;
8+
use PHPUnit\Framework\TestCase;
9+
use Imbue\SendCloud\SendCloudApiClient;
10+
11+
class ApiClientTest extends TestCase
12+
{
13+
/** @var ClientInterface */
14+
private $guzzleClient;
15+
/** @var SendCloudApiClient */
16+
private $sendCloudApiClient;
17+
18+
protected function setUp()
19+
{
20+
parent::setUp();
21+
$this->guzzleClient = $this->createMock(Client::class);
22+
$this->sendCloudApiClient = new SendCloudApiClient($this->guzzleClient);
23+
$this->sendCloudApiClient->setApiAuth('test_api_key', 'test_api_secret');
24+
}
25+
26+
public function testPerformHttpCallReturnsBodyAsObject()
27+
{
28+
$response = new Response(200, [], '{"object": "parcel"}');
29+
30+
$this->guzzleClient
31+
->expects($this->once())
32+
->method('send')
33+
->willReturn($response);
34+
35+
$parsedResponse = $this->sendCloudApiClient->performHttpCall('GET', '');
36+
37+
$this->assertEquals(
38+
(object)['object' => 'parcel'],
39+
$parsedResponse
40+
);
41+
}
42+
}

0 commit comments

Comments
 (0)