Skip to content
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
],
"scripts": {
"test": "./vendor/bin/phpunit"
"test": "./vendor/bin/phpunit tests"
},
"require": {
"php": ">=7.4",
Expand Down
6 changes: 3 additions & 3 deletions src/Onfleet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Onfleet;

use Onfleet\Resources as Resources;
use Onfleet\resources as Resources;
use Onfleet\errors\ValidationError;
use stdClass;

Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Administrators.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Administrators extends Resources
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Containers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Containers extends Resources
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Destinations.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Destinations extends Resources
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Hubs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Hubs extends Resources
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Organizations.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Organizations extends Resources
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Recipients.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Recipients extends Resources
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Resources.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

use Onfleet\Methods;

Expand Down
2 changes: 1 addition & 1 deletion src/resources/Tasks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Tasks extends Resources
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Teams.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Teams extends Resources
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Webhooks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Webhooks extends Resources
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Workers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Onfleet\Resources;
namespace Onfleet\resources;

class Workers extends Resources
{
Expand Down
52 changes: 25 additions & 27 deletions tests/OnfleetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@

class OnfleetTest extends TestCase
{

const TIMEOUT_DEFAULT = 70000;
/**
* @dataProvider data
*/
public function testAuth($data)
{
$curlClient = $this->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());
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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",
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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" => [
Expand All @@ -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',
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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(
[
Expand Down Expand Up @@ -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(
[
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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" => [
Expand Down