Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Identity request #91

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: php
php:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'

install:
- composer install
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
],
"type": "library",
"require": {
"php": ">=7.3|>=8.0",
"php": ">=8.0",
"ext-json": "*",
"ext-curl": "*",
"nimbly/shuttle": "^0.4"
"nimbly/shuttle": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -20,7 +20,6 @@
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"vimeo/psalm": "^4.0",
"symfony/var-dumper": "^4.2",
"php-coveralls/php-coveralls": "^2.1"
},
Expand Down
3 changes: 2 additions & 1 deletion src/Plaid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace TomorrowIdeas\Plaid;

use Nimbly\Shuttle\Shuttle;
use Psr\Http\Client\ClientInterface;
use ReflectionClass;
use Shuttle\Shuttle;
use TomorrowIdeas\Plaid\Resources\AbstractResource;
use UnexpectedValueException;

Expand All @@ -13,6 +13,7 @@
* @property \TomorrowIdeas\Plaid\Resources\Auth $auth
* @property \TomorrowIdeas\Plaid\Resources\BankTransfers $bank_transfers
* @property \TomorrowIdeas\Plaid\Resources\Categories $categories
* @property \TomorrowIdeas\Plaid\Resources\Identity $identity
* @property \TomorrowIdeas\Plaid\Resources\Institutions $institutions
* @property \TomorrowIdeas\Plaid\Resources\Investments $investments
* @property \TomorrowIdeas\Plaid\Resources\Items $items
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TomorrowIdeas\Plaid\Resources;

use Capsule\Request;
use Nimbly\Capsule\Request;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down
30 changes: 30 additions & 0 deletions src/Resources/Identity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace TomorrowIdeas\Plaid\Resources;

use TomorrowIdeas\Plaid\PlaidRequestException;

class Identity extends AbstractResource
{
/**
* Get Identity request.
*
* @param string $access_token
* @param array<string,mixed> $options
* @throws PlaidRequestException
* @return object
*/
public function get(string $access_token, array $options = []): object
{
$params = [
"access_token" => $access_token,
"options" => (object) $options
];

return $this->sendRequest(
"post",
"identity/get",
$this->paramsWithClientCredentials($params)
);
}
}
78 changes: 34 additions & 44 deletions tests/AbstractResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace TomorrowIdeas\Plaid\Tests;

use Capsule\Request;
use Capsule\Response;
use Capsule\ResponseStatus;
use Shuttle\Handler\MockHandler;
use Shuttle\Shuttle;
use Nimbly\Capsule\Request;
use Nimbly\Capsule\Response;
use Nimbly\Capsule\ResponseStatus;
use Nimbly\Shuttle\Handler\MockHandler;
use Nimbly\Shuttle\Shuttle;
use TomorrowIdeas\Plaid\Plaid;
use TomorrowIdeas\Plaid\PlaidRequestException;
use UnexpectedValueException;
Expand All @@ -16,7 +16,7 @@
* @covers TomorrowIdeas\Plaid\Resources\AbstractResource
* @covers TomorrowIdeas\Plaid\Resources\Items
* @covers TomorrowIdeas\Plaid\PlaidRequestException
* @uses TomorrowIdeas\Plaid\PlaidException
* @uses TomorrowIdeas\Plaid\PlaidException
*/
class AbstractResourceTest extends TestCase
{
Expand All @@ -26,40 +26,37 @@ public function test_build_request_with_no_params_sends_empty_object_in_body():

$reflectionClass = new \ReflectionClass($itemsResource);

$method = $reflectionClass->getMethod("buildRequest");
$method = $reflectionClass->getMethod("buildRequest");
$method->setAccessible(true);

$request = $method->invokeArgs($itemsResource, ["post", "/endpoint"]);

$this->assertEquals(
(object) [],
(object)[],
\json_decode($request->getBody()->getContents())
);
}

