forked from yabacon/paystack-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestBuilderTest.php
More file actions
65 lines (54 loc) · 2.25 KB
/
RequestBuilderTest.php
File metadata and controls
65 lines (54 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Yabacon\Paystack\Tests\Http;
use Yabacon\Paystack\Http\RequestBuilder;
use Yabacon\Paystack;
use Yabacon\Paystack\Contracts\RouteInterface;
use Yabacon\Paystack\Routes\Customer;
use Yabacon\Paystack\Routes\Transaction;
class RequestBuilderTest extends \PHPUnit\Framework\TestCase
{
public function testMoveArgsToSentargs()
{
$p = new Paystack('sk_');
$interface = ['args'=>['id']];
$payload = ['id'=>1,'reference'=>'something'];
$sentargs = [];
$rb = new RequestBuilder($p, $interface, $payload, $sentargs);
$rb->moveArgsToSentargs();
$this->assertEquals(1, $rb->sentargs['id']);
$this->assertEquals(1, count($rb->payload));
}
public function testPutArgsIntoEndpoint()
{
$p = new Paystack('sk_');
$rb = new RequestBuilder($p, null, [], ['reference'=>'some']);
$endpoint = 'verify/{reference}';
$rb->putArgsIntoEndpoint($endpoint);
$this->assertEquals('verify/some', $endpoint);
}
public function testBuild()
{
$p = new Paystack('sk_');
$params = ['email'=>'some@ema.il'];
$rb = new RequestBuilder($p, Customer::create(), $params);
$r = $rb->build();
$this->assertEquals('https://api.paystack.co/customer', $r->endpoint);
$this->assertEquals('Bearer sk_', $r->headers['Authorization']);
$this->assertEquals('post', $r->method);
$this->assertEquals(json_encode($params), $r->body);
$params = ['perPage'=>10];
$rb = new RequestBuilder($p, Customer::getList(), $params);
$r = $rb->build();
$this->assertEquals('https://api.paystack.co/customer?perPage=10', $r->endpoint);
$this->assertEquals('Bearer sk_', $r->headers['Authorization']);
$this->assertEquals('get', $r->method);
$this->assertEmpty($r->body);
$args = ['reference'=>'some-reference'];
$rb = new RequestBuilder($p, Transaction::verify(), [], $args);
$r = $rb->build();
$this->assertEquals('https://api.paystack.co/transaction/verify/some-reference', $r->endpoint);
$this->assertEquals('Bearer sk_', $r->headers['Authorization']);
$this->assertEquals('get', $r->method);
$this->assertEmpty($r->body);
}
}