Skip to content

Commit

Permalink
update php SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Olman62 committed Apr 9, 2021
1 parent 5b8ef04 commit a4d1cfa
Show file tree
Hide file tree
Showing 68 changed files with 4,137 additions and 362 deletions.
2 changes: 1 addition & 1 deletion UnitTestFiles/Test/AddressBookGroupUnitTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function testSearchAddressBookGroups()
$this->assertNotNull($addressBookGroups->results);

if (sizeof($addressBookGroups->results)>0) {
$this->assertContains('Louisville',implode (", ", $addressBookGroups->results[0]));
$this->assertContains('Louisville', implode (", ", $addressBookGroups->results[0]));
}
}

Expand Down
16 changes: 10 additions & 6 deletions UnitTestFiles/Test/AddressBookLocationUnitTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace UnitTestFiles\Test;

use Route4Me\SearchResponse as SearchResponse;
use Route4Me\Route4Me as Route4Me;
use Route4Me\AddressBookLocation as AddressBookLocation;
use Route4Me\Constants as Constants;
use Route4Me\SearchResponse;
use Route4Me\Route4Me;
use Route4Me\AddressBookLocation;
use Route4Me\Constants;

class AddressBookLocationUnitTests extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -200,8 +200,12 @@ public function testSearchAddressBookLocations()
$this->assertContains('address_email',$result->fields);

$this->assertNotNull($result->results);
$firstRecord = json_encode($result->results[0]);
$this->assertTrue(strpos($firstRecord, 'Douglas')>-1);

$txt = json_encode($result->results[0]);

$firstRecord = strtolower($txt);

$this->assertTrue(strpos($firstRecord, 'douglas')>=0);
}

public function testGetAddressBookLocations()
Expand Down
5 changes: 2 additions & 3 deletions UnitTestFiles/Test/AddressUnitTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace UnitTestFiles\Test;

use phpDocumentor\Reflection\Types\Boolean;
use Route4Me\Address;
use Route4Me\Constants;
use Route4Me\Enum\DeviceType;
Expand Down Expand Up @@ -247,7 +246,7 @@ public function testMarkAsDeparted()
$result = $address->markAsDeparted($params);

$this->assertNotNull($result);
$this->assertTrue(is_bool($result['status']));
$this->assertIsBool($result['status']);
$this->assertTrue($result['status']);
}

Expand All @@ -264,7 +263,7 @@ public function testMarkAsVisited()
$result = $address->markAsVisited($params);

$this->assertNotNull($result);
$this->assertTrue(is_int($result));
$this->assertIsInt($result);
$this->assertEquals(1,$result);
}

Expand Down
19 changes: 12 additions & 7 deletions UnitTestFiles/Test/OptimizationProblemUntTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,15 @@ public function testReoptimize()
{
$optimizationProblemId = self::$createdProblems[0]->getOptimizationId();

$problem = OptimizationProblem::fromArray(
OptimizationProblem::reoptimize(['optimization_problem_id' => $optimizationProblemId])
);
$optimizationProblem = new OptimizationProblem();

$problem = $optimizationProblem->reoptimize(['optimization_problem_id' => $optimizationProblemId]);

$this->assertNotNull($problem);
$this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$problem]);

$this->assertInstanceOf(
OptimizationProblem::class,
OptimizationProblem::fromArray($problem));
}

public function testUpdate()
Expand All @@ -258,8 +261,8 @@ public function testUpdate()
OptimizationProblem::update($OptimizationParameters)
);

$this->assertNotNull($problem);
$this->assertContainsOnlyInstancesOf(OptimizationProblem::class, [$problem]);
$this->assertNotNull($result);
$this->assertTrue($result instanceof OptimizationProblem);
$this->assertTrue(sizeof($result->addresses)==$initialAddresses+2);
}

Expand Down Expand Up @@ -429,7 +432,9 @@ public static function tearDownAfterClass()
'redirect' => 0,
];

$result = OptimizationProblem::removeOptimization($params);
$optProblem = new OptimizationProblem();

