From 0c24489a7817604e4b569bc9cc122ad0ea774132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Nikolaou?= Date: Fri, 31 Aug 2018 21:47:32 +0300 Subject: [PATCH] Add support for Laravel 5.7 --- .travis.yml | 1 + CHANGELOG.md | 4 ++ LICENSE => LICENSE.md | 0 composer.json | 10 +-- phpunit.xml => phpunit.xml.dist | 2 +- src/Card.php | 25 +++++--- src/Client.php | 30 ++++----- src/Order.php | 10 +-- src/Source.php | 8 +-- src/Transaction.php | 24 ++++---- src/VivaPaymentsServiceProvider.php | 3 +- src/WebhookController.php | 7 ++- tests/TestCase.php | 64 +++++++++++++------ tests/unit/CardTest.php | 4 +- tests/unit/ClientTest.php | 6 +- tests/unit/OrderTest.php | 6 +- tests/unit/TransactionTest.php | 95 +++++++++++++++++------------ 17 files changed, 181 insertions(+), 118 deletions(-) rename LICENSE => LICENSE.md (100%) rename phpunit.xml => phpunit.xml.dist (90%) diff --git a/.travis.yml b/.travis.yml index d426ab4..6d73076 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: - 7.0 - 7.1 + - 7.2 env: matrix: diff --git a/CHANGELOG.md b/CHANGELOG.md index 56ae355..c156551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `sebdesign/laravel-viva-payments` will be documented in this file +## 3.1.0 - 2018-07-31 + +- Add support for Laravel 5.7 + ## 3.0.1 - 2018-06-01 - Use TLSv1 cipher list if cURL doesn't use NSS diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/composer.json b/composer.json index 4818571..0dd59ef 100644 --- a/composer.json +++ b/composer.json @@ -25,13 +25,13 @@ "require": { "php": ">=7.0", "guzzlehttp/guzzle": "~6.0", - "illuminate/config": "~5.5", - "illuminate/routing": "~5.5", - "illuminate/support": "~5.5" + "illuminate/config": "5.5.*|5.6.*|5.7.*", + "illuminate/routing": "5.5.*|5.6.*|5.7.*", + "illuminate/support": "5.5.*|5.6.*|5.7.*" }, "require-dev": { - "orchestra/testbench": "~3.5", - "phpunit/phpunit": "^6.2" + "orchestra/testbench": "3.5.*|3.6.*|3.7.*", + "phpunit/phpunit": "6.*|7.*" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 90% rename from phpunit.xml rename to phpunit.xml.dist index bb49c9b..c17b9ed 100644 --- a/phpunit.xml +++ b/phpunit.xml.dist @@ -22,7 +22,7 @@ - + diff --git a/src/Card.php b/src/Card.php index accb59f..64eb3a6 100644 --- a/src/Card.php +++ b/src/Card.php @@ -27,14 +27,19 @@ public function __construct(Client $client) * Get a token for the credit card. * * @param string $name The cardholder's name - * @param mixed $number The credit card number + * @param string $number The credit card number * @param int $cvc The CVC number * @param int $month The expiration month * @param int $year The expiration year * @return string */ - public function token($name, $number, $cvc, $month, $year) - { + public function token( + string $name, + string $number, + int $cvc, + int $month, + int $year + ) : string { $token = $this->client->post(self::ENDPOINT, [ \GuzzleHttp\RequestOptions::FORM_PARAMS => [ 'CardHolderName' => $name, @@ -53,10 +58,10 @@ public function token($name, $number, $cvc, $month, $year) /** * Strip non-numeric characters. * - * @param mixed $number The credit card number - * @return int + * @param string $number The credit card number + * @return string */ - protected function normalizeNumber($number) + protected function normalizeNumber(string $number) : string { return preg_replace('/\D/', '', $number); } @@ -66,7 +71,7 @@ protected function normalizeNumber($number) * * @return string */ - protected function getKey() + protected function getKey() : string { return config('services.viva.public_key'); } @@ -78,7 +83,7 @@ protected function getKey() * @param int $year * @return string */ - protected function getExpirationDate($month, $year) + protected function getExpirationDate(int $month, int $year) : string { return Carbon::createFromDate($year, $month, 15)->toDateString(); } @@ -86,10 +91,10 @@ protected function getExpirationDate($month, $year) /** * Check for installments support. * - * @param mixed $number The credit card number + * @param string $number The credit card number * @return int */ - public function installments($number) + public function installments(string $number) { $response = $this->client->get(self::ENDPOINT.'/installments', [ \GuzzleHttp\RequestOptions::HEADERS => [ diff --git a/src/Client.php b/src/Client.php index 8033a87..c8a2b70 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,8 +2,9 @@ namespace Sebdesign\VivaPayments; -use GuzzleHttp\ClientInterface; -use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Client as GuzzleClient; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\UriInterface; class Client { @@ -18,16 +19,17 @@ class Client const PRODUCTION_URL = 'https://www.vivapayments.com'; /** - * @var \GuzzleHttp\ClientInterface + * @var \GuzzleHttp\Client */ protected $client; /** * Constructor. * - * @param \GuzzleHttp\ClientInterface $client + * @param \GuzzleHttp\Client $client + * @return void */ - public function __construct(ClientInterface $client) + public function __construct(GuzzleClient $client) { $this->client = $client; } @@ -39,7 +41,7 @@ public function __construct(ClientInterface $client) * @param array $options * @return object */ - public function get($url, array $options = []) + public function get(string $url, array $options = []) { $response = $this->client->get($url, $options); @@ -53,7 +55,7 @@ public function get($url, array $options = []) * @param array $options * @return object */ - public function post($url, array $options = []) + public function post(string $url, array $options = []) { $response = $this->client->post($url, $options); @@ -67,7 +69,7 @@ public function post($url, array $options = []) * @param array $options * @return object */ - public function patch($url, array $options = []) + public function patch(string $url, array $options = []) { $response = $this->client->patch($url, $options); @@ -81,7 +83,7 @@ public function patch($url, array $options = []) * @param array $options * @return object */ - public function delete($url, array $options = []) + public function delete(string $url, array $options = []) { $response = $this->client->delete($url, $options); @@ -91,12 +93,12 @@ public function delete($url, array $options = []) /** * Get the response body. * - * @param \GuzzleHttp\Psr7\Response $response - * @return mixed + * @param \Psr\Http\Message\ResponseInterface $response + * @return object * * @throws \Sebdesign\VivaPayments\VivaException */ - protected function getBody(Response $response) + protected function getBody(ResponseInterface $response) { $body = json_decode($response->getBody(), false, 512, JSON_BIGINT_AS_STRING); @@ -110,9 +112,9 @@ protected function getBody(Response $response) /** * Get the URL. * - * @return \GuzzleHttp\Psr7\Uri + * @return \Psr\Http\Message\UriInterface */ - public function getUrl() + public function getUrl() : UriInterface { return $this->client->getConfig('base_uri'); } diff --git a/src/Order.php b/src/Order.php index a602208..fb6bd04 100644 --- a/src/Order.php +++ b/src/Order.php @@ -35,7 +35,7 @@ public function __construct(Client $client) * @param array $parameters optional parameters (Full list available here: https://github.com/VivaPayments/API/wiki/Optional-Parameters) * @return int */ - public function create($amount, array $parameters = []) + public function create(int $amount, array $parameters = []) { $response = $this->client->post(self::ENDPOINT, [ \GuzzleHttp\RequestOptions::FORM_PARAMS => array_merge(['Amount' => $amount], $parameters), @@ -60,7 +60,7 @@ public function get($orderCode) * * @param int $orderCode The unique Payment Order ID. * @param array $parameters - * @return null + * @return object */ public function update($orderCode, array $parameters) { @@ -83,13 +83,15 @@ public function cancel($orderCode) /** * Get the checkout URL for an order. * - * @param int $orderCode The unique Payment Order ID. + * @param $orderCode The unique Payment Order ID. * @return \GuzzleHttp\Psr7\Uri */ public function getCheckoutUrl($orderCode) { return Uri::withQueryValue( - $this->client->getUrl()->withPath('web/checkout'), 'ref', $orderCode + $this->client->getUrl()->withPath('web/checkout'), + 'ref', + $orderCode ); } } diff --git a/src/Source.php b/src/Source.php index 81c2313..2c321e9 100644 --- a/src/Source.php +++ b/src/Source.php @@ -32,9 +32,9 @@ public function __construct(Client $client) * @param string $url The primary domain of your site WITH protocol scheme (http/https) * @param string $fail The relative path url your client will end up to, after a failed transaction * @param string $success The relative path url your client will end up to, after a successful transaction - * @return null + * @return object */ - public function create($name, $code, $url, $fail, $success) + public function create(string $name, string $code, $url, string $fail, string $success) { $uri = new Uri($url); @@ -56,7 +56,7 @@ public function create($name, $code, $url, $fail, $success) * @param \Psr\Http\Message\UriInterface $uri * @return string */ - protected function getDomain(UriInterface $uri) + protected function getDomain(UriInterface $uri) : string { return $uri->getHost(); } @@ -67,7 +67,7 @@ protected function getDomain(UriInterface $uri) * @param \Psr\Http\Message\UriInterface $uri * @return bool */ - protected function isSecure(UriInterface $uri) + protected function isSecure(UriInterface $uri) : bool { return strtolower($uri->getScheme()) === 'https'; } diff --git a/src/Transaction.php b/src/Transaction.php index 5340ea7..d3e6ad1 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -128,7 +128,7 @@ public function create(array $parameters) * @param array $parameters * @return object */ - public function createRecurring($id, $amount, array $parameters = []) + public function createRecurring(string $id, int $amount, array $parameters = []) { return $this->client->post(self::ENDPOINT.$id, [ \GuzzleHttp\RequestOptions::FORM_PARAMS => array_merge(['Amount' => $amount], $parameters), @@ -136,12 +136,12 @@ public function createRecurring($id, $amount, array $parameters = []) } /** - * Get the transactions for an order code, a transaction id, or a date. + * Get the transactions for an id. * - * @param mixed $id + * @param string $id * @return array */ - public function get($id) + public function get(string $id) : array { $response = $this->client->get(self::ENDPOINT.$id); @@ -154,7 +154,7 @@ public function get($id) * @param int $ordercode * @return array */ - public function getByOrder($ordercode) + public function getByOrder($ordercode) : array { $response = $this->client->get(self::ENDPOINT, [ \GuzzleHttp\RequestOptions::QUERY => compact('ordercode'), @@ -169,7 +169,7 @@ public function getByOrder($ordercode) * @param \DateTimeInterface|string $date * @return array */ - public function getByDate($date) + public function getByDate($date) : array { $date = $this->formatDate($date); @@ -183,10 +183,10 @@ public function getByDate($date) /** * Get the transactions that were cleared on a given date. * - * @param \DateTimeInterface|string $date + * @param \DateTimeInterface|string $clearancedate * @return array */ - public function getByClearanceDate($clearancedate) + public function getByClearanceDate($clearancedate) : array { $clearancedate = $this->formatDate($clearancedate); @@ -203,7 +203,7 @@ public function getByClearanceDate($clearancedate) * @param \DateTimeInterface|string $date * @return string */ - protected function formatDate($date) + protected function formatDate($date) : string { if ($date instanceof \DateTimeInterface) { return $date->format('Y-m-d'); @@ -220,7 +220,7 @@ protected function formatDate($date) * @param string|null $actionUser * @return object */ - public function cancel($id, $amount, $actionUser = null) + public function cancel(string $id, int $amount, $actionUser = null) { $query = ['Amount' => $amount]; $actionUser = $actionUser ? ['ActionUser' => $actionUser] : []; @@ -231,11 +231,11 @@ public function cancel($id, $amount, $actionUser = null) } /** - * Get the public key as query string. + * Get the public key. * * @return string */ - protected function getKey() + protected function getKey() : string { return config('services.viva.public_key'); } diff --git a/src/VivaPaymentsServiceProvider.php b/src/VivaPaymentsServiceProvider.php index 902de9d..9708e61 100644 --- a/src/VivaPaymentsServiceProvider.php +++ b/src/VivaPaymentsServiceProvider.php @@ -22,7 +22,8 @@ class VivaPaymentsServiceProvider extends ServiceProvider public function register() { $this->mergeConfigFrom( - __DIR__.'/../config/services.php', 'services' + __DIR__.'/../config/services.php', + 'services' ); $this->app->singleton(Client::class, function ($app) { diff --git a/src/WebhookController.php b/src/WebhookController.php index 6f24f13..e537140 100644 --- a/src/WebhookController.php +++ b/src/WebhookController.php @@ -53,6 +53,7 @@ protected function handleTransaction(Request $request) * Handle a Create Transaction event notification. * * @param \Illuminate\Http\Request $request + * @return mixed */ abstract protected function handleCreateTransaction(Request $request); @@ -60,6 +61,7 @@ abstract protected function handleCreateTransaction(Request $request); * Handle a Refund Transaction event notification. * * @param \Illuminate\Http\Request $request + * @return mixed */ abstract protected function handleRefundTransaction(Request $request); @@ -67,15 +69,16 @@ abstract protected function handleRefundTransaction(Request $request); * Handle any other type of event notification. * * @param \Illuminate\Http\Request $request + * @return mixed */ abstract protected function handleEventNotification(Request $request); /** * Verify a webhook. * - * @return Illuminate\Http\JsonResponse + * @return array */ - protected function verify() + protected function verify() : array { return (array) $this->webhook->getAuthorizationCode(); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 9b23dfa..03794a9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,15 +7,39 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; use GuzzleHttp\Psr7\Response; +use Psr\Http\Message\RequestInterface; use Sebdesign\VivaPayments\Card; use Sebdesign\VivaPayments\Client; use Sebdesign\VivaPayments\VivaPaymentsServiceProvider; abstract class TestCase extends \Orchestra\Testbench\TestCase { + /** + * Guzzle client + * + * @var \GuzzleHttp\Client + */ protected $client; + + /** + * Handler stack + * + * @var \GuzzleHttp\HandlerStack + */ protected $handler; - protected $requests = []; + + /** + * History of requests + * + * @var array + */ + protected $history = []; + + /** + * Responses + * + * @var array + */ protected $responses = []; protected function getPackageProviders($app) @@ -37,16 +61,22 @@ protected function getEnvironmentSetUp($app) protected function mockRequests() { - $history = Middleware::history($this->requests); + $history = Middleware::history($this->history); $this->handler->push($history); } - protected function getLastRequest() + protected function getLastRequest() : RequestInterface { - return $this->requests[0]['request']; + return $this->history[0]['request']; } + /** + * Mock responses. + * + * @param \GuzzleHttp\Psr7\Response[] $responses + * @return void + */ protected function mockResponses(array $responses) { $mock = new MockHandler($responses); @@ -57,17 +87,13 @@ protected function mockResponses(array $responses) /** * Make a client instance from a Guzzle handler. - * - * @param GuzzleHttp\HandlerStack $handler */ protected function makeClient() { $mockClient = new GuzzleClient([ 'handler' => $this->handler, 'base_uri' => Client::DEMO_URL, - 'curl' => [ - CURLOPT_SSL_CIPHER_LIST => 'TLSv1', - ], + 'curl' => [CURLOPT_SSL_CIPHER_LIST => 'TLSv1'], 'auth' => [ $this->app['config']['merchant_id'], $this->app['config']['api_key'], @@ -86,55 +112,57 @@ protected function mockJsonResponses(array $bodies) $this->mockResponses($responses); } - public function assertPath($path, $request) + public function assertPath(string $path, RequestInterface $request) { $this->assertEquals($path, $request->getUri()->getPath()); return $this; } - public function assertMethod($name, $request) + public function assertMethod(string $name, RequestInterface $request) { $this->assertEquals($name, $request->getMethod(), "The request method should be [{$name}]."); return $this; } - public function assertQuery($name, $value, $request) + public function assertQuery(string $name, $value, RequestInterface $request) { $query = $request->getUri()->getQuery(); parse_str($query, $output); $this->assertArrayHasKey( - $name, $output, + $name, + $output, "Did not see expected query string parameter [{$name}] in [{$query}]." ); $this->assertEquals( - $value, $output[$name], + $value, + $output[$name], "Query string parameter [{$name}] had value [{$output[$name]}], but expected [{$value}]." ); return $this; } - public function assertBody($name, $value, $request) + public function assertBody(string $name, $value, RequestInterface $request) { parse_str($request->getBody(), $body); $this->assertArrayHasKey($name, $body); - $this->assertEquals($value, $body[$name]); + $this->assertSame($value, $body[$name]); return $this; } - public function assertHeader($name, $value, $request) + public function assertHeader(string $name, $value, RequestInterface $request) { $this->assertTrue($request->hasHeader($name), "The header [{$name}] should be passed as a header."); - $this->assertEquals($value, $request->getHeader($name)[0], "The header [{$name}] card number should be [{$value}]."); + $this->assertEquals($value, $request->getHeader($name)[0], "The header [{$name}] should be [{$value}]."); return $this; } diff --git a/tests/unit/CardTest.php b/tests/unit/CardTest.php index 3b62bd1..20fbd29 100644 --- a/tests/unit/CardTest.php +++ b/tests/unit/CardTest.php @@ -26,8 +26,8 @@ public function it_creates_a_token() $this->assertMethod('POST', $request); $this->assertQuery('key', $this->app['config']->get('services.viva.public_key'), $request); $this->assertBody('CardHolderName', 'Customer name', $request); - $this->assertBody('Number', 4111111111111111, $request); - $this->assertBody('CVC', 111, $request); + $this->assertBody('Number', '4111111111111111', $request); + $this->assertBody('CVC', '111', $request); $this->assertBody('ExpirationDate', '2016-06-15', $request); } diff --git a/tests/unit/ClientTest.php b/tests/unit/ClientTest.php index 319a313..6ed33d4 100644 --- a/tests/unit/ClientTest.php +++ b/tests/unit/ClientTest.php @@ -39,7 +39,7 @@ public function it_decodes_a_json_response() $order = new Order($this->client); - $response = $order->get('foo'); + $response = $order->get(42); $this->assertEquals(json_decode($json), $response, 'The JSON response was not decoded.'); } @@ -64,10 +64,10 @@ public function it_throws_an_exception() $order = new Order($this->client); - $order->get('foo'); + $order->get(42); $this->expectException(VivaException::class); - $order->get('bar'); + $order->get(43); } } diff --git a/tests/unit/OrderTest.php b/tests/unit/OrderTest.php index 9c72997..db1fc80 100644 --- a/tests/unit/OrderTest.php +++ b/tests/unit/OrderTest.php @@ -23,9 +23,9 @@ public function it_creates_an_order() $request = $this->getLastRequest(); $this->assertMethod('POST', $request); - $this->assertBody('Amount', 30, $request); + $this->assertBody('Amount', '30', $request); $this->assertBody('CustomerTrns', 'Your reference', $request); - $this->assertEquals(175936509216, $orderCode, 'The order code should be 175936509216'); + $this->assertEquals('175936509216', $orderCode, 'The order code should be 175936509216'); } /** @@ -64,7 +64,7 @@ public function it_updates_an_order() $this->assertMethod('PATCH', $request); $this->assertPath('/api/orders/175936509216', $request); - $this->assertBody('Amount', 50, $request); + $this->assertBody('Amount', '50', $request); } /** diff --git a/tests/unit/TransactionTest.php b/tests/unit/TransactionTest.php index cf84840..f106d64 100644 --- a/tests/unit/TransactionTest.php +++ b/tests/unit/TransactionTest.php @@ -34,9 +34,9 @@ public function it_creates_a_transaction() $this->assertMethod('POST', $request); $this->assertQuery('key', $this->app['config']->get('services.viva.public_key'), $request); - $this->assertBody('OrderCode', 175936509216, $request); + $this->assertBody('OrderCode', '175936509216', $request); $this->assertBody('SourceCode', 'Default', $request); - $this->assertBody('Installments', 36, $request); + $this->assertBody('Installments', '36', $request); $this->assertBody('CreditCard', ['Token' => 'foo'], $request); $this->assertEquals(['foo' => 'bar'], (array) $response); } @@ -60,7 +60,7 @@ public function it_creates_a_recurring_transaction() $this->assertMethod('POST', $request); $this->assertPath('/api/transactions/252b950e-27f2-4300-ada1-4dedd7c17904', $request); - $this->assertBody('Amount', 30, $request); + $this->assertBody('Amount', '30', $request); $this->assertBody('MerchantTrns', 'Your reference', $request); $this->assertEquals(['foo' => 'bar'], (array) $response); } @@ -81,7 +81,7 @@ public function it_cancels_a_transaction() $this->assertMethod('DELETE', $request); $this->assertPath('/api/transactions/252b950e-27f2-4300-ada1-4dedd7c17904', $request); - $this->assertQuery('Amount', 30, $request); + $this->assertQuery('Amount', '30', $request); $this->assertQuery('ActionUser', 'Customer name', $request); $this->assertEquals(['foo' => 'bar'], (array) $response); } @@ -92,7 +92,11 @@ public function it_cancels_a_transaction() */ public function it_gets_transactions_by_id() { - $this->mockJsonResponses([['Transactions' => []]]); + $this->mockJsonResponses([ + ['Transactions' => [ + ['foo' => 'bar'], + ]], + ]); $this->mockRequests(); $transaction = new Transaction($this->client); @@ -102,7 +106,7 @@ public function it_gets_transactions_by_id() $this->assertMethod('GET', $request); $this->assertPath('/api/transactions/252b950e-27f2-4300-ada1-4dedd7c17904', $request); - $this->assertInternalType('array', $transactions); + $this->assertEquals([(object) ['foo' => 'bar']], $transactions); } /** @@ -111,76 +115,89 @@ public function it_gets_transactions_by_id() */ public function it_gets_transactions_by_order_code() { - $this->mockJsonResponses([['Transactions' => []]]); + $this->mockJsonResponses([ + ['Transactions' => [ + ['foo' => 'bar'], + ]], + ]); $this->mockRequests(); $transaction = new Transaction($this->client); $transactions = $transaction->getByOrder(175936509216); + $request = $this->getLastRequest(); $this->assertMethod('GET', $request); - $this->assertQuery('ordercode', 175936509216, $request); - $this->assertInternalType('array', $transactions); + $this->assertQuery('ordercode', '175936509216', $request); + $this->assertEquals([(object) ['foo' => 'bar']], $transactions); } /** * @test * @group unit + * @dataProvider dates */ - public function it_gets_transactions_by_date() + public function it_gets_transactions_by_date($date) { $this->mockJsonResponses([ - ['Transactions' => []], - ['Transactions' => []], - ['Transactions' => []], + ['Transactions' => [ + ['foo' => 'bar'], + ]], ]); $this->mockRequests(); $transaction = new Transaction($this->client); - $responses = [ - $transaction->getByDate('2016-03-12'), - $transaction->getByDate(new DateTime('2016-03-12')), - $transaction->getByDate(new Carbon('2016-03-12')), - ]; + $transactions = $transaction->getByDate($date); - foreach ($this->requests as $key => $transactions) { - $request = $transactions['request']; + $request = $this->getLastRequest(); - $this->assertMethod('GET', $request); - $this->assertQuery('date', '2016-03-12', $request); - $this->assertInternalType('array', $responses[$key]); - } + $this->assertMethod('GET', $request); + $this->assertQuery('date', '2016-03-12', $request); + $this->assertEquals([(object) ['foo' => 'bar']], $transactions); + } + + public function dates() : array + { + return [ + 'string' => ['2016-03-12'], + DateTime::class => [new DateTime('2016-03-12')], + Carbon::class => [new Carbon('2016-03-12')], + ]; } /** * @test * @group unit + * @dataProvider clearanceDates */ - public function it_gets_transactions_by_clearance_date() + public function it_gets_transactions_by_clearance_date($date) { $this->mockJsonResponses([ - ['Transactions' => []], - ['Transactions' => []], - ['Transactions' => []], + ['Transactions' => [ + ['foo' => 'bar'], + ]], ]); $this->mockRequests(); $transaction = new Transaction($this->client); - $responses = [ - $transaction->getByClearanceDate('2016-03-12'), - $transaction->getByClearanceDate(new DateTime('2016-03-12')), - $transaction->getByClearanceDate(new Carbon('2016-03-12')), - ]; + $transactions = $transaction->getByClearanceDate($date); - foreach ($this->requests as $key => $transactions) { - $request = $transactions['request']; + $request = $this->getLastRequest(); - $this->assertMethod('GET', $request); - $this->assertQuery('clearancedate', '2016-03-12', $request); - $this->assertInternalType('array', $responses[$key]); - } + $this->assertMethod('GET', $request); + $this->assertQuery('clearancedate', '2016-03-12', $request); + $this->assertEquals([(object) ['foo' => 'bar']], $transactions); + } + + public function clearanceDates() : array + { + return [ + 'string' => ['2016-03-12'], + DateTime::class => [new DateTime('2016-03-12')], + Carbon::class => [new Carbon('2016-03-12')], + ]; } }