Skip to content

Commit f9d5c0c

Browse files
committed
added tests for debug requests
1 parent d4f7d46 commit f9d5c0c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

test/unit/SparkPostResponseTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ public function testWithoutHeader()
9999
$this->assertEquals($this->responseMock->withoutHeader($param), $sparkpostResponse->withoutHeader($param));
100100
}
101101

102+
public function testGetRequest()
103+
{
104+
$request = ['some' => 'request'];
105+
$this->responseMock->shouldReceive('getRequest')->andReturn($request);
106+
$sparkpostResponse = new SparkPostResponse($this->responseMock, $request);
107+
$this->assertEquals($sparkpostResponse->getRequest(), $request);
108+
}
109+
102110
public function testWithBody()
103111
{
104112
$param = Mockery::mock('Psr\Http\Message\StreamInterface');

test/unit/SparkPostTest.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ public function testRequest()
6868
$this->assertInstanceOf('SparkPost\SparkPostPromise', $this->resource->request('GET', 'transmissions', $this->getTransmissionPayload));
6969
}
7070

71+
public function testDebugOptionWhenFalse() {
72+
$responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
73+
$this->resource->setOptions(['async' => false, 'debug' => false]);
74+
$this->clientMock->shouldReceive('sendRequest')->andReturn($responseMock);
75+
$response = $this->resource->request('POST', 'transmissions', $this->postTransmissionPayload);
76+
$this->assertEquals($response->getRequest(), null);
77+
}
78+
79+
public function testDebugOptionWhenTrue() {
80+
$responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
81+
$this->resource->setOptions(['async' => false, 'debug' => true]);
82+
$this->clientMock->shouldReceive('sendRequest')->andReturn($responseMock);
83+
$response = $this->resource->request('POST', 'transmissions', $this->postTransmissionPayload);
84+
$this->assertEquals(json_decode($response->getRequest()['body'], true), $this->postTransmissionPayload);
85+
}
86+
7187
public function testSuccessfulSyncRequest()
7288
{
7389
$responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface');
@@ -194,7 +210,9 @@ public function testUnsuccessfulAsyncRequestWithThen()
194210

195211
$guzzlePromise = new GuzzleRejectedPromise($exceptionMock);
196212

197-
$promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, [])));
213+
$request = $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, []);
214+
215+
$promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $request));
198216

199217
$promise->then(null, function ($exception) use ($responseBody) {
200218
$this->assertEquals(500, $exception->getCode());

0 commit comments

Comments
 (0)