public function test_request_exception_passes_through_plaid_display_message(): void
{
$httpClient = new Shuttle([
'handler' => new MockHandler([
function(Request $request) {

$httpClient = new Shuttle(
new MockHandler([
function (Request $request) {
$requestParams = [
"display_message" => "DISPLAY MESSAGE",
];

return new Response(300, \json_encode($requestParams));

}
},
])
]);
);

$plaid = new Plaid("client_id", "secret");
$plaid->setHttpClient($httpClient);

try {
$plaid->items->get("access_token");
}
catch( PlaidRequestException $plaidRequestException ){
} catch (PlaidRequestException $plaidRequestException) {

$this->assertEquals("DISPLAY MESSAGE", $plaidRequestException->getMessage());

Expand All @@ -68,27 +65,24 @@ function(Request $request) {

public function test_request_exception_passes_through_http_status_code(): void
{
$httpClient = new Shuttle([
'handler' => new MockHandler([
function(Request $request) {

$httpClient = new Shuttle(
new MockHandler([
function (Request $request) {
$requestParams = [
"display_message" => "DISPLAY MESSAGE",
];

return new Response(300, \json_encode($requestParams));

}
},
])
]);
);

$plaid = new Plaid("client_id", "secret");
$plaid->setHttpClient($httpClient);

try {
$plaid->items->get("access_token");
}
catch( PlaidRequestException $plaidRequestException ){
} catch (PlaidRequestException $plaidRequestException) {

$this->assertEquals(300, $plaidRequestException->getCode());

Expand All @@ -97,10 +91,9 @@ function(Request $request) {

public function test_1xx_responses_throw_exception(): void
{
$httpClient = new Shuttle([
'handler' => new MockHandler([
function(Request $request) {

$httpClient = new Shuttle(
new MockHandler([
function (Request $request) {
$requestParams = [
"method" => $request->getMethod(),
"version" => $request->getHeaderLine("Plaid-Version"),
Expand All @@ -112,10 +105,9 @@ function(Request $request) {
];

return new Response(100, \json_encode($requestParams));

}
},
])
]);
);

$plaid = new Plaid("client_id", "secret");
$plaid->setHttpClient($httpClient);
Expand All @@ -126,19 +118,17 @@ function(Request $request) {

public function test_3xx_responses_and_above_throw_exception(): void
{
$httpClient = new Shuttle([
'handler' => new MockHandler([
function(Request $request) {

$httpClient = new Shuttle(
new MockHandler([
function (Request $request) {
$requestParams = [
"display_message" => "PLAID_ERROR",
];

return new Response(300, \json_encode($requestParams));

}
},
])
]);
);

$plaid = new Plaid("client_id", "secret");
$plaid->setHttpClient($httpClient);
Expand All @@ -149,11 +139,11 @@ function(Request $request) {

public function test_invalid_json_when_parsing_response(): void
{
$httpClient = new Shuttle([
'handler' => new MockHandler([
new Response(ResponseStatus::OK, "invalid_json")
$httpClient = new Shuttle(
new MockHandler([
new Response(ResponseStatus::OK, "invalid_json"),
])
]);
);

$plaid = new Plaid("client_id", "secret");
$plaid->setHttpClient($httpClient);
Expand Down
2 changes: 1 addition & 1 deletion tests/PlaidClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace TomorrowIdeas\Plaid\Tests;

use ReflectionClass;
use Shuttle\Shuttle;
use Nimbly\Shuttle\Shuttle;
use TomorrowIdeas\Plaid\Plaid;
use UnexpectedValueException;

Expand Down
2 changes: 1 addition & 1 deletion tests/PlaidRequestExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TomorrowIdeas\Plaid\Tests;

use Capsule\Response;
use Nimbly\Capsule\Response;
use TomorrowIdeas\Plaid\PlaidRequestException;

/**
Expand Down
18 changes: 9 additions & 9 deletions tests/ReportsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace TomorrowIdeas\Plaid\Tests;

use Capsule\Response;
use Shuttle\Handler\MockHandler;
use Shuttle\Shuttle;
use Nimbly\Capsule\Response;
use Nimbly\Shuttle\Handler\MockHandler;
use Nimbly\Shuttle\Shuttle;
use TomorrowIdeas\Plaid\Plaid;
use TomorrowIdeas\Plaid\PlaidRequestException;

Expand All @@ -28,7 +28,7 @@ public function test_create_asset_report(): void
$this->assertEquals("secret", $response->params->secret);
$this->assertEquals(["access_token1", "access_token2"], $response->params->access_tokens);
$this->assertEquals(30, $response->params->days_requested);
$this->assertEquals((object) [], $response->params->options);
$this->assertEquals((object)[], $response->params->options);
}

public function test_refresh_asset_report(): void
Expand All @@ -43,7 +43,7 @@ public function test_refresh_asset_report(): void
$this->assertEquals("secret", $response->params->secret);
$this->assertEquals("asset_report_token", $response->params->asset_report_token);
$this->assertEquals(30, $response->params->days_requested);
$this->assertEquals((object) [], $response->params->options);
$this->assertEquals((object)[], $response->params->options);
}

public function test_filter_asset_report(): void
Expand Down Expand Up @@ -90,11 +90,11 @@ public function test_get_asset_report_pdf(): void

public function test_get_asset_report_pdf_throws_on_fail(): void
{
$httpClient = new Shuttle([
'handler' => new MockHandler([
new Response(400, "Bad Request")
$httpClient = new Shuttle(
new MockHandler([
new Response(400, "Bad Request"),
])
]);
);

$plaid = new Plaid("client_id", "secret");
$plaid->setHttpClient($httpClient);
Expand Down
22 changes: 10 additions & 12 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

namespace TomorrowIdeas\Plaid\Tests;

use Capsule\Request;
use Capsule\Response;
use Nimbly\Capsule\Request;
use Nimbly\Capsule\Response;
use Nimbly\Shuttle\Handler\MockHandler;
use Nimbly\Shuttle\Shuttle;
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
use Shuttle\Handler\MockHandler;
use Shuttle\Shuttle;
use TomorrowIdeas\Plaid\Plaid;

abstract class TestCase extends PHPUnitTestCase
{
protected function getPlaidClient(string $environment = "production"): Plaid
{
$httpClient = new Shuttle([
'handler' => new MockHandler([
function(Request $request) {

$httpClient = new Shuttle(
new MockHandler([
function (Request $request) {
$requestParams = [
"method" => $request->getMethod(),
"version" => $request->getHeaderLine("Plaid-Version"),
Expand All @@ -28,10 +27,9 @@ function(Request $request) {
];

return new Response(200, \json_encode($requestParams));

}
])
]);
},
]),
);

$plaid = new Plaid("client_id", "secret", $environment);
$plaid->setHttpClient($httpClient);
Expand Down