Skip to content

Commit 008105d

Browse files
committed
[fix] logging errors even though response was ok
1 parent 07c80d8 commit 008105d

2 files changed

Lines changed: 70 additions & 2 deletions

File tree

src/Paystack/Http/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public function wrapUp()
3636
return $this->parsePaystackResponse();
3737
}
3838
if (!$this->okay && $this->forApi) {
39-
throw new Exception($this->implodedMessages());
39+
throw new \Exception($this->implodedMessages());
4040
}
4141
if ($this->okay) {
42-
error_log($this->implodedMessages());
4342
return $this->body;
4443
}
44+
error_log($this->implodedMessages());
4545
return false;
4646
}
4747
}

tests/Http/ResponseTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Yabacon\Paystack\Tests\Http;
33

44
use Yabacon\Paystack\Http\Response;
5+
use Yabacon\Paystack\Exception\ApiException;
56

67
class ResponseTest extends \PHPUnit_Framework_TestCase
78
{
@@ -10,4 +11,71 @@ public function testInitialize()
1011
$r = new Response();
1112
$this->assertNotNull($r);
1213
}
14+
15+
public function testWrapUpForApiOkay()
16+
{
17+
$r = new Response();
18+
$r->okay = true;
19+
$r->forApi = true;
20+
$r->body = '{"status":"1","data":{"status":"okay"}}';
21+
22+
$resp = $r->wrapUp();
23+
$this->assertEquals('okay', $resp->data->status);
24+
}
25+
26+
public function testWrapUpForApiOkayStatusFalse()
27+
{
28+
$r = new Response();
29+
$r->okay = true;
30+
$r->forApi = true;
31+
$r->body = '{"status":"0","message":"I failed on Api","data":{"status":"okay"}}';
32+
33+
$this->expectException(ApiException::class);
34+
$resp = $r->wrapUp();
35+
$this->assertEquals('I failed on Api', $resp->message);
36+
}
37+
38+
public function testWrapUpForApiOkayBadJSON()
39+
{
40+
$r = new Response();
41+
$r->okay = true;
42+
$r->forApi = true;
43+
$r->body = 'API didn\'t give JSON';
44+
45+
$this->expectException(ApiException::class);
46+
$resp = $r->wrapUp();
47+
}
48+
49+
public function testWrapUpForApiNotOkay()
50+
{
51+
$r = new Response();
52+
$r->okay = false;
53+
$r->forApi = true;
54+
$r->body = 'I failed before hitting API';
55+
56+
$this->expectException(\Exception::class);
57+
$resp = $r->wrapUp();
58+
}
59+
60+
public function testWrapUpNotForApiOkay()
61+
{
62+
$r = new Response();
63+
$r->okay = true;
64+
$r->forApi = false;
65+
$r->body = 'I was not sent to API';
66+
67+
$resp = $r->wrapUp();
68+
$this->assertEquals('I was not sent to API', $resp);
69+
}
70+
71+
public function testWrapUpNotForApiNotOkay()
72+
{
73+
$r = new Response();
74+
$r->okay = false;
75+
$r->forApi = false;
76+
$r->body = 'I was not sent to API but I still failed';
77+
78+
$resp = $r->wrapUp();
79+
$this->assertFalse($resp);
80+
}
1381
}

0 commit comments

Comments
 (0)