$result = $optProblem->removeOptimization($params);

if ($result!=null && $result['status']==true) {
echo "The test optimization was removed <br>";
Expand Down
3 changes: 3 additions & 0 deletions UnitTestFiles/Test/RouteExampleTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public static function setUpBeforeClass()

public function testOptimizationWithBundledAddresses()
{
$this->markTestSkipped('The test requires special permission to use the address bundling feature.');

// Huge list of addresses
$json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);

Expand Down Expand Up @@ -454,6 +456,7 @@ public function testMultipleDepotMultipleDriverWith24StopsTimeWindow()
$this->assertInstanceOf('Route4Me\OptimizationProblem', $problem);
$this->assertNotNull($problem->getOptimizationId());
$this->assertNotNull($problem->getRoutes());
$this->assertTrue(sizeof($problem->getRoutes())>1);
}

public function testMultipleSeparateDepostMultipleDriver()
Expand Down
60 changes: 55 additions & 5 deletions UnitTestFiles/Test/RouteTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Route4Me\RouteParameters;
use Route4Me\RouteParametersQuery;
use Route4Me\Vehicles\Vehicle;
use Route4Me\Vehicles\VehicleV4;

class RouteTests extends \PHPUnit\Framework\TestCase
{
Expand All @@ -27,6 +28,7 @@ class RouteTests extends \PHPUnit\Framework\TestCase

public static $removedOptimizationIDs = [];
public static $removedRouteIDs = [];
public static $removedVehicleIDs = [];

public static function setUpBeforeClass()
{
Expand Down Expand Up @@ -240,7 +242,41 @@ public function testAssignVehicleToRoute()

$response = $vehicle->getVehicles($vehicleParameters);

$randomIndex = rand(0, 9);
$this->assertNotNull($response);
$this->assertTrue(isset($response['data']));

if (sizeof($response['data'])<1) {
$vehicle = new VehicleV4();

$vehicleParameters = Vehicle::fromArray([
'vehicle_name' => 'Ford Transit Test 5',
'vehicle_alias' => 'Ford Transit Test 5',
'vehicle_vin' => 'JS3TD62V1Y4107898',
'vehicle_reg_country_id' => '223',
'vehicle_make' => 'Ford',
'vehicle_model_year' => 2013,
'vehicle_axle_count' => 2,
'mpg_city' => 8,
'mpg_highway' => 14,
'fuel_type' => 'unleaded 93',
'height_inches' => 72,
'weight_lb' => 2000,
]);

$result = $vehicle->createVehicle($vehicleParameters);

self::assertNotNull($result);
self::assertInstanceOf(
VehicleV4::class,
VehicleV4::fromArray($result)
);

$response['data'][] = $result;

$removedVehicleIDs[] = $result['vehicle_id'];
}

$randomIndex = rand(0, sizeof($response['data'])-1);
$vehicleId = $response['data'][$randomIndex]['vehicle_id'];

//endregion
Expand Down Expand Up @@ -550,11 +586,13 @@ public function testRouteOriginParameter()

//region -- Re-sequence the route --

$params = [
'route_id' => $routeID,
];
$params = new RouteParametersQuery();
$params->route_id = $routeID;

$status = $route->resequenceAllAddresses($params);
$result = $route->reoptimizeRoute($params);

$this->assertNotNull($result);
$this->assertInstanceOf(Route::class, Route::fromArray($result));

$params = new RouteParametersQuery();

Expand Down Expand Up @@ -766,6 +804,18 @@ public static function tearDownAfterClass()
echo "Cannot remove the test routes <br>";
}
}

if (sizeof(self::$removedVehicleIDs)>0) {
$vehicle = new VehicleV4();

foreach (self::$removedVehicleIDs as $vehicleID) {
$vehicleParameters = VehicleV4::fromArray([
'vehicle_id' => $vehicleID,
]);

$result = $vehicle->removeVehicle($vehicleParameters);
}
}
}

}
Loading

0 comments on commit a4d1cfa

Please sign in to comment.