From eb4a0029fe6b3b7d21e7959bd503a5063f3f048f Mon Sep 17 00:00:00 2001 From: Santiago Botero Ruiz Date: Thu, 28 Apr 2022 09:01:01 -0500 Subject: [PATCH] [INT-592] Make the wrapper PSR-4 compliant Now the wrapper complies with PSR-4 standard also, second parameter for Onfleet is optional --- composer.json | 2 +- src/Onfleet.php | 6 ++-- src/resources/Administrators.php | 2 +- src/resources/Containers.php | 2 +- src/resources/Destinations.php | 2 +- src/resources/Hubs.php | 2 +- src/resources/Organizations.php | 2 +- src/resources/Recipients.php | 2 +- src/resources/Resources.php | 2 +- src/resources/Tasks.php | 2 +- src/resources/Teams.php | 2 +- src/resources/Webhooks.php | 2 +- src/resources/Workers.php | 2 +- tests/OnfleetTest.php | 52 +++++++++++++++----------------- 14 files changed, 40 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index d6e2622..ff27d65 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } ], "scripts": { - "test": "./vendor/bin/phpunit" + "test": "./vendor/bin/phpunit tests" }, "require": { "php": ">=7.4", diff --git a/src/Onfleet.php b/src/Onfleet.php index 452bf85..68ece87 100644 --- a/src/Onfleet.php +++ b/src/Onfleet.php @@ -2,7 +2,7 @@ namespace Onfleet; -use Onfleet\Resources as Resources; +use Onfleet\resources as Resources; use Onfleet\errors\ValidationError; use stdClass; @@ -33,7 +33,7 @@ class Onfleet */ public function __construct( $apiKey, - $userTimeout, + $userTimeout = self::DEFAULT_TIMEOUT, $baseURL = null, $defaultPath = self::DEFAULT_PATH, $defaultApiVersion = self::DEFAULT_API_VERSION @@ -47,7 +47,7 @@ public function __construct( throw new ValidationError('Onfleet API key not found, please obtain an API key from your organization admin'); } - if ($userTimeout > 70000) { + if ($userTimeout > self::DEFAULT_TIMEOUT) { throw new ValidationError('User-defined timeout has to be shorter than 70000ms'); } else { $this->_apiKey = $apiKey; diff --git a/src/resources/Administrators.php b/src/resources/Administrators.php index ccb28c2..732863a 100644 --- a/src/resources/Administrators.php +++ b/src/resources/Administrators.php @@ -1,6 +1,6 @@ createMock(CurlClient::class); $curlClient->method('authenticate')->willReturn(true); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; self::assertTrue($onfleet->verifyKey()); } @@ -29,7 +27,7 @@ public function testAdministrators($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["list"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->administrators->get(); self::assertIsArray($response); @@ -47,7 +45,7 @@ public function testTasks($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["get"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->tasks->get('SxD9Ran6pOfnUDgfTecTsgXd'); self::assertIsArray($response); @@ -62,7 +60,7 @@ public function testTaskByShortId($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["get"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->tasks->get('44a56188', 'shortId'); self::assertIsArray($response); @@ -77,7 +75,7 @@ public function testCreateRecipient($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["createRecipient"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->recipients->create([ "name" => "Boris Foster", @@ -99,7 +97,7 @@ public function testRecipientByPhoneNumber($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["getRecipients"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->recipients->get('+18881787788', 'phone'); self::assertIsArray($response); @@ -114,7 +112,7 @@ public function testRecipientByPhoneName($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["getRecipients"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->recipients->get('Onfleet Rocks', 'name'); self::assertIsArray($response); @@ -128,7 +126,7 @@ public function testCreateTeams($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["createTeams"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->teams->create([ "name" => 'Onfleet Team', @@ -152,7 +150,7 @@ public function testWorkerEta($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["getWorkerEta"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->teams->getWorkerEta('SxD9Ran6pOfnUDgfTecTsgXd', [ "dropoffLocation" => '101.627378,3.1403995', @@ -170,7 +168,7 @@ public function testForceComplete($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["forceComplete"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->tasks->forceComplete('6Fe3qqFZ0DDwsM86zBlHJtlJ', [ "completionDetails" => [ @@ -189,7 +187,7 @@ public function testUpdateWorker($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["updateWorkers"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->workers->update('Mdfs*NDZ1*lMU0abFXAT82lM', [ "name" => 'Stephen Curry', @@ -207,7 +205,7 @@ public function testGetWorker($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["getWorker"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->workers->get(); self::assertIsArray($response); @@ -225,7 +223,7 @@ public function testListWorkers($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["listWorkers"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->workers->get(); self::assertIsArray($response); @@ -239,7 +237,7 @@ public function testDeleteTask($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["delete"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->tasks->deleteOne('AqzN6ZAq*qlSDJ0FzmZIMZz~'); self::assertIsNumeric($response); @@ -253,7 +251,7 @@ public function testListWebhooks($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["listWebhooks"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->webhooks->get(); self::assertIsArray($response); @@ -267,7 +265,7 @@ public function testCreateWebhook($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["createWebhook"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->webhooks->create([ "url" => "https://11ec4a02.ngrok.com/onfleet/taskStart", "trigger" => 0 @@ -286,7 +284,7 @@ public function testDeleteWebhook($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["delete"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->webhooks->deleteOne("9zqMxI79mRcHpXE111nILiPn"); self::assertIsNumeric($response); @@ -300,7 +298,7 @@ public function testGetContainer($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["getContainer"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->webhooks->get("2Fwp6wS5wLNjDn36r1LJPscA", "workers"); self::assertIsArray($response); @@ -315,7 +313,7 @@ public function testListHubs($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["listHubs"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->hubs->get(); self::assertIsArray($response); @@ -329,7 +327,7 @@ public function testCreateHubs($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["createHub"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->hubs->create( [ @@ -361,7 +359,7 @@ public function testUpdateHubs($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["updateHub"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->hubs->create( [ @@ -380,7 +378,7 @@ public function testOrganization($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["organization"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->organization->get(); self::assertIsArray($response); @@ -397,7 +395,7 @@ public function testOrganizationDelegatee($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["organizationDelegatee"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->organization->get("cBrUjKvQQgdRp~s1qvQNLpK*"); self::assertIsArray($response); @@ -416,7 +414,7 @@ public function testGetDestination($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["getDestination"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->destinations->get("0i~RR0SUIculbRFsIse6MENg"); self::assertIsArray($response); @@ -431,7 +429,7 @@ public function testCreateDestination($data) { $curlClient = $this->createMock(CurlClient::class); $curlClient->method('execute')->willReturn(["code" => 200, "success" => true, "data" => $data["createDestination"]]); - $onfleet = new Onfleet($data["apiKey"], self::TIMEOUT_DEFAULT, null); + $onfleet = new Onfleet($data["apiKey"]); $onfleet->api->client = $curlClient; $response = $onfleet->destinations->create([ "address" => [