@@ -16,418 +16,418 @@ |
||
| 16 | 16 | |
| 17 | 17 | class AddressNoteUnitTests extends \PHPUnit\Framework\TestCase |
| 18 | 18 | { |
| 19 | - protected $addressNote; |
|
| 20 | - |
|
| 21 | - public static $problem; |
|
| 22 | - |
|
| 23 | - public static $route_id = null; |
|
| 24 | - public static $address_id = null; |
|
| 25 | - public static $address_lat = null; |
|
| 26 | - public static $address_lng = null; |
|
| 27 | - public static $address_is_depot = null; |
|
| 28 | - public static $noteAddressId = null; |
|
| 29 | - public static $noteFileAddressId = null; |
|
| 30 | - |
|
| 31 | - public static $addresIdMarkedAsVisited; |
|
| 32 | - |
|
| 33 | - public static $afterAddressId; |
|
| 34 | - public static $route_id_dest; |
|
| 35 | - |
|
| 36 | - public static $createdCustomNotes; |
|
| 37 | - |
|
| 38 | - public static function setUpBeforeClass() |
|
| 39 | - { |
|
| 40 | - if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 41 | - $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 42 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 46 | - |
|
| 47 | - //<editor-fold desc="Prepare Addresses"> |
|
| 48 | - $addresses = []; |
|
| 49 | - $addresses[] = Address::fromArray([ |
|
| 50 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 51 | - 'is_depot' => true, |
|
| 52 | - 'lat' => 30.159341812134, |
|
| 53 | - 'lng' => -81.538619995117, |
|
| 54 | - 'time' => 300, |
|
| 55 | - 'time_window_start' => 28800, |
|
| 56 | - 'time_window_end' => 32400, |
|
| 57 | - ]); |
|
| 58 | - |
|
| 59 | - $addresses[] = Address::fromArray([ |
|
| 60 | - 'address' => '214 Edgewater Branch Drive 32259', |
|
| 61 | - 'lat' => 30.103567123413, |
|
| 62 | - 'lng' => -81.595352172852, |
|
| 63 | - 'time' => 300, |
|
| 64 | - 'time_window_start' => 36000, |
|
| 65 | - 'time_window_end' => 37200, |
|
| 66 | - ]); |
|
| 67 | - |
|
| 68 | - $addresses[] = Address::fromArray([ |
|
| 69 | - 'address' => '756 eagle point dr 32092', |
|
| 70 | - 'lat' => 30.046422958374, |
|
| 71 | - 'lng' => -81.508758544922, |
|
| 72 | - 'time' => 300, |
|
| 73 | - 'time_window_start' => 39600, |
|
| 74 | - 'time_window_end' => 41400, |
|
| 75 | - ]); |
|
| 76 | - |
|
| 77 | - $addresses[] = Address::fromArray([ |
|
| 78 | - 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', |
|
| 79 | - 'lat' => 30.048496, |
|
| 80 | - 'lng' => -81.558716, |
|
| 81 | - 'time' => 300, |
|
| 82 | - 'time_window_start' => 43200, |
|
| 83 | - 'time_window_end' => 45000, |
|
| 84 | - ]); |
|
| 85 | - |
|
| 86 | - $addresses[] = Address::fromArray([ |
|
| 87 | - 'address' => 'St Johns Florida 32259, USA', |
|
| 88 | - 'lat' => 30.099642, |
|
| 89 | - 'lng' => -81.547201, |
|
| 90 | - 'time' => 300, |
|
| 91 | - 'time_window_start' => 46800, |
|
| 92 | - 'time_window_end' => 48600, |
|
| 93 | - ]); |
|
| 94 | - |
|
| 95 | - $parameters = RouteParameters::fromArray([ |
|
| 96 | - 'device_type' => DeviceType::IPAD, |
|
| 97 | - 'disable_optimization' => false, |
|
| 98 | - 'route_name' => 'phpunit test '.date('Y-m-d H:i'), |
|
| 99 | - ]); |
|
| 100 | - //</editor-fold> |
|
| 101 | - |
|
| 102 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 103 | - $optimizationParameters->setAddresses($addresses); |
|
| 104 | - $optimizationParameters->setParameters($parameters); |
|
| 105 | - |
|
| 106 | - self::$problem = OptimizationProblem::optimize($optimizationParameters); |
|
| 107 | - $routes = self::$problem->getRoutes(); |
|
| 108 | - self::$route_id = $routes[0]->route_id; |
|
| 109 | - self::$noteAddressId = $routes[0]->addresses[2]->route_destination_id; |
|
| 110 | - self::$noteFileAddressId = $routes[0]->addresses[3]->route_destination_id; |
|
| 111 | - |
|
| 112 | - $addresses = self::$problem->addresses; |
|
| 113 | - self::$address_id = $addresses[1]->getAddressId(); |
|
| 114 | - //self::$address_address = $addresses[1]->address; |
|
| 115 | - self::$address_lat = $addresses[1]->lat; |
|
| 116 | - self::$address_lng = $addresses[1]->lng; |
|
| 117 | - self::$address_is_depot = $addresses[1]->is_depot; |
|
| 118 | - |
|
| 119 | - $noteParameters = [ |
|
| 120 | - 'route_id' => self::$route_id, |
|
| 121 | - 'address_id' => self::$address_id, |
|
| 122 | - 'dev_lat' => self::$address_lat, |
|
| 123 | - 'dev_lng' => self::$address_lng, |
|
| 124 | - 'device_type' => 'web', |
|
| 125 | - 'strUpdateType' => 'dropoff', |
|
| 126 | - 'strNoteContents' => 'Test Address Note', |
|
| 127 | - ]; |
|
| 128 | - |
|
| 129 | - $addressNote = new AddressNote(); |
|
| 130 | - |
|
| 131 | - $addresses[1] = $addressNote->AddAddressNote($noteParameters); |
|
| 132 | - |
|
| 133 | - self::$createdCustomNotes = []; |
|
| 134 | - |
|
| 135 | - $customNoteTypes = $addressNote->getAllCustomNoteTypes(); |
|
| 136 | - |
|
| 137 | - foreach ($customNoteTypes as $custNote) { |
|
| 138 | - if ($custNote['note_custom_type'] == 'Unit Test To Do') { |
|
| 139 | - self::$createdCustomNotes[]='Unit Test To Do'; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - if (sizeof(self::$createdCustomNotes)<1) { |
|
| 144 | - $customNoteTypeParameters = [ |
|
| 145 | - 'type' => 'Unit Test To Do', |
|
| 146 | - 'values' => [ |
|
| 147 | - 'Pass a package', |
|
| 148 | - 'Pickup package', |
|
| 149 | - 'Do a service', |
|
| 150 | - ], |
|
| 151 | - ]; |
|
| 152 | - |
|
| 153 | - $customNoteTypeResult = $addressNote->createCustomNoteType($customNoteTypeParameters); |
|
| 154 | - |
|
| 155 | - if ($customNoteTypeResult!=null |
|
| 156 | - && $customNoteTypeResult['result']!=null |
|
| 157 | - && $customNoteTypeResult['result']=='OK' |
|
| 158 | - && $customNoteTypeResult['affected']!=null |
|
| 159 | - && $customNoteTypeResult['affected']==1 |
|
| 160 | - ) { |
|
| 161 | - self::$createdCustomNotes[]='Unit Test To Do'; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - public function testFromArray() |
|
| 167 | - { |
|
| 168 | - $addressNote = AddressNote::fromArray([ |
|
| 169 | - 'note_id' => 539264, |
|
| 170 | - 'route_id' => '5555E83A4BE0055551537955558D5555', |
|
| 171 | - 'route_destination_id' => 162916895, |
|
| 172 | - 'ts_added' => 1466515325, |
|
| 173 | - 'activity_type' => 'dropoff', |
|
| 174 | - 'upload_id' => '1a499993c63d68d1a5d26045a1763d16', |
|
| 175 | - 'upload_extension' => 'csv', |
|
| 176 | - 'upload_url' => 'http:\/\/adb6def9928467589ebb-f540d5a8d53c2e76ad581b6e5c346ad6.\/1a499113c63d68d1a5d26045a1763d16.csv', |
|
| 177 | - 'upload_type' => 'ANY_FILE', |
|
| 178 | - 'contents' => 'Some text', |
|
| 179 | - 'lat' => 33.132675, |
|
| 180 | - 'lng' => -83.244743, |
|
| 181 | - 'device_type' => 'web' |
|
| 182 | - ]); |
|
| 183 | - |
|
| 184 | - $this->assertEquals(539264, $addressNote->note_id); |
|
| 185 | - $this->assertEquals('5555E83A4BE0055551537955558D5555', $addressNote->route_id); |
|
| 186 | - $this->assertEquals(162916895, $addressNote->route_destination_id); |
|
| 187 | - $this->assertEquals(1466515325, $addressNote->ts_added); |
|
| 188 | - $this->assertEquals('dropoff', $addressNote->activity_type); |
|
| 189 | - $this->assertEquals('1a499993c63d68d1a5d26045a1763d16', $addressNote->upload_id); |
|
| 190 | - $this->assertEquals('csv', $addressNote->upload_extension); |
|
| 191 | - $this->assertEquals('http:\/\/adb6def9928467589ebb-f540d5a8d53c2e76ad581b6e5c346ad6.\/1a499113c63d68d1a5d26045a1763d16.csv', $addressNote->upload_url); |
|
| 192 | - $this->assertEquals('ANY_FILE', $addressNote->upload_type); |
|
| 193 | - $this->assertEquals('Some text', $addressNote->contents); |
|
| 194 | - $this->assertEquals(33.132675, $addressNote->lat); |
|
| 195 | - $this->assertEquals(-83.244743, $addressNote->lng); |
|
| 196 | - $this->assertEquals('web', $addressNote->device_type); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - public function testGetAddressesNotes() |
|
| 200 | - { |
|
| 201 | - $noteParameters = [ |
|
| 202 | - 'route_id' => self::$route_id, |
|
| 203 | - 'route_destination_id' => self::$address_id, |
|
| 204 | - ]; |
|
| 205 | - |
|
| 206 | - $addressNote = new AddressNote(); |
|
| 207 | - |
|
| 208 | - $addressWithNotes = Address::fromArray( |
|
| 209 | - $addressNote->GetAddressesNotes($noteParameters) |
|
| 210 | - ); |
|
| 211 | - |
|
| 212 | - $firstNote = AddressNote::fromArray( |
|
| 213 | - $addressWithNotes->notes[0] |
|
| 214 | - ); |
|
| 215 | - |
|
| 216 | - $this->assertNotNull($addressWithNotes); |
|
| 217 | - $this->assertTrue(sizeof( $addressWithNotes->notes)>0); |
|
| 218 | - $this->assertContainsOnlyInstancesOf(AddressNote::class, [$firstNote]); |
|
| 219 | - $this->assertEquals('Test Address Note', $firstNote->contents); |
|
| 220 | - $this->assertEquals('dropoff',$firstNote->activity_type); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - public function testAddAddressNote() |
|
| 224 | - { |
|
| 225 | - $noteParameters = [ |
|
| 226 | - 'strFilename' => 'notes.csv', |
|
| 227 | - 'route_id' => self::$route_id, |
|
| 228 | - 'address_id' => self::$noteAddressId, |
|
| 229 | - 'dev_lat' => 33.132675170898, |
|
| 230 | - 'dev_lng' => -83.244743347168, |
|
| 231 | - 'device_type' => 'web', |
|
| 232 | - 'strUpdateType' => 'dropoff', |
|
| 233 | - 'strNoteContents' => 'Test Add Note To Route Address', |
|
| 234 | - ]; |
|
| 235 | - |
|
| 236 | - $addressNote = new AddressNote(); |
|
| 237 | - |
|
| 238 | - $response = AddressNoteResponse::fromArray( |
|
| 239 | - $addressNote->AddAddressNote($noteParameters) |
|
| 240 | - ); |
|
| 241 | - |
|
| 242 | - $this->assertNotNull($response); |
|
| 243 | - $this->assertContainsOnlyInstancesOf(AddressNoteResponse::class, [$response]); |
|
| 244 | - |
|
| 245 | - $firstNote = AddressNote::fromArray( |
|
| 246 | - $response->note |
|
| 247 | - ); |
|
| 248 | - |
|
| 249 | - $this->assertContainsOnlyInstancesOf(AddressNote::class, [$firstNote]); |
|
| 250 | - $this->assertEquals('Test Add Note To Route Address', $firstNote->contents); |
|
| 251 | - $this->assertNotNull($firstNote->upload_id); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - public function testAddNoteFile() |
|
| 255 | - { |
|
| 256 | - //$this->markTestSkipped('must be revisited.'); |
|
| 257 | - |
|
| 258 | - $noteParameters = [ |
|
| 259 | - 'strFilename' => dirname(__FILE__).'\data\notes.csv', |
|
| 260 | - 'route_id' => self::$route_id, |
|
| 261 | - 'address_id' => self::$noteFileAddressId, |
|
| 262 | - 'dev_lat' => 33.132675170898, |
|
| 263 | - 'dev_lng' => -83.244743347168, |
|
| 264 | - 'device_type' => 'web', |
|
| 265 | - 'strUpdateType' => 'dropoff', |
|
| 266 | - ]; |
|
| 267 | - |
|
| 268 | - $addressNote = new AddressNote(); |
|
| 269 | - |
|
| 270 | - $result = $addressNote->AddNoteFile($noteParameters); |
|
| 271 | - |
|
| 272 | - $response = AddressNoteResponse::fromArray( |
|
| 273 | - $result |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - sleep(5); |
|
| 277 | - |
|
| 278 | - $this->assertNotNull($response); |
|
| 279 | - $this->assertNotNull($response->status); |
|
| 280 | - $this->assertTrue($response->status); |
|
| 281 | - $this->assertContainsOnlyInstancesOf(AddressNoteResponse::class, [$response]); |
|
| 282 | - |
|
| 283 | - $firstNote = AddressNote::fromArray( |
|
| 284 | - $response->note |
|
| 285 | - ); |
|
| 286 | - |
|
| 287 | - $this->assertContainsOnlyInstancesOf(AddressNote::class, [$firstNote]); |
|
| 288 | - $this->assertNotNull($firstNote->upload_id); |
|
| 289 | - $this->assertNotNull($firstNote->upload_url); |
|
| 290 | - $this->assertEquals('csv', $firstNote->upload_extension); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - public function testGetCustomNoteTypeByKey() |
|
| 294 | - { |
|
| 295 | - $addressNote = new AddressNote(); |
|
| 296 | - |
|
| 297 | - $customNoteType = $addressNote->getCustomNoteTypeByKey(self::$createdCustomNotes[0]); |
|
| 298 | - |
|
| 299 | - $this->assertEquals(self::$createdCustomNotes[0],$customNoteType['note_custom_type']); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - public function testGetAllCustomNoteTypes() |
|
| 303 | - { |
|
| 304 | - $addressNote = new AddressNote(); |
|
| 305 | - |
|
| 306 | - $customNoteTypes = $addressNote->getAllCustomNoteTypes(); |
|
| 307 | - |
|
| 308 | - $firstCustomNoteType = CustomNoteTypeResponse::fromArray($customNoteTypes[0]); |
|
| 309 | - |
|
| 310 | - $this->assertNotNull($customNoteTypes); |
|
| 311 | - $this->assertTrue(sizeof($customNoteTypes)>0); |
|
| 312 | - $this->assertContainsOnlyInstancesOf(CustomNoteTypeResponse::class, [$firstCustomNoteType]); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - public function testCreateCustomNoteType() |
|
| 316 | - { |
|
| 317 | - $customNoteTypeKey = 'cnt'.date('yMdHi'); |
|
| 318 | - |
|
| 319 | - $noteParameters = [ |
|
| 320 | - 'type' => $customNoteTypeKey, |
|
| 321 | - 'values' => [ |
|
| 322 | - 'First value', |
|
| 323 | - 'Second value', |
|
| 324 | - 'Third value', |
|
| 325 | - ], |
|
| 326 | - ]; |
|
| 19 | + protected $addressNote; |
|
| 20 | + |
|
| 21 | + public static $problem; |
|
| 22 | + |
|
| 23 | + public static $route_id = null; |
|
| 24 | + public static $address_id = null; |
|
| 25 | + public static $address_lat = null; |
|
| 26 | + public static $address_lng = null; |
|
| 27 | + public static $address_is_depot = null; |
|
| 28 | + public static $noteAddressId = null; |
|
| 29 | + public static $noteFileAddressId = null; |
|
| 30 | + |
|
| 31 | + public static $addresIdMarkedAsVisited; |
|
| 32 | + |
|
| 33 | + public static $afterAddressId; |
|
| 34 | + public static $route_id_dest; |
|
| 35 | + |
|
| 36 | + public static $createdCustomNotes; |
|
| 37 | + |
|
| 38 | + public static function setUpBeforeClass() |
|
| 39 | + { |
|
| 40 | + if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 41 | + $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 42 | + self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 46 | + |
|
| 47 | + //<editor-fold desc="Prepare Addresses"> |
|
| 48 | + $addresses = []; |
|
| 49 | + $addresses[] = Address::fromArray([ |
|
| 50 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 51 | + 'is_depot' => true, |
|
| 52 | + 'lat' => 30.159341812134, |
|
| 53 | + 'lng' => -81.538619995117, |
|
| 54 | + 'time' => 300, |
|
| 55 | + 'time_window_start' => 28800, |
|
| 56 | + 'time_window_end' => 32400, |
|
| 57 | + ]); |
|
| 58 | + |
|
| 59 | + $addresses[] = Address::fromArray([ |
|
| 60 | + 'address' => '214 Edgewater Branch Drive 32259', |
|
| 61 | + 'lat' => 30.103567123413, |
|
| 62 | + 'lng' => -81.595352172852, |
|
| 63 | + 'time' => 300, |
|
| 64 | + 'time_window_start' => 36000, |
|
| 65 | + 'time_window_end' => 37200, |
|
| 66 | + ]); |
|
| 67 | + |
|
| 68 | + $addresses[] = Address::fromArray([ |
|
| 69 | + 'address' => '756 eagle point dr 32092', |
|
| 70 | + 'lat' => 30.046422958374, |
|
| 71 | + 'lng' => -81.508758544922, |
|
| 72 | + 'time' => 300, |
|
| 73 | + 'time_window_start' => 39600, |
|
| 74 | + 'time_window_end' => 41400, |
|
| 75 | + ]); |
|
| 76 | + |
|
| 77 | + $addresses[] = Address::fromArray([ |
|
| 78 | + 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', |
|
| 79 | + 'lat' => 30.048496, |
|
| 80 | + 'lng' => -81.558716, |
|
| 81 | + 'time' => 300, |
|
| 82 | + 'time_window_start' => 43200, |
|
| 83 | + 'time_window_end' => 45000, |
|
| 84 | + ]); |
|
| 85 | + |
|
| 86 | + $addresses[] = Address::fromArray([ |
|
| 87 | + 'address' => 'St Johns Florida 32259, USA', |
|
| 88 | + 'lat' => 30.099642, |
|
| 89 | + 'lng' => -81.547201, |
|
| 90 | + 'time' => 300, |
|
| 91 | + 'time_window_start' => 46800, |
|
| 92 | + 'time_window_end' => 48600, |
|
| 93 | + ]); |
|
| 94 | + |
|
| 95 | + $parameters = RouteParameters::fromArray([ |
|
| 96 | + 'device_type' => DeviceType::IPAD, |
|
| 97 | + 'disable_optimization' => false, |
|
| 98 | + 'route_name' => 'phpunit test '.date('Y-m-d H:i'), |
|
| 99 | + ]); |
|
| 100 | + //</editor-fold> |
|
| 101 | + |
|
| 102 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 103 | + $optimizationParameters->setAddresses($addresses); |
|
| 104 | + $optimizationParameters->setParameters($parameters); |
|
| 105 | + |
|
| 106 | + self::$problem = OptimizationProblem::optimize($optimizationParameters); |
|
| 107 | + $routes = self::$problem->getRoutes(); |
|
| 108 | + self::$route_id = $routes[0]->route_id; |
|
| 109 | + self::$noteAddressId = $routes[0]->addresses[2]->route_destination_id; |
|
| 110 | + self::$noteFileAddressId = $routes[0]->addresses[3]->route_destination_id; |
|
| 111 | + |
|
| 112 | + $addresses = self::$problem->addresses; |
|
| 113 | + self::$address_id = $addresses[1]->getAddressId(); |
|
| 114 | + //self::$address_address = $addresses[1]->address; |
|
| 115 | + self::$address_lat = $addresses[1]->lat; |
|
| 116 | + self::$address_lng = $addresses[1]->lng; |
|
| 117 | + self::$address_is_depot = $addresses[1]->is_depot; |
|
| 118 | + |
|
| 119 | + $noteParameters = [ |
|
| 120 | + 'route_id' => self::$route_id, |
|
| 121 | + 'address_id' => self::$address_id, |
|
| 122 | + 'dev_lat' => self::$address_lat, |
|
| 123 | + 'dev_lng' => self::$address_lng, |
|
| 124 | + 'device_type' => 'web', |
|
| 125 | + 'strUpdateType' => 'dropoff', |
|
| 126 | + 'strNoteContents' => 'Test Address Note', |
|
| 127 | + ]; |
|
| 128 | + |
|
| 129 | + $addressNote = new AddressNote(); |
|
| 130 | + |
|
| 131 | + $addresses[1] = $addressNote->AddAddressNote($noteParameters); |
|
| 132 | + |
|
| 133 | + self::$createdCustomNotes = []; |
|
| 134 | + |
|
| 135 | + $customNoteTypes = $addressNote->getAllCustomNoteTypes(); |
|
| 136 | + |
|
| 137 | + foreach ($customNoteTypes as $custNote) { |
|
| 138 | + if ($custNote['note_custom_type'] == 'Unit Test To Do') { |
|
| 139 | + self::$createdCustomNotes[]='Unit Test To Do'; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + if (sizeof(self::$createdCustomNotes)<1) { |
|
| 144 | + $customNoteTypeParameters = [ |
|
| 145 | + 'type' => 'Unit Test To Do', |
|
| 146 | + 'values' => [ |
|
| 147 | + 'Pass a package', |
|
| 148 | + 'Pickup package', |
|
| 149 | + 'Do a service', |
|
| 150 | + ], |
|
| 151 | + ]; |
|
| 152 | + |
|
| 153 | + $customNoteTypeResult = $addressNote->createCustomNoteType($customNoteTypeParameters); |
|
| 154 | + |
|
| 155 | + if ($customNoteTypeResult!=null |
|
| 156 | + && $customNoteTypeResult['result']!=null |
|
| 157 | + && $customNoteTypeResult['result']=='OK' |
|
| 158 | + && $customNoteTypeResult['affected']!=null |
|
| 159 | + && $customNoteTypeResult['affected']==1 |
|
| 160 | + ) { |
|
| 161 | + self::$createdCustomNotes[]='Unit Test To Do'; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + public function testFromArray() |
|
| 167 | + { |
|
| 168 | + $addressNote = AddressNote::fromArray([ |
|
| 169 | + 'note_id' => 539264, |
|
| 170 | + 'route_id' => '5555E83A4BE0055551537955558D5555', |
|
| 171 | + 'route_destination_id' => 162916895, |
|
| 172 | + 'ts_added' => 1466515325, |
|
| 173 | + 'activity_type' => 'dropoff', |
|
| 174 | + 'upload_id' => '1a499993c63d68d1a5d26045a1763d16', |
|
| 175 | + 'upload_extension' => 'csv', |
|
| 176 | + 'upload_url' => 'http:\/\/adb6def9928467589ebb-f540d5a8d53c2e76ad581b6e5c346ad6.\/1a499113c63d68d1a5d26045a1763d16.csv', |
|
| 177 | + 'upload_type' => 'ANY_FILE', |
|
| 178 | + 'contents' => 'Some text', |
|
| 179 | + 'lat' => 33.132675, |
|
| 180 | + 'lng' => -83.244743, |
|
| 181 | + 'device_type' => 'web' |
|
| 182 | + ]); |
|
| 183 | + |
|
| 184 | + $this->assertEquals(539264, $addressNote->note_id); |
|
| 185 | + $this->assertEquals('5555E83A4BE0055551537955558D5555', $addressNote->route_id); |
|
| 186 | + $this->assertEquals(162916895, $addressNote->route_destination_id); |
|
| 187 | + $this->assertEquals(1466515325, $addressNote->ts_added); |
|
| 188 | + $this->assertEquals('dropoff', $addressNote->activity_type); |
|
| 189 | + $this->assertEquals('1a499993c63d68d1a5d26045a1763d16', $addressNote->upload_id); |
|
| 190 | + $this->assertEquals('csv', $addressNote->upload_extension); |
|
| 191 | + $this->assertEquals('http:\/\/adb6def9928467589ebb-f540d5a8d53c2e76ad581b6e5c346ad6.\/1a499113c63d68d1a5d26045a1763d16.csv', $addressNote->upload_url); |
|
| 192 | + $this->assertEquals('ANY_FILE', $addressNote->upload_type); |
|
| 193 | + $this->assertEquals('Some text', $addressNote->contents); |
|
| 194 | + $this->assertEquals(33.132675, $addressNote->lat); |
|
| 195 | + $this->assertEquals(-83.244743, $addressNote->lng); |
|
| 196 | + $this->assertEquals('web', $addressNote->device_type); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + public function testGetAddressesNotes() |
|
| 200 | + { |
|
| 201 | + $noteParameters = [ |
|
| 202 | + 'route_id' => self::$route_id, |
|
| 203 | + 'route_destination_id' => self::$address_id, |
|
| 204 | + ]; |
|
| 205 | + |
|
| 206 | + $addressNote = new AddressNote(); |
|
| 207 | + |
|
| 208 | + $addressWithNotes = Address::fromArray( |
|
| 209 | + $addressNote->GetAddressesNotes($noteParameters) |
|
| 210 | + ); |
|
| 211 | + |
|
| 212 | + $firstNote = AddressNote::fromArray( |
|
| 213 | + $addressWithNotes->notes[0] |
|
| 214 | + ); |
|
| 215 | + |
|
| 216 | + $this->assertNotNull($addressWithNotes); |
|
| 217 | + $this->assertTrue(sizeof( $addressWithNotes->notes)>0); |
|
| 218 | + $this->assertContainsOnlyInstancesOf(AddressNote::class, [$firstNote]); |
|
| 219 | + $this->assertEquals('Test Address Note', $firstNote->contents); |
|
| 220 | + $this->assertEquals('dropoff',$firstNote->activity_type); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + public function testAddAddressNote() |
|
| 224 | + { |
|
| 225 | + $noteParameters = [ |
|
| 226 | + 'strFilename' => 'notes.csv', |
|
| 227 | + 'route_id' => self::$route_id, |
|
| 228 | + 'address_id' => self::$noteAddressId, |
|
| 229 | + 'dev_lat' => 33.132675170898, |
|
| 230 | + 'dev_lng' => -83.244743347168, |
|
| 231 | + 'device_type' => 'web', |
|
| 232 | + 'strUpdateType' => 'dropoff', |
|
| 233 | + 'strNoteContents' => 'Test Add Note To Route Address', |
|
| 234 | + ]; |
|
| 235 | + |
|
| 236 | + $addressNote = new AddressNote(); |
|
| 237 | + |
|
| 238 | + $response = AddressNoteResponse::fromArray( |
|
| 239 | + $addressNote->AddAddressNote($noteParameters) |
|
| 240 | + ); |
|
| 241 | + |
|
| 242 | + $this->assertNotNull($response); |
|
| 243 | + $this->assertContainsOnlyInstancesOf(AddressNoteResponse::class, [$response]); |
|
| 244 | + |
|
| 245 | + $firstNote = AddressNote::fromArray( |
|
| 246 | + $response->note |
|
| 247 | + ); |
|
| 248 | + |
|
| 249 | + $this->assertContainsOnlyInstancesOf(AddressNote::class, [$firstNote]); |
|
| 250 | + $this->assertEquals('Test Add Note To Route Address', $firstNote->contents); |
|
| 251 | + $this->assertNotNull($firstNote->upload_id); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + public function testAddNoteFile() |
|
| 255 | + { |
|
| 256 | + //$this->markTestSkipped('must be revisited.'); |
|
| 257 | + |
|
| 258 | + $noteParameters = [ |
|
| 259 | + 'strFilename' => dirname(__FILE__).'\data\notes.csv', |
|
| 260 | + 'route_id' => self::$route_id, |
|
| 261 | + 'address_id' => self::$noteFileAddressId, |
|
| 262 | + 'dev_lat' => 33.132675170898, |
|
| 263 | + 'dev_lng' => -83.244743347168, |
|
| 264 | + 'device_type' => 'web', |
|
| 265 | + 'strUpdateType' => 'dropoff', |
|
| 266 | + ]; |
|
| 267 | + |
|
| 268 | + $addressNote = new AddressNote(); |
|
| 269 | + |
|
| 270 | + $result = $addressNote->AddNoteFile($noteParameters); |
|
| 271 | + |
|
| 272 | + $response = AddressNoteResponse::fromArray( |
|
| 273 | + $result |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + sleep(5); |
|
| 277 | + |
|
| 278 | + $this->assertNotNull($response); |
|
| 279 | + $this->assertNotNull($response->status); |
|
| 280 | + $this->assertTrue($response->status); |
|
| 281 | + $this->assertContainsOnlyInstancesOf(AddressNoteResponse::class, [$response]); |
|
| 282 | + |
|
| 283 | + $firstNote = AddressNote::fromArray( |
|
| 284 | + $response->note |
|
| 285 | + ); |
|
| 286 | + |
|
| 287 | + $this->assertContainsOnlyInstancesOf(AddressNote::class, [$firstNote]); |
|
| 288 | + $this->assertNotNull($firstNote->upload_id); |
|
| 289 | + $this->assertNotNull($firstNote->upload_url); |
|
| 290 | + $this->assertEquals('csv', $firstNote->upload_extension); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + public function testGetCustomNoteTypeByKey() |
|
| 294 | + { |
|
| 295 | + $addressNote = new AddressNote(); |
|
| 296 | + |
|
| 297 | + $customNoteType = $addressNote->getCustomNoteTypeByKey(self::$createdCustomNotes[0]); |
|
| 298 | + |
|
| 299 | + $this->assertEquals(self::$createdCustomNotes[0],$customNoteType['note_custom_type']); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + public function testGetAllCustomNoteTypes() |
|
| 303 | + { |
|
| 304 | + $addressNote = new AddressNote(); |
|
| 305 | + |
|
| 306 | + $customNoteTypes = $addressNote->getAllCustomNoteTypes(); |
|
| 307 | + |
|
| 308 | + $firstCustomNoteType = CustomNoteTypeResponse::fromArray($customNoteTypes[0]); |
|
| 309 | + |
|
| 310 | + $this->assertNotNull($customNoteTypes); |
|
| 311 | + $this->assertTrue(sizeof($customNoteTypes)>0); |
|
| 312 | + $this->assertContainsOnlyInstancesOf(CustomNoteTypeResponse::class, [$firstCustomNoteType]); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + public function testCreateCustomNoteType() |
|
| 316 | + { |
|
| 317 | + $customNoteTypeKey = 'cnt'.date('yMdHi'); |
|
| 318 | + |
|
| 319 | + $noteParameters = [ |
|
| 320 | + 'type' => $customNoteTypeKey, |
|
| 321 | + 'values' => [ |
|
| 322 | + 'First value', |
|
| 323 | + 'Second value', |
|
| 324 | + 'Third value', |
|
| 325 | + ], |
|
| 326 | + ]; |
|
| 327 | 327 | |
| 328 | - $addressNote = new AddressNote(); |
|
| 328 | + $addressNote = new AddressNote(); |
|
| 329 | 329 | |
| 330 | - $response = $addressNote->createCustomNoteType($noteParameters); |
|
| 330 | + $response = $addressNote->createCustomNoteType($noteParameters); |
|
| 331 | 331 | |
| 332 | - $this->assertNotNull($response); |
|
| 333 | - $this->assertNotNull($response['result']); |
|
| 334 | - $this->assertEquals('OK', $response['result']); |
|
| 335 | - $this->assertNotNull($response['affected']); |
|
| 336 | - $this->assertEquals(1, $response['affected']); |
|
| 332 | + $this->assertNotNull($response); |
|
| 333 | + $this->assertNotNull($response['result']); |
|
| 334 | + $this->assertEquals('OK', $response['result']); |
|
| 335 | + $this->assertNotNull($response['affected']); |
|
| 336 | + $this->assertEquals(1, $response['affected']); |
|
| 337 | 337 | |
| 338 | - self::$createdCustomNotes[] = $customNoteTypeKey; |
|
| 339 | - } |
|
| 338 | + self::$createdCustomNotes[] = $customNoteTypeKey; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - public function testAddCustomNoteToRoute() |
|
| 342 | - { |
|
| 343 | - $addressNote = new AddressNote(); |
|
| 341 | + public function testAddCustomNoteToRoute() |
|
| 342 | + { |
|
| 343 | + $addressNote = new AddressNote(); |
|
| 344 | 344 | |
| 345 | - $customNoteType = $addressNote->getCustomNoteTypeByKey(self::$createdCustomNotes[0]); |
|
| 345 | + $customNoteType = $addressNote->getCustomNoteTypeByKey(self::$createdCustomNotes[0]); |
|
| 346 | 346 | |
| 347 | - $noteParameters = [ |
|
| 348 | - 'route_id' => self::$route_id, |
|
| 349 | - 'address_id' => self::$address_id, |
|
| 350 | - 'format' => 'json', |
|
| 351 | - 'dev_lat' => 33.132675170898, |
|
| 352 | - 'dev_lng' => -83.244743347168, |
|
| 353 | - 'custom_note_type['.$customNoteType["note_custom_type_id"].']' => 'Pickup package', |
|
| 354 | - 'strUpdateType' => 'dropoff', |
|
| 355 | - 'strNoteContents' => 'php test 1111', |
|
| 356 | - ]; |
|
| 347 | + $noteParameters = [ |
|
| 348 | + 'route_id' => self::$route_id, |
|
| 349 | + 'address_id' => self::$address_id, |
|
| 350 | + 'format' => 'json', |
|
| 351 | + 'dev_lat' => 33.132675170898, |
|
| 352 | + 'dev_lng' => -83.244743347168, |
|
| 353 | + 'custom_note_type['.$customNoteType["note_custom_type_id"].']' => 'Pickup package', |
|
| 354 | + 'strUpdateType' => 'dropoff', |
|
| 355 | + 'strNoteContents' => 'php test 1111', |
|
| 356 | + ]; |
|
| 357 | 357 | |
| 358 | - $response = AddressNoteResponse::fromArray( |
|
| 359 | - $addressNote->addCustomNoteToRoute($noteParameters) |
|
| 360 | - ); |
|
| 358 | + $response = AddressNoteResponse::fromArray( |
|
| 359 | + $addressNote->addCustomNoteToRoute($noteParameters) |
|
| 360 | + ); |
|
| 361 | 361 | |
| 362 | - $this->assertNotNull($response); |
|
| 363 | - $this->assertContainsOnlyInstancesOf(AddressNoteResponse::class, [$response]); |
|
| 362 | + $this->assertNotNull($response); |
|
| 363 | + $this->assertContainsOnlyInstancesOf(AddressNoteResponse::class, [$response]); |
|
| 364 | 364 | |
| 365 | - $note = AddressNote::fromArray($response->note); |
|
| 366 | - $this->assertNotNull($note); |
|
| 367 | - $this->assertNotNull($note->custom_types); |
|
| 368 | - $this->assertTrue(sizeof($note->custom_types)>0); |
|
| 365 | + $note = AddressNote::fromArray($response->note); |
|
| 366 | + $this->assertNotNull($note); |
|
| 367 | + $this->assertNotNull($note->custom_types); |
|
| 368 | + $this->assertTrue(sizeof($note->custom_types)>0); |
|
| 369 | 369 | |
| 370 | - $customNote = CustomNoteType::fromArray($note->custom_types[0]); |
|
| 370 | + $customNote = CustomNoteType::fromArray($note->custom_types[0]); |
|
| 371 | 371 | |
| 372 | - $this->assertContainsOnlyInstancesOf(CustomNoteType::class, [$customNote]); |
|
| 373 | - $this->assertEquals('Pickup package',$customNote->note_custom_value); |
|
| 374 | - } |
|
| 372 | + $this->assertContainsOnlyInstancesOf(CustomNoteType::class, [$customNote]); |
|
| 373 | + $this->assertEquals('Pickup package',$customNote->note_custom_value); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - public function testRemoveCustomNoteType() |
|
| 377 | - { |
|
| 378 | - $addressNote = new AddressNote(); |
|
| 376 | + public function testRemoveCustomNoteType() |
|
| 377 | + { |
|
| 378 | + $addressNote = new AddressNote(); |
|
| 379 | 379 | |
| 380 | - $customNoteType = $addressNote->getCustomNoteTypeByKey(self::$createdCustomNotes[0]); |
|
| 380 | + $customNoteType = $addressNote->getCustomNoteTypeByKey(self::$createdCustomNotes[0]); |
|
| 381 | 381 | |
| 382 | - $customNoteTypeParameters = [ |
|
| 383 | - 'id' => $customNoteType["note_custom_type_id"], |
|
| 384 | - ]; |
|
| 382 | + $customNoteTypeParameters = [ |
|
| 383 | + 'id' => $customNoteType["note_custom_type_id"], |
|
| 384 | + ]; |
|
| 385 | 385 | |
| 386 | - $response = $addressNote->removeCustomNoteType($customNoteTypeParameters); |
|
| 386 | + $response = $addressNote->removeCustomNoteType($customNoteTypeParameters); |
|
| 387 | 387 | |
| 388 | - $this->assertNotNull($response); |
|
| 389 | - $this->assertNotNull($response['result']); |
|
| 390 | - $this->assertEquals('OK', $response['result']); |
|
| 391 | - $this->assertNotNull($response['affected']); |
|
| 392 | - $this->assertEquals(1, $response['affected']); |
|
| 388 | + $this->assertNotNull($response); |
|
| 389 | + $this->assertNotNull($response['result']); |
|
| 390 | + $this->assertEquals('OK', $response['result']); |
|
| 391 | + $this->assertNotNull($response['affected']); |
|
| 392 | + $this->assertEquals(1, $response['affected']); |
|
| 393 | 393 | |
| 394 | - array_shift(self::$createdCustomNotes); |
|
| 395 | - } |
|
| 394 | + array_shift(self::$createdCustomNotes); |
|
| 395 | + } |
|
| 396 | 396 | |
| 397 | - public static function tearDownAfterClass() |
|
| 398 | - { |
|
| 399 | - $optimizationProblemId = self:: $problem->optimization_problem_id; |
|
| 397 | + public static function tearDownAfterClass() |
|
| 398 | + { |
|
| 399 | + $optimizationProblemId = self:: $problem->optimization_problem_id; |
|
| 400 | 400 | |
| 401 | - $params = [ |
|
| 402 | - 'optimization_problem_ids' => [ |
|
| 403 | - '0' => $optimizationProblemId |
|
| 404 | - ], |
|
| 405 | - 'redirect' => 0, |
|
| 406 | - ]; |
|
| 401 | + $params = [ |
|
| 402 | + 'optimization_problem_ids' => [ |
|
| 403 | + '0' => $optimizationProblemId |
|
| 404 | + ], |
|
| 405 | + 'redirect' => 0, |
|
| 406 | + ]; |
|
| 407 | 407 | |
| 408 | - $result = self:: $problem->removeOptimization($params); |
|
| 408 | + $result = self:: $problem->removeOptimization($params); |
|
| 409 | 409 | |
| 410 | - if ($result!=null && $result['status']==true) { |
|
| 411 | - echo "The test optimization was removed <br>"; |
|
| 412 | - } else { |
|
| 413 | - echo "Cannot remove the test optimization <br>"; |
|
| 414 | - } |
|
| 410 | + if ($result!=null && $result['status']==true) { |
|
| 411 | + echo "The test optimization was removed <br>"; |
|
| 412 | + } else { |
|
| 413 | + echo "Cannot remove the test optimization <br>"; |
|
| 414 | + } |
|
| 415 | 415 | |
| 416 | - $addressNote = new AddressNote(); |
|
| 416 | + $addressNote = new AddressNote(); |
|
| 417 | 417 | |
| 418 | - foreach (self::$createdCustomNotes as $createdCustomNote) { |
|
| 419 | - $customNoteId = $addressNote->getCustomNoteTypeByKey($createdCustomNote)["note_custom_type_id"]; |
|
| 418 | + foreach (self::$createdCustomNotes as $createdCustomNote) { |
|
| 419 | + $customNoteId = $addressNote->getCustomNoteTypeByKey($createdCustomNote)["note_custom_type_id"]; |
|
| 420 | 420 | |
| 421 | - $customNoteTypeParameters = [ |
|
| 422 | - 'id' => $customNoteId, |
|
| 423 | - ]; |
|
| 421 | + $customNoteTypeParameters = [ |
|
| 422 | + 'id' => $customNoteId, |
|
| 423 | + ]; |
|
| 424 | 424 | |
| 425 | - $response = $addressNote->removeCustomNoteType($customNoteTypeParameters); |
|
| 425 | + $response = $addressNote->removeCustomNoteType($customNoteTypeParameters); |
|
| 426 | 426 | |
| 427 | - if ($response!=null && $response['result']!=null && $response['result']=='OK') { |
|
| 428 | - echo "Removed the custom note type ".$createdCustomNote.'<br>'; |
|
| 429 | - } |
|
| 430 | - } |
|
| 427 | + if ($response!=null && $response['result']!=null && $response['result']=='OK') { |
|
| 428 | + echo "Removed the custom note type ".$createdCustomNote.'<br>'; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | 431 | |
| 432 | - } |
|
| 432 | + } |
|
| 433 | 433 | } |
| 434 | 434 | \ No newline at end of file |
@@ -14,205 +14,205 @@ |
||
| 14 | 14 | |
| 15 | 15 | class ActivityParametersUntTests extends \PHPUnit\Framework\TestCase |
| 16 | 16 | { |
| 17 | - public static $route_id = null; |
|
| 18 | - public static $problem = null; |
|
| 19 | - |
|
| 20 | - public static function setUpBeforeClass() |
|
| 21 | - { |
|
| 22 | - if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 23 | - $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 24 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 28 | - |
|
| 29 | - $addresses = []; |
|
| 30 | - $addresses[] = Address::fromArray([ |
|
| 31 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 32 | - 'is_depot' => true, |
|
| 33 | - 'lat' => 30.159341812134, |
|
| 34 | - 'lng' => -81.538619995117, |
|
| 35 | - 'time' => 300, |
|
| 36 | - 'time_window_start' => 28800, |
|
| 37 | - 'time_window_end' => 32400, |
|
| 38 | - ]); |
|
| 39 | - |
|
| 40 | - $addresses[] = Address::fromArray([ |
|
| 41 | - 'address' => '214 Edgewater Branch Drive 32259', |
|
| 42 | - 'lat' => 30.103567123413, |
|
| 43 | - 'lng' => -81.595352172852, |
|
| 44 | - 'time' => 300, |
|
| 45 | - 'time_window_start' => 36000, |
|
| 46 | - 'time_window_end' => 37200, |
|
| 47 | - ]); |
|
| 48 | - |
|
| 49 | - $addresses[] = Address::fromArray([ |
|
| 50 | - 'address' => '756 eagle point dr 32092', |
|
| 51 | - 'lat' => 30.046422958374, |
|
| 52 | - 'lng' => -81.508758544922, |
|
| 53 | - 'time' => 300, |
|
| 54 | - 'time_window_start' => 39600, |
|
| 55 | - 'time_window_end' => 41400, |
|
| 56 | - ]); |
|
| 57 | - |
|
| 58 | - $addresses[] = Address::fromArray([ |
|
| 59 | - 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', |
|
| 60 | - 'lat' => 30.048496, |
|
| 61 | - 'lng' => -81.558716, |
|
| 62 | - 'time' => 300, |
|
| 63 | - 'time_window_start' => 43200, |
|
| 64 | - 'time_window_end' => 45000, |
|
| 65 | - ]); |
|
| 66 | - |
|
| 67 | - $parameters = RouteParameters::fromArray([ |
|
| 68 | - 'device_type' => DeviceType::IPAD, |
|
| 69 | - 'disable_optimization' => false, |
|
| 70 | - 'route_name' => 'phpunit test '.date('Y-m-d H:i'), |
|
| 71 | - ]); |
|
| 72 | - |
|
| 73 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 74 | - $optimizationParameters->setAddresses($addresses); |
|
| 75 | - $optimizationParameters->setParameters($parameters); |
|
| 76 | - |
|
| 77 | - self::$problem = OptimizationProblem::optimize($optimizationParameters); |
|
| 78 | - $routes = self::$problem->getRoutes(); |
|
| 79 | - self::$route_id = $routes[0]->route_id; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function testFromArray() |
|
| 83 | - { |
|
| 84 | - $activityParameters = ActivityParameters::fromArray([ |
|
| 85 | - "activity_id" => "77BBB5F38723CCCCCCCCCCCCCCCCDD88", |
|
| 86 | - "member_id" => 444333, |
|
| 87 | - "activity_timestamp" => 1595418362, |
|
| 88 | - "activity_type" => "note-insert", |
|
| 89 | - "activity_message" => "A note was added to address '63 Stone Creek Cir St Johns, FL 32259, USA' from Web Interface", |
|
| 90 | - "route_id" => "38777FFFE274A1F970A3CA8D96F32222", |
|
| 91 | - "route_destination_id" => 535455583, |
|
| 92 | - "note_id" => 9933366, |
|
| 93 | - "note_type" => "Drop Off Occurred", |
|
| 94 | - "note_contents" => "Test Add Note To Route Address", |
|
| 95 | - "route_name" => "phpunit test 2020-07-22 13:45", |
|
| 96 | - "note_file" => "file.ext", |
|
| 97 | - "destination_name" => "63 Stone Creek Cir St Johns, FL 32259, USA", |
|
| 98 | - "destination_alias" => "Dest Alias", |
|
| 99 | - "member" => [ |
|
| 100 | - "member_id" => "444333", |
|
| 101 | - "member_first_name" => "Olbay", |
|
| 102 | - "member_last_name" => "Gustavson", |
|
| 103 | - "member_email" => "[email protected]" |
|
| 104 | - ] |
|
| 105 | - ]); |
|
| 106 | - |
|
| 107 | - $this->assertEquals('77BBB5F38723CCCCCCCCCCCCCCCCDD88', $activityParameters->activity_id); |
|
| 108 | - |
|
| 109 | - $this->assertEquals(444333, $activityParameters->member_id); |
|
| 110 | - $this->assertEquals(1595418362, $activityParameters->activity_timestamp); |
|
| 111 | - $this->assertEquals('note-insert', $activityParameters->activity_type); |
|
| 112 | - $this->assertEquals('A note was added to address \'63 Stone Creek Cir St Johns, FL 32259, USA\' from Web Interface', $activityParameters->activity_message); |
|
| 113 | - $this->assertEquals('38777FFFE274A1F970A3CA8D96F32222', $activityParameters->route_id); |
|
| 114 | - $this->assertEquals(535455583, $activityParameters->route_destination_id); |
|
| 115 | - $this->assertEquals(9933366, $activityParameters->note_id); |
|
| 116 | - $this->assertEquals('Drop Off Occurred', $activityParameters->note_type); |
|
| 117 | - $this->assertEquals('Test Add Note To Route Address', $activityParameters->note_contents); |
|
| 118 | - $this->assertEquals('phpunit test 2020-07-22 13:45', $activityParameters->route_name); |
|
| 119 | - $this->assertEquals('file.ext', $activityParameters->note_file); |
|
| 120 | - $this->assertEquals('63 Stone Creek Cir St Johns, FL 32259, USA', $activityParameters->destination_name); |
|
| 121 | - $this->assertEquals('Dest Alias', $activityParameters->destination_alias); |
|
| 122 | - $this->assertEquals([ |
|
| 123 | - "member_id" => "444333", |
|
| 124 | - "member_first_name" => "Olbay", |
|
| 125 | - "member_last_name" => "Gustavson", |
|
| 126 | - "member_email" => "[email protected]" |
|
| 127 | - ], $activityParameters->member); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - public function testGetActivities() |
|
| 131 | - { |
|
| 132 | - $activities = new ActivityParameters(); |
|
| 133 | - |
|
| 134 | - $activityParameters = ActivityParameters::fromArray([ |
|
| 135 | - 'limit' => 10, |
|
| 136 | - 'offset' => 0, |
|
| 137 | - ]); |
|
| 138 | - |
|
| 139 | - $result = $activities->getActivities($activityParameters); |
|
| 140 | - |
|
| 141 | - $this->assertNotNull($result); |
|
| 142 | - $this->assertNotNull(isset($result['results'])); |
|
| 143 | - |
|
| 144 | - $firstActivity = ActivityParameters::fromArray( |
|
| 145 | - $result['results'][0] |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - $this->assertContainsOnlyInstancesOf(ActivityParameters::class, [$firstActivity]); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - public function testSearchActivities() |
|
| 152 | - { |
|
| 153 | - $activities = new ActivityParameters(); |
|
| 154 | - |
|
| 155 | - $activityTypes = new ActivityTypes(); |
|
| 156 | - |
|
| 157 | - foreach ($activityTypes->getConstants() as $prop => $value) { |
|
| 158 | - $activityParameters = ActivityParameters::fromArray([ |
|
| 159 | - 'activity_type' => $value, |
|
| 160 | - 'limit' => 2, |
|
| 161 | - 'offset' => 0, |
|
| 162 | - ]); |
|
| 163 | - |
|
| 164 | - $activities = new ActivityParameters(); |
|
| 165 | - $result = $activities->searchActivities($activityParameters); |
|
| 166 | - |
|
| 167 | - $this->assertNotNull($result); |
|
| 168 | - $this->assertNotNull(isset($result['results'])); |
|
| 169 | - |
|
| 170 | - if (sizeof($result['results'])>0) { |
|
| 171 | - $firstActivity = ActivityParameters::fromArray( |
|
| 172 | - $result['results'][0] |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - $this->assertContainsOnlyInstancesOf(ActivityParameters::class, [$firstActivity]); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - public function testSendUserMessage() |
|
| 181 | - { |
|
| 182 | - $activities = new ActivityParameters(); |
|
| 183 | - |
|
| 184 | - $postParameters = ActivityParameters::fromArray([ |
|
| 185 | - 'activity_type' => 'user_message', |
|
| 186 | - 'activity_message' => 'Hello - php!', |
|
| 187 | - 'route_id' => self::$route_id, |
|
| 188 | - ]); |
|
| 189 | - |
|
| 190 | - $result = $activities->sendUserMessage($postParameters); |
|
| 191 | - |
|
| 192 | - $this->assertNotNull($result); |
|
| 193 | - $this->assertNotNull(isset($result['status'])); |
|
| 194 | - $this->assertTrue(isset($result['status'])); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - public static function tearDownAfterClass() |
|
| 198 | - { |
|
| 199 | - $optimizationProblemId = self:: $problem->optimization_problem_id; |
|
| 200 | - |
|
| 201 | - $params = [ |
|
| 202 | - 'optimization_problem_ids' => [ |
|
| 203 | - '0' => $optimizationProblemId |
|
| 204 | - ], |
|
| 205 | - 'redirect' => 0, |
|
| 206 | - ]; |
|
| 207 | - |
|
| 208 | - $optimizationProblem = new OptimizationProblem(); |
|
| 209 | - |
|
| 210 | - $result = $optimizationProblem->removeOptimization($params); |
|
| 211 | - |
|
| 212 | - if ($result!=null && $result['status']==true) { |
|
| 213 | - echo "The test optimization was removed <br>"; |
|
| 214 | - } else { |
|
| 215 | - echo "Cannot remove the test optimization <br>"; |
|
| 216 | - } |
|
| 217 | - } |
|
| 17 | + public static $route_id = null; |
|
| 18 | + public static $problem = null; |
|
| 19 | + |
|
| 20 | + public static function setUpBeforeClass() |
|
| 21 | + { |
|
| 22 | + if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 23 | + $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 24 | + self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 28 | + |
|
| 29 | + $addresses = []; |
|
| 30 | + $addresses[] = Address::fromArray([ |
|
| 31 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 32 | + 'is_depot' => true, |
|
| 33 | + 'lat' => 30.159341812134, |
|
| 34 | + 'lng' => -81.538619995117, |
|
| 35 | + 'time' => 300, |
|
| 36 | + 'time_window_start' => 28800, |
|
| 37 | + 'time_window_end' => 32400, |
|
| 38 | + ]); |
|
| 39 | + |
|
| 40 | + $addresses[] = Address::fromArray([ |
|
| 41 | + 'address' => '214 Edgewater Branch Drive 32259', |
|
| 42 | + 'lat' => 30.103567123413, |
|
| 43 | + 'lng' => -81.595352172852, |
|
| 44 | + 'time' => 300, |
|
| 45 | + 'time_window_start' => 36000, |
|
| 46 | + 'time_window_end' => 37200, |
|
| 47 | + ]); |
|
| 48 | + |
|
| 49 | + $addresses[] = Address::fromArray([ |
|
| 50 | + 'address' => '756 eagle point dr 32092', |
|
| 51 | + 'lat' => 30.046422958374, |
|
| 52 | + 'lng' => -81.508758544922, |
|
| 53 | + 'time' => 300, |
|
| 54 | + 'time_window_start' => 39600, |
|
| 55 | + 'time_window_end' => 41400, |
|
| 56 | + ]); |
|
| 57 | + |
|
| 58 | + $addresses[] = Address::fromArray([ |
|
| 59 | + 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', |
|
| 60 | + 'lat' => 30.048496, |
|
| 61 | + 'lng' => -81.558716, |
|
| 62 | + 'time' => 300, |
|
| 63 | + 'time_window_start' => 43200, |
|
| 64 | + 'time_window_end' => 45000, |
|
| 65 | + ]); |
|
| 66 | + |
|
| 67 | + $parameters = RouteParameters::fromArray([ |
|
| 68 | + 'device_type' => DeviceType::IPAD, |
|
| 69 | + 'disable_optimization' => false, |
|
| 70 | + 'route_name' => 'phpunit test '.date('Y-m-d H:i'), |
|
| 71 | + ]); |
|
| 72 | + |
|
| 73 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 74 | + $optimizationParameters->setAddresses($addresses); |
|
| 75 | + $optimizationParameters->setParameters($parameters); |
|
| 76 | + |
|
| 77 | + self::$problem = OptimizationProblem::optimize($optimizationParameters); |
|
| 78 | + $routes = self::$problem->getRoutes(); |
|
| 79 | + self::$route_id = $routes[0]->route_id; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function testFromArray() |
|
| 83 | + { |
|
| 84 | + $activityParameters = ActivityParameters::fromArray([ |
|
| 85 | + "activity_id" => "77BBB5F38723CCCCCCCCCCCCCCCCDD88", |
|
| 86 | + "member_id" => 444333, |
|
| 87 | + "activity_timestamp" => 1595418362, |
|
| 88 | + "activity_type" => "note-insert", |
|
| 89 | + "activity_message" => "A note was added to address '63 Stone Creek Cir St Johns, FL 32259, USA' from Web Interface", |
|
| 90 | + "route_id" => "38777FFFE274A1F970A3CA8D96F32222", |
|
| 91 | + "route_destination_id" => 535455583, |
|
| 92 | + "note_id" => 9933366, |
|
| 93 | + "note_type" => "Drop Off Occurred", |
|
| 94 | + "note_contents" => "Test Add Note To Route Address", |
|
| 95 | + "route_name" => "phpunit test 2020-07-22 13:45", |
|
| 96 | + "note_file" => "file.ext", |
|
| 97 | + "destination_name" => "63 Stone Creek Cir St Johns, FL 32259, USA", |
|
| 98 | + "destination_alias" => "Dest Alias", |
|
| 99 | + "member" => [ |
|
| 100 | + "member_id" => "444333", |
|
| 101 | + "member_first_name" => "Olbay", |
|
| 102 | + "member_last_name" => "Gustavson", |
|
| 103 | + "member_email" => "[email protected]" |
|
| 104 | + ] |
|
| 105 | + ]); |
|
| 106 | + |
|
| 107 | + $this->assertEquals('77BBB5F38723CCCCCCCCCCCCCCCCDD88', $activityParameters->activity_id); |
|
| 108 | + |
|
| 109 | + $this->assertEquals(444333, $activityParameters->member_id); |
|
| 110 | + $this->assertEquals(1595418362, $activityParameters->activity_timestamp); |
|
| 111 | + $this->assertEquals('note-insert', $activityParameters->activity_type); |
|
| 112 | + $this->assertEquals('A note was added to address \'63 Stone Creek Cir St Johns, FL 32259, USA\' from Web Interface', $activityParameters->activity_message); |
|
| 113 | + $this->assertEquals('38777FFFE274A1F970A3CA8D96F32222', $activityParameters->route_id); |
|
| 114 | + $this->assertEquals(535455583, $activityParameters->route_destination_id); |
|
| 115 | + $this->assertEquals(9933366, $activityParameters->note_id); |
|
| 116 | + $this->assertEquals('Drop Off Occurred', $activityParameters->note_type); |
|
| 117 | + $this->assertEquals('Test Add Note To Route Address', $activityParameters->note_contents); |
|
| 118 | + $this->assertEquals('phpunit test 2020-07-22 13:45', $activityParameters->route_name); |
|
| 119 | + $this->assertEquals('file.ext', $activityParameters->note_file); |
|
| 120 | + $this->assertEquals('63 Stone Creek Cir St Johns, FL 32259, USA', $activityParameters->destination_name); |
|
| 121 | + $this->assertEquals('Dest Alias', $activityParameters->destination_alias); |
|
| 122 | + $this->assertEquals([ |
|
| 123 | + "member_id" => "444333", |
|
| 124 | + "member_first_name" => "Olbay", |
|
| 125 | + "member_last_name" => "Gustavson", |
|
| 126 | + "member_email" => "[email protected]" |
|
| 127 | + ], $activityParameters->member); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + public function testGetActivities() |
|
| 131 | + { |
|
| 132 | + $activities = new ActivityParameters(); |
|
| 133 | + |
|
| 134 | + $activityParameters = ActivityParameters::fromArray([ |
|
| 135 | + 'limit' => 10, |
|
| 136 | + 'offset' => 0, |
|
| 137 | + ]); |
|
| 138 | + |
|
| 139 | + $result = $activities->getActivities($activityParameters); |
|
| 140 | + |
|
| 141 | + $this->assertNotNull($result); |
|
| 142 | + $this->assertNotNull(isset($result['results'])); |
|
| 143 | + |
|
| 144 | + $firstActivity = ActivityParameters::fromArray( |
|
| 145 | + $result['results'][0] |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + $this->assertContainsOnlyInstancesOf(ActivityParameters::class, [$firstActivity]); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + public function testSearchActivities() |
|
| 152 | + { |
|
| 153 | + $activities = new ActivityParameters(); |
|
| 154 | + |
|
| 155 | + $activityTypes = new ActivityTypes(); |
|
| 156 | + |
|
| 157 | + foreach ($activityTypes->getConstants() as $prop => $value) { |
|
| 158 | + $activityParameters = ActivityParameters::fromArray([ |
|
| 159 | + 'activity_type' => $value, |
|
| 160 | + 'limit' => 2, |
|
| 161 | + 'offset' => 0, |
|
| 162 | + ]); |
|
| 163 | + |
|
| 164 | + $activities = new ActivityParameters(); |
|
| 165 | + $result = $activities->searchActivities($activityParameters); |
|
| 166 | + |
|
| 167 | + $this->assertNotNull($result); |
|
| 168 | + $this->assertNotNull(isset($result['results'])); |
|
| 169 | + |
|
| 170 | + if (sizeof($result['results'])>0) { |
|
| 171 | + $firstActivity = ActivityParameters::fromArray( |
|
| 172 | + $result['results'][0] |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + $this->assertContainsOnlyInstancesOf(ActivityParameters::class, [$firstActivity]); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + public function testSendUserMessage() |
|
| 181 | + { |
|
| 182 | + $activities = new ActivityParameters(); |
|
| 183 | + |
|
| 184 | + $postParameters = ActivityParameters::fromArray([ |
|
| 185 | + 'activity_type' => 'user_message', |
|
| 186 | + 'activity_message' => 'Hello - php!', |
|
| 187 | + 'route_id' => self::$route_id, |
|
| 188 | + ]); |
|
| 189 | + |
|
| 190 | + $result = $activities->sendUserMessage($postParameters); |
|
| 191 | + |
|
| 192 | + $this->assertNotNull($result); |
|
| 193 | + $this->assertNotNull(isset($result['status'])); |
|
| 194 | + $this->assertTrue(isset($result['status'])); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + public static function tearDownAfterClass() |
|
| 198 | + { |
|
| 199 | + $optimizationProblemId = self:: $problem->optimization_problem_id; |
|
| 200 | + |
|
| 201 | + $params = [ |
|
| 202 | + 'optimization_problem_ids' => [ |
|
| 203 | + '0' => $optimizationProblemId |
|
| 204 | + ], |
|
| 205 | + 'redirect' => 0, |
|
| 206 | + ]; |
|
| 207 | + |
|
| 208 | + $optimizationProblem = new OptimizationProblem(); |
|
| 209 | + |
|
| 210 | + $result = $optimizationProblem->removeOptimization($params); |
|
| 211 | + |
|
| 212 | + if ($result!=null && $result['status']==true) { |
|
| 213 | + echo "The test optimization was removed <br>"; |
|
| 214 | + } else { |
|
| 215 | + echo "Cannot remove the test optimization <br>"; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | 218 | } |
| 219 | 219 | \ No newline at end of file |
@@ -7,53 +7,53 @@ |
||
| 7 | 7 | |
| 8 | 8 | class AddressNoteResponseUnitTests extends \PHPUnit\Framework\TestCase |
| 9 | 9 | { |
| 10 | - public function testFromArray() |
|
| 11 | - { |
|
| 12 | - $addressNoteResponse = AddressNoteResponse::fromArray([ |
|
| 13 | - 'status' => true, |
|
| 14 | - 'note_id' => '1015289', |
|
| 15 | - 'upload_id' => '', |
|
| 16 | - 'note' => [ |
|
| 17 | - 'note_id' => 1015289, |
|
| 18 | - 'route_id' => 'DD376C7148E777736CFABE2BD9998BDD', |
|
| 19 | - 'route_destination_id' => 183045812, |
|
| 20 | - 'ts_added' => 1480511401, |
|
| 21 | - 'activity_type' => '', |
|
| 22 | - 'upload_id' => '', |
|
| 23 | - 'upload_extension' => null, |
|
| 24 | - 'upload_url' => null, |
|
| 25 | - 'upload_type' => null, |
|
| 26 | - 'contents' => 'Note example for Destination Audit Use Case', |
|
| 27 | - 'lat' => 41.145241, |
|
| 28 | - 'lng' => -81.410248, |
|
| 29 | - 'device_type' => 'web' |
|
| 30 | - ] |
|
| 31 | - ]); |
|
| 10 | + public function testFromArray() |
|
| 11 | + { |
|
| 12 | + $addressNoteResponse = AddressNoteResponse::fromArray([ |
|
| 13 | + 'status' => true, |
|
| 14 | + 'note_id' => '1015289', |
|
| 15 | + 'upload_id' => '', |
|
| 16 | + 'note' => [ |
|
| 17 | + 'note_id' => 1015289, |
|
| 18 | + 'route_id' => 'DD376C7148E777736CFABE2BD9998BDD', |
|
| 19 | + 'route_destination_id' => 183045812, |
|
| 20 | + 'ts_added' => 1480511401, |
|
| 21 | + 'activity_type' => '', |
|
| 22 | + 'upload_id' => '', |
|
| 23 | + 'upload_extension' => null, |
|
| 24 | + 'upload_url' => null, |
|
| 25 | + 'upload_type' => null, |
|
| 26 | + 'contents' => 'Note example for Destination Audit Use Case', |
|
| 27 | + 'lat' => 41.145241, |
|
| 28 | + 'lng' => -81.410248, |
|
| 29 | + 'device_type' => 'web' |
|
| 30 | + ] |
|
| 31 | + ]); |
|
| 32 | 32 | |
| 33 | - $this->assertEquals(true, $addressNoteResponse->status); |
|
| 34 | - $this->assertEquals('1015289', $addressNoteResponse->note_id); |
|
| 35 | - $this->assertEquals('', $addressNoteResponse->upload_id); |
|
| 36 | - $this->assertEquals([ |
|
| 37 | - 'note_id' => 1015289, |
|
| 38 | - 'route_id' => 'DD376C7148E777736CFABE2BD9998BDD', |
|
| 39 | - 'route_destination_id' => 183045812, |
|
| 40 | - 'ts_added' => 1480511401, |
|
| 41 | - 'activity_type' => '', |
|
| 42 | - 'upload_id' => '', |
|
| 43 | - 'upload_extension' => null, |
|
| 44 | - 'upload_url' => null, |
|
| 45 | - 'upload_type' => null, |
|
| 46 | - 'contents' => 'Note example for Destination Audit Use Case', |
|
| 47 | - 'lat' => 41.145241, |
|
| 48 | - 'lng' => -81.410248, |
|
| 49 | - 'device_type' => 'web' |
|
| 50 | - ], |
|
| 51 | - $addressNoteResponse->note); |
|
| 33 | + $this->assertEquals(true, $addressNoteResponse->status); |
|
| 34 | + $this->assertEquals('1015289', $addressNoteResponse->note_id); |
|
| 35 | + $this->assertEquals('', $addressNoteResponse->upload_id); |
|
| 36 | + $this->assertEquals([ |
|
| 37 | + 'note_id' => 1015289, |
|
| 38 | + 'route_id' => 'DD376C7148E777736CFABE2BD9998BDD', |
|
| 39 | + 'route_destination_id' => 183045812, |
|
| 40 | + 'ts_added' => 1480511401, |
|
| 41 | + 'activity_type' => '', |
|
| 42 | + 'upload_id' => '', |
|
| 43 | + 'upload_extension' => null, |
|
| 44 | + 'upload_url' => null, |
|
| 45 | + 'upload_type' => null, |
|
| 46 | + 'contents' => 'Note example for Destination Audit Use Case', |
|
| 47 | + 'lat' => 41.145241, |
|
| 48 | + 'lng' => -81.410248, |
|
| 49 | + 'device_type' => 'web' |
|
| 50 | + ], |
|
| 51 | + $addressNoteResponse->note); |
|
| 52 | 52 | |
| 53 | - $note = AddressNote::fromArray( |
|
| 54 | - $addressNoteResponse->note |
|
| 55 | - ); |
|
| 53 | + $note = AddressNote::fromArray( |
|
| 54 | + $addressNoteResponse->note |
|
| 55 | + ); |
|
| 56 | 56 | |
| 57 | - $this->assertContainsOnlyInstancesOf(AddressNote::class, [$note]); |
|
| 58 | - } |
|
| 57 | + $this->assertContainsOnlyInstancesOf(AddressNote::class, [$note]); |
|
| 58 | + } |
|
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |
@@ -7,16 +7,16 @@ |
||
| 7 | 7 | |
| 8 | 8 | class RapidAddressSearchResponseUnitTests extends \PHPUnit\Framework\TestCase |
| 9 | 9 | { |
| 10 | - public function testFromArray() |
|
| 11 | - { |
|
| 12 | - $rapidAddressSearch = RapidAddressSearchResponse::fromArray([ |
|
| 13 | - 'zipcode' => '00601', |
|
| 14 | - 'street_name' => 'GENERAL DELIVERY', |
|
| 15 | - 'county_no' => '103' |
|
| 16 | - ]); |
|
| 10 | + public function testFromArray() |
|
| 11 | + { |
|
| 12 | + $rapidAddressSearch = RapidAddressSearchResponse::fromArray([ |
|
| 13 | + 'zipcode' => '00601', |
|
| 14 | + 'street_name' => 'GENERAL DELIVERY', |
|
| 15 | + 'county_no' => '103' |
|
| 16 | + ]); |
|
| 17 | 17 | |
| 18 | - $this->assertEquals('00601', $rapidAddressSearch->zipcode); |
|
| 19 | - $this->assertEquals('GENERAL DELIVERY', $rapidAddressSearch->street_name); |
|
| 20 | - $this->assertEquals('103', $rapidAddressSearch->county_no); |
|
| 21 | - } |
|
| 18 | + $this->assertEquals('00601', $rapidAddressSearch->zipcode); |
|
| 19 | + $this->assertEquals('GENERAL DELIVERY', $rapidAddressSearch->street_name); |
|
| 20 | + $this->assertEquals('103', $rapidAddressSearch->county_no); |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | \ No newline at end of file |
@@ -27,391 +27,391 @@ |
||
| 27 | 27 | |
| 28 | 28 | class RouteTests extends \PHPUnit\Framework\TestCase |
| 29 | 29 | { |
| 30 | - public static $createdProblems = []; |
|
| 31 | - public static $testRoutes = []; |
|
| 32 | - public static $addresses = []; |
|
| 33 | - |
|
| 34 | - public static $removedOptimizationIDs = []; |
|
| 35 | - public static $removedRouteIDs = []; |
|
| 36 | - |
|
| 37 | - public static function setUpBeforeClass() |
|
| 38 | - { |
|
| 39 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 40 | - |
|
| 41 | - //region -- Prepae Addresses -- |
|
| 42 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); |
|
| 43 | - |
|
| 44 | - $addresses = []; |
|
| 45 | - foreach ($json as $address) { |
|
| 46 | - $addresses[] = Address::fromArray($address); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $parameters = RouteParameters::fromArray([ |
|
| 50 | - 'algorithm_type' => AlgorithmType::CVRP_TW_MD, |
|
| 51 | - 'distance_unit' => DistanceUnit::MILES, |
|
| 52 | - 'device_type' => DeviceType::WEB, |
|
| 53 | - 'optimize' => OptimizationType::DISTANCE, |
|
| 54 | - 'metric' => Metric::GEODESIC, |
|
| 55 | - 'route_max_duration' => 86400 * 2, |
|
| 56 | - 'travel_mode' => TravelMode::DRIVING, |
|
| 57 | - 'vehicle_capacity' => 50, |
|
| 58 | - 'vehicle_max_distance_mi' => 10000, |
|
| 59 | - 'parts' => 50, |
|
| 60 | - ]); |
|
| 61 | - //endregion |
|
| 62 | - |
|
| 63 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 64 | - $optimizationParameters->setAddresses($addresses); |
|
| 65 | - $optimizationParameters->setParameters($parameters); |
|
| 66 | - |
|
| 67 | - self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); |
|
| 68 | - |
|
| 69 | - self::$testRoutes = self::$createdProblems[0]->routes; |
|
| 70 | - |
|
| 71 | - //region -- Extra Testing Addresses -- |
|
| 72 | - $addresses = []; |
|
| 73 | - $addresses[] = Address::fromArray([ |
|
| 74 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 75 | - 'is_depot' => true, |
|
| 76 | - 'lat' => 30.159341812134, |
|
| 77 | - 'lng' => -81.538619995117, |
|
| 78 | - 'time' => 300, |
|
| 79 | - 'time_window_start' => 28800, |
|
| 80 | - 'time_window_end' => 32400, |
|
| 81 | - ]); |
|
| 82 | - |
|
| 83 | - $addresses[] = Address::fromArray([ |
|
| 84 | - 'address' => '214 Edgewater Branch Drive 32259', |
|
| 85 | - 'lat' => 30.103567123413, |
|
| 86 | - 'lng' => -81.595352172852, |
|
| 87 | - 'time' => 300, |
|
| 88 | - 'time_window_start' => 36000, |
|
| 89 | - 'time_window_end' => 37200, |
|
| 90 | - ]); |
|
| 91 | - |
|
| 92 | - $addresses[] = Address::fromArray([ |
|
| 93 | - 'address' => '756 eagle point dr 32092', |
|
| 94 | - 'lat' => 30.046422958374, |
|
| 95 | - 'lng' => -81.508758544922, |
|
| 96 | - 'time' => 300, |
|
| 97 | - 'time_window_start' => 39600, |
|
| 98 | - 'time_window_end' => 41400, |
|
| 99 | - ]); |
|
| 100 | - //endregion |
|
| 101 | - |
|
| 102 | - self::$addresses = $addresses; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function testFromArray() |
|
| 106 | - { |
|
| 107 | - //region -- Prepare Addresses -- |
|
| 108 | - |
|
| 109 | - $addresses = []; |
|
| 110 | - $addresses[] = [ |
|
| 111 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 112 | - 'is_depot' => true, |
|
| 113 | - 'lat' => 30.159341812134, |
|
| 114 | - 'lng' => -81.538619995117, |
|
| 115 | - 'time' => 300, |
|
| 116 | - 'time_window_start' => 28800, |
|
| 117 | - 'time_window_end' => 32400, |
|
| 118 | - ]; |
|
| 119 | - |
|
| 120 | - $addresses[] = [ |
|
| 121 | - 'address' => '214 Edgewater Branch Drive 32259', |
|
| 122 | - 'lat' => 30.103567123413, |
|
| 123 | - 'lng' => -81.595352172852, |
|
| 124 | - 'time' => 300, |
|
| 125 | - 'time_window_start' => 36000, |
|
| 126 | - 'time_window_end' => 37200, |
|
| 127 | - ]; |
|
| 128 | - |
|
| 129 | - $addresses[] = [ |
|
| 130 | - 'address' => '756 eagle point dr 32092', |
|
| 131 | - 'lat' => 30.046422958374, |
|
| 132 | - 'lng' => -81.508758544922, |
|
| 133 | - 'time' => 300, |
|
| 134 | - 'time_window_start' => 39600, |
|
| 135 | - 'time_window_end' => 41400, |
|
| 136 | - ]; |
|
| 137 | - |
|
| 138 | - $addresses[] = [ |
|
| 139 | - 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', |
|
| 140 | - 'lat' => 30.048496, |
|
| 141 | - 'lng' => -81.558716, |
|
| 142 | - 'time' => 300, |
|
| 143 | - 'time_window_start' => 43200, |
|
| 144 | - 'time_window_end' => 45000, |
|
| 145 | - ]; |
|
| 146 | - |
|
| 147 | - $addresses[] = [ |
|
| 148 | - 'address' => 'St Johns Florida 32259, USA', |
|
| 149 | - 'lat' => 30.099642, |
|
| 150 | - 'lng' => -81.547201, |
|
| 151 | - 'time' => 300, |
|
| 152 | - 'time_window_start' => 46800, |
|
| 153 | - 'time_window_end' => 48600, |
|
| 154 | - ]; |
|
| 155 | - |
|
| 156 | - //endregion |
|
| 157 | - |
|
| 158 | - $parameters = [ |
|
| 159 | - 'device_type' => DeviceType::IPAD, |
|
| 160 | - 'disable_optimization' => false, |
|
| 161 | - 'route_name' => 'phpunit test '.date('Y-m-d H:i'), |
|
| 162 | - ]; |
|
| 163 | - |
|
| 164 | - $routeParameters = Route::fromArray([ |
|
| 165 | - 'parameters' => $parameters, |
|
| 166 | - 'addresses' => $addresses |
|
| 167 | - ]); |
|
| 168 | - |
|
| 169 | - $this->assertEquals(RouteParameters::fromArray($parameters), $routeParameters->parameters); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function testGetRoutes() |
|
| 173 | - { |
|
| 174 | - $params = new RouteParametersQuery(); |
|
| 175 | - |
|
| 176 | - $params->limit = 10; |
|
| 177 | - $params->offset = 0; |
|
| 178 | - |
|
| 179 | - $route = new Route(); |
|
| 180 | - |
|
| 181 | - $routeResults = $route->getRoutes($params->toArray()); |
|
| 182 | - |
|
| 183 | - $this->assertNotNull($routeResults); |
|
| 184 | - $this->assertTrue(is_array($routeResults)); |
|
| 185 | - $this->assertTrue(sizeof($routeResults)>0); |
|
| 186 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - public function testGetAllRoutesWithPagination() |
|
| 190 | - { |
|
| 191 | - $params = new RouteParametersQuery(); |
|
| 192 | - |
|
| 193 | - $params->page = 1; |
|
| 194 | - $params->per_page = 10; |
|
| 195 | - |
|
| 196 | - $route = new Route(); |
|
| 197 | - |
|
| 198 | - $routeResults = $route->getAllRoutesWithPagination($params->toArray()); |
|
| 199 | - |
|
| 200 | - $this->assertNotNull($routeResults); |
|
| 201 | - $this->assertTrue(is_array($routeResults)); |
|
| 202 | - $this->assertTrue(sizeof($routeResults)>0); |
|
| 203 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - public function testGetPaginatedRouteListWithoutElasticSearch() |
|
| 207 | - { |
|
| 208 | - $params = new RouteParametersQuery(); |
|
| 209 | - |
|
| 210 | - $params->page = 1; |
|
| 211 | - $params->per_page = 10; |
|
| 212 | - |
|
| 213 | - $route = new Route(); |
|
| 214 | - |
|
| 215 | - $routeResults = $route->getPaginatedRouteListWithoutElasticSearch($params->toArray()); |
|
| 216 | - |
|
| 217 | - $this->assertNotNull($routeResults); |
|
| 218 | - $this->assertTrue(is_array($routeResults)); |
|
| 219 | - $this->assertTrue(sizeof($routeResults)>0); |
|
| 220 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - public function testGetRouteDataTableWithoutElasticSearch() |
|
| 224 | - { |
|
| 225 | - $scheduleFilter = new RouteFilterParametersFilters(); |
|
| 226 | - |
|
| 227 | - $scheduleFilter->schedule_date = [ |
|
| 228 | - date('Y-m-d', strtotime('-2 days')), |
|
| 229 | - date('Y-m-d', strtotime('-3 days')), |
|
| 230 | - date('Y-m-d', strtotime('-4 days')) |
|
| 231 | - ]; |
|
| 232 | - |
|
| 233 | - $filterParams = new RouteFilterParameters(); |
|
| 234 | - $filterParams->page = 1; |
|
| 235 | - $filterParams->per_page = 20; |
|
| 236 | - $filterParams->filters = $scheduleFilter; |
|
| 237 | - $filterParams->order_by = [["route_created_unix", "desc"]]; |
|
| 238 | - $filterParams->timezone = "UTC"; |
|
| 239 | - |
|
| 240 | - $route = new Route(); |
|
| 30 | + public static $createdProblems = []; |
|
| 31 | + public static $testRoutes = []; |
|
| 32 | + public static $addresses = []; |
|
| 33 | + |
|
| 34 | + public static $removedOptimizationIDs = []; |
|
| 35 | + public static $removedRouteIDs = []; |
|
| 36 | + |
|
| 37 | + public static function setUpBeforeClass() |
|
| 38 | + { |
|
| 39 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 40 | + |
|
| 41 | + //region -- Prepae Addresses -- |
|
| 42 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); |
|
| 43 | + |
|
| 44 | + $addresses = []; |
|
| 45 | + foreach ($json as $address) { |
|
| 46 | + $addresses[] = Address::fromArray($address); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $parameters = RouteParameters::fromArray([ |
|
| 50 | + 'algorithm_type' => AlgorithmType::CVRP_TW_MD, |
|
| 51 | + 'distance_unit' => DistanceUnit::MILES, |
|
| 52 | + 'device_type' => DeviceType::WEB, |
|
| 53 | + 'optimize' => OptimizationType::DISTANCE, |
|
| 54 | + 'metric' => Metric::GEODESIC, |
|
| 55 | + 'route_max_duration' => 86400 * 2, |
|
| 56 | + 'travel_mode' => TravelMode::DRIVING, |
|
| 57 | + 'vehicle_capacity' => 50, |
|
| 58 | + 'vehicle_max_distance_mi' => 10000, |
|
| 59 | + 'parts' => 50, |
|
| 60 | + ]); |
|
| 61 | + //endregion |
|
| 62 | + |
|
| 63 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 64 | + $optimizationParameters->setAddresses($addresses); |
|
| 65 | + $optimizationParameters->setParameters($parameters); |
|
| 66 | + |
|
| 67 | + self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); |
|
| 68 | + |
|
| 69 | + self::$testRoutes = self::$createdProblems[0]->routes; |
|
| 70 | + |
|
| 71 | + //region -- Extra Testing Addresses -- |
|
| 72 | + $addresses = []; |
|
| 73 | + $addresses[] = Address::fromArray([ |
|
| 74 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 75 | + 'is_depot' => true, |
|
| 76 | + 'lat' => 30.159341812134, |
|
| 77 | + 'lng' => -81.538619995117, |
|
| 78 | + 'time' => 300, |
|
| 79 | + 'time_window_start' => 28800, |
|
| 80 | + 'time_window_end' => 32400, |
|
| 81 | + ]); |
|
| 82 | + |
|
| 83 | + $addresses[] = Address::fromArray([ |
|
| 84 | + 'address' => '214 Edgewater Branch Drive 32259', |
|
| 85 | + 'lat' => 30.103567123413, |
|
| 86 | + 'lng' => -81.595352172852, |
|
| 87 | + 'time' => 300, |
|
| 88 | + 'time_window_start' => 36000, |
|
| 89 | + 'time_window_end' => 37200, |
|
| 90 | + ]); |
|
| 91 | + |
|
| 92 | + $addresses[] = Address::fromArray([ |
|
| 93 | + 'address' => '756 eagle point dr 32092', |
|
| 94 | + 'lat' => 30.046422958374, |
|
| 95 | + 'lng' => -81.508758544922, |
|
| 96 | + 'time' => 300, |
|
| 97 | + 'time_window_start' => 39600, |
|
| 98 | + 'time_window_end' => 41400, |
|
| 99 | + ]); |
|
| 100 | + //endregion |
|
| 101 | + |
|
| 102 | + self::$addresses = $addresses; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function testFromArray() |
|
| 106 | + { |
|
| 107 | + //region -- Prepare Addresses -- |
|
| 108 | + |
|
| 109 | + $addresses = []; |
|
| 110 | + $addresses[] = [ |
|
| 111 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 112 | + 'is_depot' => true, |
|
| 113 | + 'lat' => 30.159341812134, |
|
| 114 | + 'lng' => -81.538619995117, |
|
| 115 | + 'time' => 300, |
|
| 116 | + 'time_window_start' => 28800, |
|
| 117 | + 'time_window_end' => 32400, |
|
| 118 | + ]; |
|
| 119 | + |
|
| 120 | + $addresses[] = [ |
|
| 121 | + 'address' => '214 Edgewater Branch Drive 32259', |
|
| 122 | + 'lat' => 30.103567123413, |
|
| 123 | + 'lng' => -81.595352172852, |
|
| 124 | + 'time' => 300, |
|
| 125 | + 'time_window_start' => 36000, |
|
| 126 | + 'time_window_end' => 37200, |
|
| 127 | + ]; |
|
| 128 | + |
|
| 129 | + $addresses[] = [ |
|
| 130 | + 'address' => '756 eagle point dr 32092', |
|
| 131 | + 'lat' => 30.046422958374, |
|
| 132 | + 'lng' => -81.508758544922, |
|
| 133 | + 'time' => 300, |
|
| 134 | + 'time_window_start' => 39600, |
|
| 135 | + 'time_window_end' => 41400, |
|
| 136 | + ]; |
|
| 137 | + |
|
| 138 | + $addresses[] = [ |
|
| 139 | + 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', |
|
| 140 | + 'lat' => 30.048496, |
|
| 141 | + 'lng' => -81.558716, |
|
| 142 | + 'time' => 300, |
|
| 143 | + 'time_window_start' => 43200, |
|
| 144 | + 'time_window_end' => 45000, |
|
| 145 | + ]; |
|
| 146 | + |
|
| 147 | + $addresses[] = [ |
|
| 148 | + 'address' => 'St Johns Florida 32259, USA', |
|
| 149 | + 'lat' => 30.099642, |
|
| 150 | + 'lng' => -81.547201, |
|
| 151 | + 'time' => 300, |
|
| 152 | + 'time_window_start' => 46800, |
|
| 153 | + 'time_window_end' => 48600, |
|
| 154 | + ]; |
|
| 155 | + |
|
| 156 | + //endregion |
|
| 157 | + |
|
| 158 | + $parameters = [ |
|
| 159 | + 'device_type' => DeviceType::IPAD, |
|
| 160 | + 'disable_optimization' => false, |
|
| 161 | + 'route_name' => 'phpunit test '.date('Y-m-d H:i'), |
|
| 162 | + ]; |
|
| 163 | + |
|
| 164 | + $routeParameters = Route::fromArray([ |
|
| 165 | + 'parameters' => $parameters, |
|
| 166 | + 'addresses' => $addresses |
|
| 167 | + ]); |
|
| 168 | + |
|
| 169 | + $this->assertEquals(RouteParameters::fromArray($parameters), $routeParameters->parameters); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function testGetRoutes() |
|
| 173 | + { |
|
| 174 | + $params = new RouteParametersQuery(); |
|
| 175 | + |
|
| 176 | + $params->limit = 10; |
|
| 177 | + $params->offset = 0; |
|
| 178 | + |
|
| 179 | + $route = new Route(); |
|
| 180 | + |
|
| 181 | + $routeResults = $route->getRoutes($params->toArray()); |
|
| 182 | + |
|
| 183 | + $this->assertNotNull($routeResults); |
|
| 184 | + $this->assertTrue(is_array($routeResults)); |
|
| 185 | + $this->assertTrue(sizeof($routeResults)>0); |
|
| 186 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + public function testGetAllRoutesWithPagination() |
|
| 190 | + { |
|
| 191 | + $params = new RouteParametersQuery(); |
|
| 192 | + |
|
| 193 | + $params->page = 1; |
|
| 194 | + $params->per_page = 10; |
|
| 195 | + |
|
| 196 | + $route = new Route(); |
|
| 197 | + |
|
| 198 | + $routeResults = $route->getAllRoutesWithPagination($params->toArray()); |
|
| 199 | + |
|
| 200 | + $this->assertNotNull($routeResults); |
|
| 201 | + $this->assertTrue(is_array($routeResults)); |
|
| 202 | + $this->assertTrue(sizeof($routeResults)>0); |
|
| 203 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + public function testGetPaginatedRouteListWithoutElasticSearch() |
|
| 207 | + { |
|
| 208 | + $params = new RouteParametersQuery(); |
|
| 209 | + |
|
| 210 | + $params->page = 1; |
|
| 211 | + $params->per_page = 10; |
|
| 212 | + |
|
| 213 | + $route = new Route(); |
|
| 214 | + |
|
| 215 | + $routeResults = $route->getPaginatedRouteListWithoutElasticSearch($params->toArray()); |
|
| 216 | + |
|
| 217 | + $this->assertNotNull($routeResults); |
|
| 218 | + $this->assertTrue(is_array($routeResults)); |
|
| 219 | + $this->assertTrue(sizeof($routeResults)>0); |
|
| 220 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + public function testGetRouteDataTableWithoutElasticSearch() |
|
| 224 | + { |
|
| 225 | + $scheduleFilter = new RouteFilterParametersFilters(); |
|
| 226 | + |
|
| 227 | + $scheduleFilter->schedule_date = [ |
|
| 228 | + date('Y-m-d', strtotime('-2 days')), |
|
| 229 | + date('Y-m-d', strtotime('-3 days')), |
|
| 230 | + date('Y-m-d', strtotime('-4 days')) |
|
| 231 | + ]; |
|
| 232 | + |
|
| 233 | + $filterParams = new RouteFilterParameters(); |
|
| 234 | + $filterParams->page = 1; |
|
| 235 | + $filterParams->per_page = 20; |
|
| 236 | + $filterParams->filters = $scheduleFilter; |
|
| 237 | + $filterParams->order_by = [["route_created_unix", "desc"]]; |
|
| 238 | + $filterParams->timezone = "UTC"; |
|
| 239 | + |
|
| 240 | + $route = new Route(); |
|
| 241 | 241 | |
| 242 | - $routeResults = $route->getRouteDataTableWithoutElasticSearch($filterParams->toArray()); |
|
| 242 | + $routeResults = $route->getRouteDataTableWithoutElasticSearch($filterParams->toArray()); |
|
| 243 | 243 | |
| 244 | - $this->assertNotNull($routeResults); |
|
| 245 | - $this->assertTrue(is_array($routeResults)); |
|
| 246 | - $this->assertTrue(sizeof($routeResults)>0); |
|
| 247 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 248 | - } |
|
| 244 | + $this->assertNotNull($routeResults); |
|
| 245 | + $this->assertTrue(is_array($routeResults)); |
|
| 246 | + $this->assertTrue(sizeof($routeResults)>0); |
|
| 247 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - public function testGetRouteDatatableWithElasticSearch() |
|
| 251 | - { |
|
| 252 | - $scheduleFilter = new RouteFilterParametersFilters(); |
|
| 250 | + public function testGetRouteDatatableWithElasticSearch() |
|
| 251 | + { |
|
| 252 | + $scheduleFilter = new RouteFilterParametersFilters(); |
|
| 253 | 253 | |
| 254 | - $scheduleFilter->schedule_date = [ |
|
| 255 | - date('Y-m-d', strtotime('-1 days')), |
|
| 256 | - date('Y-m-d', strtotime('-2 days')), |
|
| 257 | - date('Y-m-d', strtotime('-3 days')) |
|
| 258 | - ]; |
|
| 254 | + $scheduleFilter->schedule_date = [ |
|
| 255 | + date('Y-m-d', strtotime('-1 days')), |
|
| 256 | + date('Y-m-d', strtotime('-2 days')), |
|
| 257 | + date('Y-m-d', strtotime('-3 days')) |
|
| 258 | + ]; |
|
| 259 | 259 | |
| 260 | - $filterParams = new RouteFilterParameters(); |
|
| 261 | - $filterParams->page = 1; |
|
| 262 | - $filterParams->per_page = 20; |
|
| 263 | - $filterParams->filters = $scheduleFilter; |
|
| 264 | - $filterParams->order_by = [["route_created_unix", "desc"]]; |
|
| 265 | - $filterParams->timezone = "UTC"; |
|
| 260 | + $filterParams = new RouteFilterParameters(); |
|
| 261 | + $filterParams->page = 1; |
|
| 262 | + $filterParams->per_page = 20; |
|
| 263 | + $filterParams->filters = $scheduleFilter; |
|
| 264 | + $filterParams->order_by = [["route_created_unix", "desc"]]; |
|
| 265 | + $filterParams->timezone = "UTC"; |
|
| 266 | 266 | |
| 267 | - $route = new Route(); |
|
| 267 | + $route = new Route(); |
|
| 268 | 268 | |
| 269 | - $routeResults = $route->getRouteDataTableWithElasticSearch($filterParams->toArray()); |
|
| 269 | + $routeResults = $route->getRouteDataTableWithElasticSearch($filterParams->toArray()); |
|
| 270 | 270 | |
| 271 | - $this->assertNotNull($routeResults); |
|
| 272 | - $this->assertTrue(is_array($routeResults)); |
|
| 273 | - $this->assertTrue(sizeof($routeResults)>0); |
|
| 274 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 275 | - } |
|
| 271 | + $this->assertNotNull($routeResults); |
|
| 272 | + $this->assertTrue(is_array($routeResults)); |
|
| 273 | + $this->assertTrue(sizeof($routeResults)>0); |
|
| 274 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - public function testGetRouteListWithoutElasticSearch() |
|
| 278 | - { |
|
| 279 | - $params = new RouteParametersQuery(); |
|
| 277 | + public function testGetRouteListWithoutElasticSearch() |
|
| 278 | + { |
|
| 279 | + $params = new RouteParametersQuery(); |
|
| 280 | 280 | |
| 281 | - $params->limit = 10; |
|
| 282 | - $params->offset = 0; |
|
| 281 | + $params->limit = 10; |
|
| 282 | + $params->offset = 0; |
|
| 283 | 283 | |
| 284 | - $route = new Route(); |
|
| 284 | + $route = new Route(); |
|
| 285 | 285 | |
| 286 | - $routeResults = $route->getRouteListWithoutElasticSearch($params->toArray()); |
|
| 286 | + $routeResults = $route->getRouteListWithoutElasticSearch($params->toArray()); |
|
| 287 | 287 | |
| 288 | - $this->assertNotNull($routeResults); |
|
| 289 | - $this->assertTrue(is_array($routeResults)); |
|
| 290 | - $this->assertTrue(sizeof($routeResults)>0); |
|
| 291 | - $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 292 | - } |
|
| 288 | + $this->assertNotNull($routeResults); |
|
| 289 | + $this->assertTrue(is_array($routeResults)); |
|
| 290 | + $this->assertTrue(sizeof($routeResults)>0); |
|
| 291 | + $this->assertInstanceOf(Route::class, Route::fromArray($routeResults)); |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - public function testDuplicateRoutes() |
|
| 295 | - { |
|
| 296 | - $routeIDs = [ |
|
| 297 | - self::$testRoutes[sizeof(self::$testRoutes) - 1]->route_id |
|
| 298 | - ]; |
|
| 294 | + public function testDuplicateRoutes() |
|
| 295 | + { |
|
| 296 | + $routeIDs = [ |
|
| 297 | + self::$testRoutes[sizeof(self::$testRoutes) - 1]->route_id |
|
| 298 | + ]; |
|
| 299 | 299 | |
| 300 | - $route = new Route(); |
|
| 300 | + $route = new Route(); |
|
| 301 | 301 | |
| 302 | - $result = $route->duplicateRoute($routeIDs); |
|
| 302 | + $result = $route->duplicateRoute($routeIDs); |
|
| 303 | 303 | |
| 304 | - $this->assertNotNull($result); |
|
| 305 | - $this->assertInstanceOf(RouteDuplicateResponse::class, RouteDuplicateResponse::fromArray( $result)); |
|
| 306 | - $this->assertTrue($result['status']); |
|
| 307 | - } |
|
| 304 | + $this->assertNotNull($result); |
|
| 305 | + $this->assertInstanceOf(RouteDuplicateResponse::class, RouteDuplicateResponse::fromArray( $result)); |
|
| 306 | + $this->assertTrue($result['status']); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - public function testGetRouteDataTableConfig() |
|
| 310 | - { |
|
| 311 | - $route = new Route(); |
|
| 309 | + public function testGetRouteDataTableConfig() |
|
| 310 | + { |
|
| 311 | + $route = new Route(); |
|
| 312 | 312 | |
| 313 | - $result = $route->getRouteDataTableConfig(); |
|
| 313 | + $result = $route->getRouteDataTableConfig(); |
|
| 314 | 314 | |
| 315 | - $this->assertNotNull($result); |
|
| 316 | - $this->assertInstanceOf( RouteDataTableConfigResponse::class, RouteDataTableConfigResponse::fromArray( $result)); |
|
| 317 | - $this->assertInstanceOf( ApiCapabilities::class, ApiCapabilities::fromArray( $result['api_capabilities'])); |
|
| 318 | - $this->assertInstanceOf( ApiPreferences::class, ApiPreferences::fromArray( $result['api_preferences'])); |
|
| 319 | - } |
|
| 315 | + $this->assertNotNull($result); |
|
| 316 | + $this->assertInstanceOf( RouteDataTableConfigResponse::class, RouteDataTableConfigResponse::fromArray( $result)); |
|
| 317 | + $this->assertInstanceOf( ApiCapabilities::class, ApiCapabilities::fromArray( $result['api_capabilities'])); |
|
| 318 | + $this->assertInstanceOf( ApiPreferences::class, ApiPreferences::fromArray( $result['api_preferences'])); |
|
| 319 | + } |
|
| 320 | 320 | |
| 321 | - public function testRouteDataTableFallbackConfig() |
|
| 322 | - { |
|
| 323 | - $route = new Route(); |
|
| 321 | + public function testRouteDataTableFallbackConfig() |
|
| 322 | + { |
|
| 323 | + $route = new Route(); |
|
| 324 | 324 | |
| 325 | - $result = $route->getRouteDataTableFallbackConfig(); |
|
| 325 | + $result = $route->getRouteDataTableFallbackConfig(); |
|
| 326 | 326 | |
| 327 | - $this->assertNotNull($result); |
|
| 328 | - $this->assertInstanceOf( RouteDataTableConfigResponse::class, RouteDataTableConfigResponse::fromArray( $result)); |
|
| 329 | - $this->assertInstanceOf( ApiCapabilities::class, ApiCapabilities::fromArray( $result['api_capabilities'])); |
|
| 330 | - $this->assertInstanceOf( ApiPreferences::class, ApiPreferences::fromArray( $result['api_preferences'])); |
|
| 331 | - } |
|
| 327 | + $this->assertNotNull($result); |
|
| 328 | + $this->assertInstanceOf( RouteDataTableConfigResponse::class, RouteDataTableConfigResponse::fromArray( $result)); |
|
| 329 | + $this->assertInstanceOf( ApiCapabilities::class, ApiCapabilities::fromArray( $result['api_capabilities'])); |
|
| 330 | + $this->assertInstanceOf( ApiPreferences::class, ApiPreferences::fromArray( $result['api_preferences'])); |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - public function testUpdateRouteParameters() |
|
| 334 | - { |
|
| 335 | - $routeQueryParams= new RouteParametersQuery(); |
|
| 336 | - $routeQueryParams->route_id = self::$testRoutes[sizeof(self::$testRoutes) - 1]->route_id; |
|
| 337 | - $routeQueryParams->original = 0; |
|
| 333 | + public function testUpdateRouteParameters() |
|
| 334 | + { |
|
| 335 | + $routeQueryParams= new RouteParametersQuery(); |
|
| 336 | + $routeQueryParams->route_id = self::$testRoutes[sizeof(self::$testRoutes) - 1]->route_id; |
|
| 337 | + $routeQueryParams->original = 0; |
|
| 338 | 338 | |
| 339 | - $routeParams = new RouteParameters(); |
|
| 339 | + $routeParams = new RouteParameters(); |
|
| 340 | 340 | |
| 341 | - $routeParams->disable_optimization = false; |
|
| 342 | - $routeParams->vehicle_capacity = 9800; |
|
| 343 | - $routeParams->target_duration = 0; |
|
| 344 | - $routeParams->target_distance = 100; |
|
| 345 | - $routeParams->target_wait_by_tail_size = 0; |
|
| 341 | + $routeParams->disable_optimization = false; |
|
| 342 | + $routeParams->vehicle_capacity = 9800; |
|
| 343 | + $routeParams->target_duration = 0; |
|
| 344 | + $routeParams->target_distance = 100; |
|
| 345 | + $routeParams->target_wait_by_tail_size = 0; |
|
| 346 | 346 | |
| 347 | - $route = new Route(); |
|
| 347 | + $route = new Route(); |
|
| 348 | 348 | |
| 349 | - $result = $route->updateRouteParameters($routeQueryParams->toArray(), $routeParams->toArray()); |
|
| 349 | + $result = $route->updateRouteParameters($routeQueryParams->toArray(), $routeParams->toArray()); |
|
| 350 | 350 | |
| 351 | - $this->assertNotNull($result); |
|
| 352 | - $this->assertInstanceOf( Route::class, Route::fromArray( $result)); |
|
| 353 | - } |
|
| 351 | + $this->assertNotNull($result); |
|
| 352 | + $this->assertInstanceOf( Route::class, Route::fromArray( $result)); |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - public function testDeleteRoutes() |
|
| 356 | - { |
|
| 357 | - $routeToDeleteID = self::$testRoutes[sizeof(self::$testRoutes) - 1]->route_id; |
|
| 355 | + public function testDeleteRoutes() |
|
| 356 | + { |
|
| 357 | + $routeToDeleteID = self::$testRoutes[sizeof(self::$testRoutes) - 1]->route_id; |
|
| 358 | 358 | |
| 359 | - $routeIDs = [ $routeToDeleteID ]; |
|
| 359 | + $routeIDs = [ $routeToDeleteID ]; |
|
| 360 | 360 | |
| 361 | - $route = new Route(); |
|
| 361 | + $route = new Route(); |
|
| 362 | 362 | |
| 363 | - $result = $route->deleteRoutes($routeIDs); |
|
| 363 | + $result = $route->deleteRoutes($routeIDs); |
|
| 364 | 364 | |
| 365 | - $this->assertNotNull($result); |
|
| 366 | - $this->assertInstanceOf(RoutesDeleteResponse::class, RoutesDeleteResponse::fromArray( $result)); |
|
| 367 | - $this->assertTrue($result['deleted']); |
|
| 365 | + $this->assertNotNull($result); |
|
| 366 | + $this->assertInstanceOf(RoutesDeleteResponse::class, RoutesDeleteResponse::fromArray( $result)); |
|
| 367 | + $this->assertTrue($result['deleted']); |
|
| 368 | 368 | |
| 369 | - self::$testRoutes = array_pop(self::$testRoutes); |
|
| 370 | - } |
|
| 369 | + self::$testRoutes = array_pop(self::$testRoutes); |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | - public static function tearDownAfterClass() |
|
| 373 | - { |
|
| 374 | - if (sizeof(self::$createdProblems)>0) { |
|
| 375 | - $optimizationProblemIDs = []; |
|
| 372 | + public static function tearDownAfterClass() |
|
| 373 | + { |
|
| 374 | + if (sizeof(self::$createdProblems)>0) { |
|
| 375 | + $optimizationProblemIDs = []; |
|
| 376 | 376 | |
| 377 | - foreach (self::$createdProblems as $problem) { |
|
| 378 | - $optimizationProblemId = $problem->optimization_problem_id; |
|
| 377 | + foreach (self::$createdProblems as $problem) { |
|
| 378 | + $optimizationProblemId = $problem->optimization_problem_id; |
|
| 379 | 379 | |
| 380 | - $optimizationProblemIDs[] = $optimizationProblemId; |
|
| 381 | - } |
|
| 380 | + $optimizationProblemIDs[] = $optimizationProblemId; |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - if (sizeof(self::$removedOptimizationIDs)>0) { |
|
| 384 | - $optimizationProblemIDs = array_merge($optimizationProblemIDs,self::$removedOptimizationIDs); |
|
| 385 | - } |
|
| 383 | + if (sizeof(self::$removedOptimizationIDs)>0) { |
|
| 384 | + $optimizationProblemIDs = array_merge($optimizationProblemIDs,self::$removedOptimizationIDs); |
|
| 385 | + } |
|
| 386 | 386 | |
| 387 | - $params = [ |
|
| 388 | - 'optimization_problem_ids' => $optimizationProblemIDs, |
|
| 389 | - 'redirect' => 0, |
|
| 390 | - ]; |
|
| 387 | + $params = [ |
|
| 388 | + 'optimization_problem_ids' => $optimizationProblemIDs, |
|
| 389 | + 'redirect' => 0, |
|
| 390 | + ]; |
|
| 391 | 391 | |
| 392 | - $problem = new OptimizationProblem(); |
|
| 393 | - $result = $problem->removeOptimization($params); |
|
| 392 | + $problem = new OptimizationProblem(); |
|
| 393 | + $result = $problem->removeOptimization($params); |
|
| 394 | 394 | |
| 395 | - if ($result!=null && $result['status']==true) { |
|
| 396 | - echo "The test optimizations were removed <br>"; |
|
| 397 | - } else { |
|
| 398 | - echo "Cannot remove the test optimizations <br>"; |
|
| 399 | - } |
|
| 400 | - } |
|
| 395 | + if ($result!=null && $result['status']==true) { |
|
| 396 | + echo "The test optimizations were removed <br>"; |
|
| 397 | + } else { |
|
| 398 | + echo "Cannot remove the test optimizations <br>"; |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | 401 | |
| 402 | - if (sizeof(self::$removedRouteIDs)>0) { |
|
| 403 | - $route = new Route(); |
|
| 402 | + if (sizeof(self::$removedRouteIDs)>0) { |
|
| 403 | + $route = new Route(); |
|
| 404 | 404 | |
| 405 | - $route_ids = join(',', self::$removedRouteIDs); |
|
| 405 | + $route_ids = join(',', self::$removedRouteIDs); |
|
| 406 | 406 | |
| 407 | - $result = $route->deleteRoutes($route_ids); |
|
| 407 | + $result = $route->deleteRoutes($route_ids); |
|
| 408 | 408 | |
| 409 | - if ($result!=null && $result['deleted']==true) { |
|
| 410 | - echo "The test routes were removed <br>"; |
|
| 411 | - } else { |
|
| 412 | - echo "Cannot remove the test routes <br>"; |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - } |
|
| 409 | + if ($result!=null && $result['deleted']==true) { |
|
| 410 | + echo "The test routes were removed <br>"; |
|
| 411 | + } else { |
|
| 412 | + echo "Cannot remove the test routes <br>"; |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | 417 | } |
| 418 | 418 | \ No newline at end of file |
@@ -6,21 +6,21 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CustomNoteTypeUnitTests extends \PHPUnit\Framework\TestCase |
| 8 | 8 | { |
| 9 | - public function testFromArray() |
|
| 10 | - { |
|
| 11 | - $customNoteType = CustomNoteType::fromArray([ |
|
| 12 | - 'note_custom_entry_id' => 'ABCBA1228FA18888DBEECBFA2DA7777C850E15CA', |
|
| 13 | - 'note_id' => '3237302', |
|
| 14 | - 'note_custom_type_id' => '10', |
|
| 15 | - 'note_custom_value' => 'Backdoor', |
|
| 16 | - 'note_custom_type' => 'Dropoff Location' |
|
| 17 | - ]); |
|
| 9 | + public function testFromArray() |
|
| 10 | + { |
|
| 11 | + $customNoteType = CustomNoteType::fromArray([ |
|
| 12 | + 'note_custom_entry_id' => 'ABCBA1228FA18888DBEECBFA2DA7777C850E15CA', |
|
| 13 | + 'note_id' => '3237302', |
|
| 14 | + 'note_custom_type_id' => '10', |
|
| 15 | + 'note_custom_value' => 'Backdoor', |
|
| 16 | + 'note_custom_type' => 'Dropoff Location' |
|
| 17 | + ]); |
|
| 18 | 18 | |
| 19 | - $this->assertEquals('ABCBA1228FA18888DBEECBFA2DA7777C850E15CA', $customNoteType->note_custom_entry_id); |
|
| 20 | - $this->assertEquals('3237302', $customNoteType->note_id); |
|
| 21 | - $this->assertEquals('10', $customNoteType->note_custom_type_id); |
|
| 22 | - $this->assertEquals('Backdoor', $customNoteType->note_custom_value); |
|
| 23 | - $this->assertEquals('Dropoff Location', $customNoteType->note_custom_type); |
|
| 24 | - } |
|
| 19 | + $this->assertEquals('ABCBA1228FA18888DBEECBFA2DA7777C850E15CA', $customNoteType->note_custom_entry_id); |
|
| 20 | + $this->assertEquals('3237302', $customNoteType->note_id); |
|
| 21 | + $this->assertEquals('10', $customNoteType->note_custom_type_id); |
|
| 22 | + $this->assertEquals('Backdoor', $customNoteType->note_custom_value); |
|
| 23 | + $this->assertEquals('Dropoff Location', $customNoteType->note_custom_type); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -8,202 +8,202 @@ |
||
| 8 | 8 | use Route4Me\Route4Me; |
| 9 | 9 | |
| 10 | 10 | class AvoidanceZoneUnitTests extends \PHPUnit\Framework\TestCase { |
| 11 | - protected $avoidanceZone; |
|
| 12 | - protected $createdAvoidanceZones; |
|
| 13 | - |
|
| 14 | - public function setUp() |
|
| 15 | - { |
|
| 16 | - $this->avoidanceZone = new AvoidanceZone(); |
|
| 17 | - |
|
| 18 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 19 | - |
|
| 20 | - $createdAvoidanceZones = []; |
|
| 21 | - |
|
| 22 | - $rectTerritoryParams['type'] = TerritoryTypes::RECT; |
|
| 23 | - $rectTerritoryParams['data'] = [ |
|
| 24 | - '43.51668853502909,-109.3798828125', |
|
| 25 | - '46.98025235521883,-101.865234375', |
|
| 26 | - ]; |
|
| 27 | - |
|
| 28 | - $AvoidanceZoneParameters = AvoidanceZone::fromArray([ |
|
| 29 | - 'territory_name' => 'Test Rectangular Avoidance Zone '.strval(rand(10000, 99999)), |
|
| 30 | - 'territory_color' => 'ff7700', |
|
| 31 | - 'territory' => $rectTerritoryParams, |
|
| 32 | - ]); |
|
| 33 | - |
|
| 34 | - $rectAvoidanceZone = AvoidanceZone::fromArray( |
|
| 35 | - AvoidanceZone::addAvoidanceZone($AvoidanceZoneParameters) |
|
| 36 | - ); |
|
| 37 | - |
|
| 38 | - $this->createdAvoidanceZones[] = $rectAvoidanceZone; |
|
| 39 | - |
|
| 40 | - $circleTerritoryParams['type'] = TerritoryTypes::CIRCLE; |
|
| 41 | - $circleTerritoryParams['data'] = [ |
|
| 42 | - '37.569752822786455,-77.47833251953125', |
|
| 43 | - '5000', |
|
| 44 | - ]; |
|
| 45 | - |
|
| 46 | - $AvoidanceZoneParameters = AvoidanceZone::fromArray([ |
|
| 47 | - 'territory_name' => 'Test Rectangular Avoidance Zone '.strval(rand(10000, 99999)), |
|
| 48 | - 'territory_color' => 'ff7700', |
|
| 49 | - 'territory' => $circleTerritoryParams, |
|
| 50 | - ]); |
|
| 51 | - |
|
| 52 | - $circleAvoidanceZone = AvoidanceZone::fromArray( |
|
| 53 | - AvoidanceZone::addAvoidanceZone($AvoidanceZoneParameters) |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - $this->createdAvoidanceZones[] = $circleAvoidanceZone; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function testFromArray() |
|
| 60 | - { |
|
| 61 | - $circleTerritoryParams['type'] = TerritoryTypes::CIRCLE; |
|
| 62 | - $circleTerritoryParams['data'] = [ |
|
| 63 | - '37.569752822786455,-77.47833251953125', |
|
| 64 | - '5000', |
|
| 65 | - ]; |
|
| 66 | - |
|
| 67 | - $avoidanceZone = AvoidanceZone::fromArray([ |
|
| 68 | - 'territory_name' => "Rect Territory Name", |
|
| 69 | - 'territory_color' => "ff0000", |
|
| 70 | - 'territory' => $circleTerritoryParams |
|
| 71 | - ]); |
|
| 72 | - |
|
| 73 | - $this->assertEquals($avoidanceZone->territory_name, "Rect Territory Name"); |
|
| 74 | - $this->assertEquals($avoidanceZone->territory_color, "ff0000"); |
|
| 75 | - $this->assertEquals($avoidanceZone->territory['type'], TerritoryTypes::CIRCLE); |
|
| 76 | - $this->assertEquals($avoidanceZone->territory['data'], [ |
|
| 77 | - '37.569752822786455,-77.47833251953125', |
|
| 78 | - '5000', |
|
| 79 | - ]); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function testToArray() |
|
| 83 | - { |
|
| 84 | - $rectTerritoryParams['type'] = TerritoryTypes::RECT; |
|
| 85 | - $rectTerritoryParams['data'] = [ |
|
| 86 | - '43.51668853502909,-109.3798828125', |
|
| 87 | - '46.98025235521883,-101.865234375', |
|
| 88 | - ]; |
|
| 89 | - |
|
| 90 | - $avoidanceZone = AvoidanceZone::fromArray([ |
|
| 91 | - 'territory_name' => "Rect Territory Name", |
|
| 92 | - 'territory_color' => "ff0000", |
|
| 93 | - 'territory' => $rectTerritoryParams |
|
| 94 | - ]); |
|
| 95 | - |
|
| 96 | - $this->assertEquals($avoidanceZone->toArray(), |
|
| 97 | - [ |
|
| 98 | - 'territory_name' => "Rect Territory Name", |
|
| 99 | - 'territory_color' => "ff0000", |
|
| 100 | - 'territory' => $rectTerritoryParams |
|
| 101 | - ] |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function testGetAvoidanceZones() |
|
| 106 | - { |
|
| 107 | - $avoidanceZones = AvoidanceZone::getAvoidanceZones([]); |
|
| 108 | - |
|
| 109 | - $this->assertNotNull($avoidanceZones); |
|
| 110 | - $this->assertTrue(is_array($avoidanceZones)); |
|
| 111 | - $first=AvoidanceZone::fromArray($avoidanceZones[0]); |
|
| 112 | - $this->assertContainsOnlyInstancesOf('Route4Me\AvoidanceZone', [$first]); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function testGetAvoidanceZone() |
|
| 116 | - { |
|
| 117 | - $avoidanceZones = AvoidanceZone::getAvoidanceZones([]); |
|
| 118 | - |
|
| 119 | - $avoidanceZoneId = $avoidanceZones[0]['territory_id']; |
|
| 120 | - $this->assertNotNull($avoidanceZoneId); |
|
| 121 | - |
|
| 122 | - $avoidanceZone = AvoidanceZone::fromArray(AvoidanceZone::getAvoidanceZone($avoidanceZoneId)); |
|
| 123 | - |
|
| 124 | - $this->assertNotNull($avoidanceZone); |
|
| 125 | - $this->assertContainsOnlyInstancesOf('Route4Me\AvoidanceZone', [$avoidanceZone]); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function testAddAvoidanceZone() |
|
| 129 | - { |
|
| 130 | - $polyTerritoryParams['type'] = TerritoryTypes::POLY; |
|
| 131 | - $polyTerritoryParams['data'] = [ |
|
| 132 | - '37.769752822786455,-77.67833251953125', |
|
| 133 | - '37.75886716305343,-77.68974800109863', |
|
| 134 | - '37.74763966054455,-77.6917221069336', |
|
| 135 | - '37.74655084306813,-77.68863220214844', |
|
| 136 | - '37.7502255383101,-77.68125076293945', |
|
| 137 | - '37.74797991274437,-77.67498512268066', |
|
| 138 | - '37.73327960206065,-77.6411678314209', |
|
| 139 | - '37.74430510679532,-77.63172645568848', |
|
| 140 | - '37.76641925847049,-77.66846199035645', |
|
| 141 | - ]; |
|
| 142 | - |
|
| 143 | - $AvoidanceZoneParameters = AvoidanceZone::fromArray([ |
|
| 144 | - 'territory_name' => 'Test Rectangular Avoidance Zone '.strval(rand(10000, 99999)), |
|
| 145 | - 'territory_color' => 'ff7700', |
|
| 146 | - 'territory' => $polyTerritoryParams, |
|
| 147 | - ]); |
|
| 148 | - |
|
| 149 | - $polyAvoidanceZone = AvoidanceZone::fromArray( |
|
| 150 | - AvoidanceZone::addAvoidanceZone($AvoidanceZoneParameters) |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - $this->createdAvoidanceZones[] = $polyAvoidanceZone; |
|
| 154 | - |
|
| 155 | - $this->assertNotNull($polyAvoidanceZone); |
|
| 156 | - $this->assertContainsOnlyInstancesOf('Route4Me\AvoidanceZone', [$polyAvoidanceZone]); |
|
| 157 | - $this->assertEquals(TerritoryTypes::POLY, $polyAvoidanceZone->territory['type']); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - public function testDeleteAvoidanceZone() |
|
| 161 | - { |
|
| 162 | - $territoryId = $this->createdAvoidanceZones[sizeof($this->createdAvoidanceZones)-1]->territory_id; |
|
| 163 | - $result = $this->avoidanceZone->deleteAvoidanceZone($territoryId); |
|
| 164 | - //$result = AvoidanceZone::deleteAvoidanceZone($territoryId); |
|
| 165 | - |
|
| 166 | - $this->assertNotNull($result); |
|
| 167 | - $this->assertTrue($result['status']); |
|
| 168 | - |
|
| 169 | - $this->createdAvoidanceZones[] = array_pop($this->createdAvoidanceZones); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function testUpdateAvoidanceZone() |
|
| 173 | - { |
|
| 174 | - $territoryId = $this->createdAvoidanceZones[0]->territory_id; |
|
| 175 | - |
|
| 176 | - $avoidanceZoneParameters = [ |
|
| 177 | - 'territory_id' => $territoryId, |
|
| 178 | - 'territory_name' => 'Test Territory Updated', |
|
| 179 | - 'territory_color' => 'ff5500' |
|
| 180 | - ]; |
|
| 181 | - |
|
| 182 | - $updatedRoute = AvoidanceZone::fromArray( |
|
| 183 | - $this->avoidanceZone->updateAvoidanceZone($avoidanceZoneParameters) |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - $this->assertNotNull($updatedRoute); |
|
| 187 | - $this->assertContainsOnlyInstancesOf('Route4Me\AvoidanceZone', [$updatedRoute]); |
|
| 188 | - $this->assertEquals('Test Territory Updated',$updatedRoute->territory_name, "The territory name not updated"); |
|
| 189 | - $this->assertEquals('ff5500',$updatedRoute->territory_color, "The territory color not updated"); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - public function tearDown() |
|
| 193 | - { |
|
| 194 | - foreach ($this->createdAvoidanceZones as $avZone) |
|
| 195 | - { |
|
| 196 | - $territoryId = $avZone->territory_id; |
|
| 197 | - |
|
| 198 | - $result = $this->avoidanceZone->deleteAvoidanceZone($territoryId); |
|
| 199 | - |
|
| 200 | - if ($result==true) { |
|
| 201 | - echo "The test avoidance zone with territory_id=".$territoryId." removed. <br>"; |
|
| 202 | - } |
|
| 203 | - else { |
|
| 204 | - echo "Cannot remove the test avoidance zone with territory_id=".$territoryId."<br>"; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - } |
|
| 208 | - } |
|
| 11 | + protected $avoidanceZone; |
|
| 12 | + protected $createdAvoidanceZones; |
|
| 13 | + |
|
| 14 | + public function setUp() |
|
| 15 | + { |
|
| 16 | + $this->avoidanceZone = new AvoidanceZone(); |
|
| 17 | + |
|
| 18 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 19 | + |
|
| 20 | + $createdAvoidanceZones = []; |
|
| 21 | + |
|
| 22 | + $rectTerritoryParams['type'] = TerritoryTypes::RECT; |
|
| 23 | + $rectTerritoryParams['data'] = [ |
|
| 24 | + '43.51668853502909,-109.3798828125', |
|
| 25 | + '46.98025235521883,-101.865234375', |
|
| 26 | + ]; |
|
| 27 | + |
|
| 28 | + $AvoidanceZoneParameters = AvoidanceZone::fromArray([ |
|
| 29 | + 'territory_name' => 'Test Rectangular Avoidance Zone '.strval(rand(10000, 99999)), |
|
| 30 | + 'territory_color' => 'ff7700', |
|
| 31 | + 'territory' => $rectTerritoryParams, |
|
| 32 | + ]); |
|
| 33 | + |
|
| 34 | + $rectAvoidanceZone = AvoidanceZone::fromArray( |
|
| 35 | + AvoidanceZone::addAvoidanceZone($AvoidanceZoneParameters) |
|
| 36 | + ); |
|
| 37 | + |
|
| 38 | + $this->createdAvoidanceZones[] = $rectAvoidanceZone; |
|
| 39 | + |
|
| 40 | + $circleTerritoryParams['type'] = TerritoryTypes::CIRCLE; |
|
| 41 | + $circleTerritoryParams['data'] = [ |
|
| 42 | + '37.569752822786455,-77.47833251953125', |
|
| 43 | + '5000', |
|
| 44 | + ]; |
|
| 45 | + |
|
| 46 | + $AvoidanceZoneParameters = AvoidanceZone::fromArray([ |
|
| 47 | + 'territory_name' => 'Test Rectangular Avoidance Zone '.strval(rand(10000, 99999)), |
|
| 48 | + 'territory_color' => 'ff7700', |
|
| 49 | + 'territory' => $circleTerritoryParams, |
|
| 50 | + ]); |
|
| 51 | + |
|
| 52 | + $circleAvoidanceZone = AvoidanceZone::fromArray( |
|
| 53 | + AvoidanceZone::addAvoidanceZone($AvoidanceZoneParameters) |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + $this->createdAvoidanceZones[] = $circleAvoidanceZone; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function testFromArray() |
|
| 60 | + { |
|
| 61 | + $circleTerritoryParams['type'] = TerritoryTypes::CIRCLE; |
|
| 62 | + $circleTerritoryParams['data'] = [ |
|
| 63 | + '37.569752822786455,-77.47833251953125', |
|
| 64 | + '5000', |
|
| 65 | + ]; |
|
| 66 | + |
|
| 67 | + $avoidanceZone = AvoidanceZone::fromArray([ |
|
| 68 | + 'territory_name' => "Rect Territory Name", |
|
| 69 | + 'territory_color' => "ff0000", |
|
| 70 | + 'territory' => $circleTerritoryParams |
|
| 71 | + ]); |
|
| 72 | + |
|
| 73 | + $this->assertEquals($avoidanceZone->territory_name, "Rect Territory Name"); |
|
| 74 | + $this->assertEquals($avoidanceZone->territory_color, "ff0000"); |
|
| 75 | + $this->assertEquals($avoidanceZone->territory['type'], TerritoryTypes::CIRCLE); |
|
| 76 | + $this->assertEquals($avoidanceZone->territory['data'], [ |
|
| 77 | + '37.569752822786455,-77.47833251953125', |
|
| 78 | + '5000', |
|
| 79 | + ]); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function testToArray() |
|
| 83 | + { |
|
| 84 | + $rectTerritoryParams['type'] = TerritoryTypes::RECT; |
|
| 85 | + $rectTerritoryParams['data'] = [ |
|
| 86 | + '43.51668853502909,-109.3798828125', |
|
| 87 | + '46.98025235521883,-101.865234375', |
|
| 88 | + ]; |
|
| 89 | + |
|
| 90 | + $avoidanceZone = AvoidanceZone::fromArray([ |
|
| 91 | + 'territory_name' => "Rect Territory Name", |
|
| 92 | + 'territory_color' => "ff0000", |
|
| 93 | + 'territory' => $rectTerritoryParams |
|
| 94 | + ]); |
|
| 95 | + |
|
| 96 | + $this->assertEquals($avoidanceZone->toArray(), |
|
| 97 | + [ |
|
| 98 | + 'territory_name' => "Rect Territory Name", |
|
| 99 | + 'territory_color' => "ff0000", |
|
| 100 | + 'territory' => $rectTerritoryParams |
|
| 101 | + ] |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function testGetAvoidanceZones() |
|
| 106 | + { |
|
| 107 | + $avoidanceZones = AvoidanceZone::getAvoidanceZones([]); |
|
| 108 | + |
|
| 109 | + $this->assertNotNull($avoidanceZones); |
|
| 110 | + $this->assertTrue(is_array($avoidanceZones)); |
|
| 111 | + $first=AvoidanceZone::fromArray($avoidanceZones[0]); |
|
| 112 | + $this->assertContainsOnlyInstancesOf('Route4Me\AvoidanceZone', [$first]); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function testGetAvoidanceZone() |
|
| 116 | + { |
|
| 117 | + $avoidanceZones = AvoidanceZone::getAvoidanceZones([]); |
|
| 118 | + |
|
| 119 | + $avoidanceZoneId = $avoidanceZones[0]['territory_id']; |
|
| 120 | + $this->assertNotNull($avoidanceZoneId); |
|
| 121 | + |
|
| 122 | + $avoidanceZone = AvoidanceZone::fromArray(AvoidanceZone::getAvoidanceZone($avoidanceZoneId)); |
|
| 123 | + |
|
| 124 | + $this->assertNotNull($avoidanceZone); |
|
| 125 | + $this->assertContainsOnlyInstancesOf('Route4Me\AvoidanceZone', [$avoidanceZone]); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function testAddAvoidanceZone() |
|
| 129 | + { |
|
| 130 | + $polyTerritoryParams['type'] = TerritoryTypes::POLY; |
|
| 131 | + $polyTerritoryParams['data'] = [ |
|
| 132 | + '37.769752822786455,-77.67833251953125', |
|
| 133 | + '37.75886716305343,-77.68974800109863', |
|
| 134 | + '37.74763966054455,-77.6917221069336', |
|
| 135 | + '37.74655084306813,-77.68863220214844', |
|
| 136 | + '37.7502255383101,-77.68125076293945', |
|
| 137 | + '37.74797991274437,-77.67498512268066', |
|
| 138 | + '37.73327960206065,-77.6411678314209', |
|
| 139 | + '37.74430510679532,-77.63172645568848', |
|
| 140 | + '37.76641925847049,-77.66846199035645', |
|
| 141 | + ]; |
|
| 142 | + |
|
| 143 | + $AvoidanceZoneParameters = AvoidanceZone::fromArray([ |
|
| 144 | + 'territory_name' => 'Test Rectangular Avoidance Zone '.strval(rand(10000, 99999)), |
|
| 145 | + 'territory_color' => 'ff7700', |
|
| 146 | + 'territory' => $polyTerritoryParams, |
|
| 147 | + ]); |
|
| 148 | + |
|
| 149 | + $polyAvoidanceZone = AvoidanceZone::fromArray( |
|
| 150 | + AvoidanceZone::addAvoidanceZone($AvoidanceZoneParameters) |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + $this->createdAvoidanceZones[] = $polyAvoidanceZone; |
|
| 154 | + |
|
| 155 | + $this->assertNotNull($polyAvoidanceZone); |
|
| 156 | + $this->assertContainsOnlyInstancesOf('Route4Me\AvoidanceZone', [$polyAvoidanceZone]); |
|
| 157 | + $this->assertEquals(TerritoryTypes::POLY, $polyAvoidanceZone->territory['type']); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + public function testDeleteAvoidanceZone() |
|
| 161 | + { |
|
| 162 | + $territoryId = $this->createdAvoidanceZones[sizeof($this->createdAvoidanceZones)-1]->territory_id; |
|
| 163 | + $result = $this->avoidanceZone->deleteAvoidanceZone($territoryId); |
|
| 164 | + //$result = AvoidanceZone::deleteAvoidanceZone($territoryId); |
|
| 165 | + |
|
| 166 | + $this->assertNotNull($result); |
|
| 167 | + $this->assertTrue($result['status']); |
|
| 168 | + |
|
| 169 | + $this->createdAvoidanceZones[] = array_pop($this->createdAvoidanceZones); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function testUpdateAvoidanceZone() |
|
| 173 | + { |
|
| 174 | + $territoryId = $this->createdAvoidanceZones[0]->territory_id; |
|
| 175 | + |
|
| 176 | + $avoidanceZoneParameters = [ |
|
| 177 | + 'territory_id' => $territoryId, |
|
| 178 | + 'territory_name' => 'Test Territory Updated', |
|
| 179 | + 'territory_color' => 'ff5500' |
|
| 180 | + ]; |
|
| 181 | + |
|
| 182 | + $updatedRoute = AvoidanceZone::fromArray( |
|
| 183 | + $this->avoidanceZone->updateAvoidanceZone($avoidanceZoneParameters) |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + $this->assertNotNull($updatedRoute); |
|
| 187 | + $this->assertContainsOnlyInstancesOf('Route4Me\AvoidanceZone', [$updatedRoute]); |
|
| 188 | + $this->assertEquals('Test Territory Updated',$updatedRoute->territory_name, "The territory name not updated"); |
|
| 189 | + $this->assertEquals('ff5500',$updatedRoute->territory_color, "The territory color not updated"); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + public function tearDown() |
|
| 193 | + { |
|
| 194 | + foreach ($this->createdAvoidanceZones as $avZone) |
|
| 195 | + { |
|
| 196 | + $territoryId = $avZone->territory_id; |
|
| 197 | + |
|
| 198 | + $result = $this->avoidanceZone->deleteAvoidanceZone($territoryId); |
|
| 199 | + |
|
| 200 | + if ($result==true) { |
|
| 201 | + echo "The test avoidance zone with territory_id=".$territoryId." removed. <br>"; |
|
| 202 | + } |
|
| 203 | + else { |
|
| 204 | + echo "Cannot remove the test avoidance zone with territory_id=".$territoryId."<br>"; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | 209 | } |
@@ -12,447 +12,447 @@ |
||
| 12 | 12 | |
| 13 | 13 | class VehicleTests extends \PHPUnit\Framework\TestCase |
| 14 | 14 | { |
| 15 | - public static $createdVehicles=[]; |
|
| 16 | - |
|
| 17 | - public static function setUpBeforeClass() |
|
| 18 | - { |
|
| 19 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 20 | - |
|
| 21 | - $vehicle = new VehicleV4(); |
|
| 22 | - |
|
| 23 | - $vehicleParameters = Vehicle::fromArray([ |
|
| 24 | - 'vehicle_name' => 'Ford Transit Test 5', |
|
| 25 | - 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 26 | - 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 27 | - 'vehicle_reg_country_id' => '223', |
|
| 28 | - 'vehicle_make' => 'Ford', |
|
| 29 | - 'vehicle_model_year' => 2013, |
|
| 30 | - 'vehicle_axle_count' => 2, |
|
| 31 | - 'mpg_city' => 8, |
|
| 32 | - 'mpg_highway' => 14, |
|
| 33 | - 'fuel_type' => 'unleaded 93', |
|
| 34 | - 'height_inches' => 72, |
|
| 35 | - 'weight_lb' => 2000, |
|
| 36 | - ]); |
|
| 37 | - |
|
| 38 | - $result = $vehicle->createVehicle($vehicleParameters); |
|
| 39 | - |
|
| 40 | - self::assertNotNull($result); |
|
| 41 | - self::assertInstanceOf( |
|
| 42 | - VehicleV4::class, |
|
| 43 | - VehicleV4::fromArray($result) |
|
| 44 | - ); |
|
| 45 | - |
|
| 46 | - self::$createdVehicles[] = $result['vehicle_id']; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function testFromArray() |
|
| 50 | - { |
|
| 51 | - $vehicleParameters = VehicleV4::fromArray([ |
|
| 52 | - 'vehicle_id' => '43B1DC9C2C4DC3A8FE080A126B12ACBD', |
|
| 53 | - 'member_id' => 18154, |
|
| 54 | - 'is_deleted' => false, |
|
| 55 | - 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 56 | - 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 57 | - 'vehicle_reg_state_id' => null, |
|
| 58 | - 'vehicle_reg_country_id' => 223, |
|
| 59 | - 'vehicle_license_plate' => null, |
|
| 60 | - 'vehicle_type_id' => null, |
|
| 61 | - 'timestamp_added' => '2020-12-20T17:25:14+00:00', |
|
| 62 | - 'vehicle_make' => 'Ford', |
|
| 63 | - 'vehicle_model_year' => 2013, |
|
| 64 | - 'vehicle_model' => null, |
|
| 65 | - 'vehicle_year_acquired' => null, |
|
| 66 | - 'vehicle_cost_new' => null, |
|
| 67 | - 'purchased_new' => null, |
|
| 68 | - 'license_start_date' => '2020-12-20', |
|
| 69 | - 'license_end_date' => '2020-12-20', |
|
| 70 | - 'is_operational' => true, |
|
| 71 | - 'fuel_type' => 'unleaded 93', |
|
| 72 | - 'external_telematics_vehicle_id' => null, |
|
| 73 | - 'timestamp_removed' => null, |
|
| 74 | - 'vehicle_profile_id' => null, |
|
| 75 | - 'fuel_consumption_city' => '8', |
|
| 76 | - 'fuel_consumption_highway' => '14', |
|
| 77 | - 'fuel_consumption_city_unit' => 'mi\/l', |
|
| 78 | - 'fuel_consumption_highway_unit' => 'mi\/l', |
|
| 79 | - 'mpg_city' => 30.28, |
|
| 80 | - 'mpg_highway' => 53, |
|
| 81 | - 'fuel_consumption_city_uf_value' => '8 mi\/l', |
|
| 82 | - 'fuel_consumption_highway_uf_value' => '14 mi\/l' |
|
| 83 | - ]); |
|
| 84 | - |
|
| 85 | - $this->assertEquals('43B1DC9C2C4DC3A8FE080A126B12ACBD', $vehicleParameters->vehicle_id); |
|
| 86 | - $this->assertEquals(18154, $vehicleParameters->member_id); |
|
| 87 | - $this->assertEquals(false, $vehicleParameters->is_deleted); |
|
| 88 | - $this->assertEquals('Ford Transit Test 5', $vehicleParameters->vehicle_alias); |
|
| 89 | - $this->assertEquals('JS3TD62V1Y4107898', $vehicleParameters->vehicle_vin); |
|
| 90 | - $this->assertEquals(null, $vehicleParameters->vehicle_reg_state_id); |
|
| 91 | - $this->assertEquals(223, $vehicleParameters->vehicle_reg_country_id); |
|
| 92 | - $this->assertEquals(null, $vehicleParameters->vehicle_license_plate); |
|
| 93 | - $this->assertEquals(null, $vehicleParameters->vehicle_type_id); |
|
| 94 | - $this->assertEquals('2020-12-20T17:25:14+00:00', $vehicleParameters->timestamp_added); |
|
| 95 | - $this->assertEquals('Ford', $vehicleParameters->vehicle_make); |
|
| 96 | - $this->assertEquals(2013, $vehicleParameters->vehicle_model_year); |
|
| 97 | - $this->assertEquals(null, $vehicleParameters->vehicle_model); |
|
| 98 | - $this->assertEquals(null, $vehicleParameters->vehicle_year_acquired); |
|
| 99 | - $this->assertEquals(null, $vehicleParameters->vehicle_cost_new); |
|
| 100 | - $this->assertEquals(null, $vehicleParameters->purchased_new); |
|
| 101 | - $this->assertEquals('2020-12-20', $vehicleParameters->license_start_date); |
|
| 102 | - $this->assertEquals('2020-12-20', $vehicleParameters->license_end_date); |
|
| 103 | - $this->assertEquals(true, $vehicleParameters->is_operational); |
|
| 104 | - $this->assertEquals('unleaded 93', $vehicleParameters->fuel_type); |
|
| 105 | - $this->assertEquals(null, $vehicleParameters->external_telematics_vehicle_id); |
|
| 106 | - $this->assertEquals(null, $vehicleParameters->timestamp_removed); |
|
| 107 | - $this->assertEquals(null, $vehicleParameters->vehicle_profile_id); |
|
| 108 | - $this->assertEquals('8', $vehicleParameters->fuel_consumption_city); |
|
| 109 | - $this->assertEquals('14', $vehicleParameters->fuel_consumption_highway); |
|
| 110 | - $this->assertEquals('mi\/l', $vehicleParameters->fuel_consumption_city_unit); |
|
| 111 | - $this->assertEquals('mi\/l', $vehicleParameters->fuel_consumption_highway_unit); |
|
| 112 | - $this->assertEquals(30.28, $vehicleParameters->mpg_city); |
|
| 113 | - $this->assertEquals(53, $vehicleParameters->mpg_highway); |
|
| 114 | - $this->assertEquals('8 mi\/l', $vehicleParameters->fuel_consumption_city_uf_value); |
|
| 115 | - $this->assertEquals('14 mi\/l', $vehicleParameters->fuel_consumption_highway_uf_value); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - public function testToArray() |
|
| 119 | - { |
|
| 120 | - $vehicleParameters = VehicleV4::fromArray([ |
|
| 121 | - 'vehicle_id' => '43B1DC9C2C4DC3A8FE080A126B12ACBD', |
|
| 122 | - 'member_id' => 18154, |
|
| 123 | - 'is_deleted' => false, |
|
| 124 | - 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 125 | - 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 126 | - 'vehicle_reg_country_id' => 223, |
|
| 127 | - 'timestamp_added' => '2020-12-20T17:25:14+00:00', |
|
| 128 | - 'vehicle_make' => 'Ford', |
|
| 129 | - 'vehicle_model_year' => 2013, |
|
| 130 | - 'license_start_date' => '2020-12-20', |
|
| 131 | - 'license_end_date' => '2020-12-20', |
|
| 132 | - 'is_operational' => true, |
|
| 133 | - 'fuel_type' => 'unleaded 93', |
|
| 134 | - 'fuel_consumption_city' => '8', |
|
| 135 | - 'fuel_consumption_highway' => '14', |
|
| 136 | - 'fuel_consumption_city_unit' => 'mi\/l', |
|
| 137 | - 'fuel_consumption_highway_unit' => 'mi\/l', |
|
| 138 | - 'mpg_city' => 30.28, |
|
| 139 | - 'mpg_highway' => 53, |
|
| 140 | - 'fuel_consumption_city_uf_value' => '8 mi\/l', |
|
| 141 | - 'fuel_consumption_highway_uf_value' => '14 mi\/l' |
|
| 142 | - ]); |
|
| 143 | - |
|
| 144 | - $this->assertEquals($vehicleParameters->toArray(), |
|
| 145 | - [ |
|
| 146 | - 'vehicle_id' => '43B1DC9C2C4DC3A8FE080A126B12ACBD', |
|
| 147 | - 'member_id' => 18154, |
|
| 148 | - 'is_deleted' => false, |
|
| 149 | - 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 150 | - 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 151 | - 'vehicle_reg_country_id' => 223, |
|
| 152 | - 'timestamp_added' => '2020-12-20T17:25:14+00:00', |
|
| 153 | - 'vehicle_make' => 'Ford', |
|
| 154 | - 'vehicle_model_year' => 2013, |
|
| 155 | - 'license_start_date' => '2020-12-20', |
|
| 156 | - 'license_end_date' => '2020-12-20', |
|
| 157 | - 'is_operational' => true, |
|
| 158 | - 'fuel_type' => 'unleaded 93', |
|
| 159 | - 'fuel_consumption_city' => '8', |
|
| 160 | - 'fuel_consumption_highway' => '14', |
|
| 161 | - 'fuel_consumption_city_unit' => 'mi\/l', |
|
| 162 | - 'fuel_consumption_highway_unit' => 'mi\/l', |
|
| 163 | - 'mpg_city' => 30.28, |
|
| 164 | - 'mpg_highway' => 53, |
|
| 165 | - 'fuel_consumption_city_uf_value' => '8 mi\/l', |
|
| 166 | - 'fuel_consumption_highway_uf_value' => '14 mi\/l' |
|
| 167 | - ] |
|
| 168 | - ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function testGetVehiclesList() |
|
| 172 | - { |
|
| 173 | - $vehicle = new Vehicle(); |
|
| 174 | - |
|
| 175 | - $vehicleParameters = [ |
|
| 176 | - 'with_pagination' => true, |
|
| 177 | - 'page' => 2, |
|
| 178 | - 'perPage' => 10, |
|
| 179 | - ]; |
|
| 180 | - |
|
| 181 | - $result = $vehicle->getVehicles($vehicleParameters); |
|
| 182 | - |
|
| 183 | - $this->assertNotNull($result); |
|
| 184 | - $this->assertTrue(is_array($result)); |
|
| 185 | - $this->assertInstanceOf( |
|
| 186 | - DataVehicle::class, |
|
| 187 | - DataVehicle::fromArray($result) |
|
| 188 | - ); |
|
| 15 | + public static $createdVehicles=[]; |
|
| 16 | + |
|
| 17 | + public static function setUpBeforeClass() |
|
| 18 | + { |
|
| 19 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 20 | + |
|
| 21 | + $vehicle = new VehicleV4(); |
|
| 22 | + |
|
| 23 | + $vehicleParameters = Vehicle::fromArray([ |
|
| 24 | + 'vehicle_name' => 'Ford Transit Test 5', |
|
| 25 | + 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 26 | + 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 27 | + 'vehicle_reg_country_id' => '223', |
|
| 28 | + 'vehicle_make' => 'Ford', |
|
| 29 | + 'vehicle_model_year' => 2013, |
|
| 30 | + 'vehicle_axle_count' => 2, |
|
| 31 | + 'mpg_city' => 8, |
|
| 32 | + 'mpg_highway' => 14, |
|
| 33 | + 'fuel_type' => 'unleaded 93', |
|
| 34 | + 'height_inches' => 72, |
|
| 35 | + 'weight_lb' => 2000, |
|
| 36 | + ]); |
|
| 37 | + |
|
| 38 | + $result = $vehicle->createVehicle($vehicleParameters); |
|
| 39 | + |
|
| 40 | + self::assertNotNull($result); |
|
| 41 | + self::assertInstanceOf( |
|
| 42 | + VehicleV4::class, |
|
| 43 | + VehicleV4::fromArray($result) |
|
| 44 | + ); |
|
| 45 | + |
|
| 46 | + self::$createdVehicles[] = $result['vehicle_id']; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function testFromArray() |
|
| 50 | + { |
|
| 51 | + $vehicleParameters = VehicleV4::fromArray([ |
|
| 52 | + 'vehicle_id' => '43B1DC9C2C4DC3A8FE080A126B12ACBD', |
|
| 53 | + 'member_id' => 18154, |
|
| 54 | + 'is_deleted' => false, |
|
| 55 | + 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 56 | + 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 57 | + 'vehicle_reg_state_id' => null, |
|
| 58 | + 'vehicle_reg_country_id' => 223, |
|
| 59 | + 'vehicle_license_plate' => null, |
|
| 60 | + 'vehicle_type_id' => null, |
|
| 61 | + 'timestamp_added' => '2020-12-20T17:25:14+00:00', |
|
| 62 | + 'vehicle_make' => 'Ford', |
|
| 63 | + 'vehicle_model_year' => 2013, |
|
| 64 | + 'vehicle_model' => null, |
|
| 65 | + 'vehicle_year_acquired' => null, |
|
| 66 | + 'vehicle_cost_new' => null, |
|
| 67 | + 'purchased_new' => null, |
|
| 68 | + 'license_start_date' => '2020-12-20', |
|
| 69 | + 'license_end_date' => '2020-12-20', |
|
| 70 | + 'is_operational' => true, |
|
| 71 | + 'fuel_type' => 'unleaded 93', |
|
| 72 | + 'external_telematics_vehicle_id' => null, |
|
| 73 | + 'timestamp_removed' => null, |
|
| 74 | + 'vehicle_profile_id' => null, |
|
| 75 | + 'fuel_consumption_city' => '8', |
|
| 76 | + 'fuel_consumption_highway' => '14', |
|
| 77 | + 'fuel_consumption_city_unit' => 'mi\/l', |
|
| 78 | + 'fuel_consumption_highway_unit' => 'mi\/l', |
|
| 79 | + 'mpg_city' => 30.28, |
|
| 80 | + 'mpg_highway' => 53, |
|
| 81 | + 'fuel_consumption_city_uf_value' => '8 mi\/l', |
|
| 82 | + 'fuel_consumption_highway_uf_value' => '14 mi\/l' |
|
| 83 | + ]); |
|
| 84 | + |
|
| 85 | + $this->assertEquals('43B1DC9C2C4DC3A8FE080A126B12ACBD', $vehicleParameters->vehicle_id); |
|
| 86 | + $this->assertEquals(18154, $vehicleParameters->member_id); |
|
| 87 | + $this->assertEquals(false, $vehicleParameters->is_deleted); |
|
| 88 | + $this->assertEquals('Ford Transit Test 5', $vehicleParameters->vehicle_alias); |
|
| 89 | + $this->assertEquals('JS3TD62V1Y4107898', $vehicleParameters->vehicle_vin); |
|
| 90 | + $this->assertEquals(null, $vehicleParameters->vehicle_reg_state_id); |
|
| 91 | + $this->assertEquals(223, $vehicleParameters->vehicle_reg_country_id); |
|
| 92 | + $this->assertEquals(null, $vehicleParameters->vehicle_license_plate); |
|
| 93 | + $this->assertEquals(null, $vehicleParameters->vehicle_type_id); |
|
| 94 | + $this->assertEquals('2020-12-20T17:25:14+00:00', $vehicleParameters->timestamp_added); |
|
| 95 | + $this->assertEquals('Ford', $vehicleParameters->vehicle_make); |
|
| 96 | + $this->assertEquals(2013, $vehicleParameters->vehicle_model_year); |
|
| 97 | + $this->assertEquals(null, $vehicleParameters->vehicle_model); |
|
| 98 | + $this->assertEquals(null, $vehicleParameters->vehicle_year_acquired); |
|
| 99 | + $this->assertEquals(null, $vehicleParameters->vehicle_cost_new); |
|
| 100 | + $this->assertEquals(null, $vehicleParameters->purchased_new); |
|
| 101 | + $this->assertEquals('2020-12-20', $vehicleParameters->license_start_date); |
|
| 102 | + $this->assertEquals('2020-12-20', $vehicleParameters->license_end_date); |
|
| 103 | + $this->assertEquals(true, $vehicleParameters->is_operational); |
|
| 104 | + $this->assertEquals('unleaded 93', $vehicleParameters->fuel_type); |
|
| 105 | + $this->assertEquals(null, $vehicleParameters->external_telematics_vehicle_id); |
|
| 106 | + $this->assertEquals(null, $vehicleParameters->timestamp_removed); |
|
| 107 | + $this->assertEquals(null, $vehicleParameters->vehicle_profile_id); |
|
| 108 | + $this->assertEquals('8', $vehicleParameters->fuel_consumption_city); |
|
| 109 | + $this->assertEquals('14', $vehicleParameters->fuel_consumption_highway); |
|
| 110 | + $this->assertEquals('mi\/l', $vehicleParameters->fuel_consumption_city_unit); |
|
| 111 | + $this->assertEquals('mi\/l', $vehicleParameters->fuel_consumption_highway_unit); |
|
| 112 | + $this->assertEquals(30.28, $vehicleParameters->mpg_city); |
|
| 113 | + $this->assertEquals(53, $vehicleParameters->mpg_highway); |
|
| 114 | + $this->assertEquals('8 mi\/l', $vehicleParameters->fuel_consumption_city_uf_value); |
|
| 115 | + $this->assertEquals('14 mi\/l', $vehicleParameters->fuel_consumption_highway_uf_value); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + public function testToArray() |
|
| 119 | + { |
|
| 120 | + $vehicleParameters = VehicleV4::fromArray([ |
|
| 121 | + 'vehicle_id' => '43B1DC9C2C4DC3A8FE080A126B12ACBD', |
|
| 122 | + 'member_id' => 18154, |
|
| 123 | + 'is_deleted' => false, |
|
| 124 | + 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 125 | + 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 126 | + 'vehicle_reg_country_id' => 223, |
|
| 127 | + 'timestamp_added' => '2020-12-20T17:25:14+00:00', |
|
| 128 | + 'vehicle_make' => 'Ford', |
|
| 129 | + 'vehicle_model_year' => 2013, |
|
| 130 | + 'license_start_date' => '2020-12-20', |
|
| 131 | + 'license_end_date' => '2020-12-20', |
|
| 132 | + 'is_operational' => true, |
|
| 133 | + 'fuel_type' => 'unleaded 93', |
|
| 134 | + 'fuel_consumption_city' => '8', |
|
| 135 | + 'fuel_consumption_highway' => '14', |
|
| 136 | + 'fuel_consumption_city_unit' => 'mi\/l', |
|
| 137 | + 'fuel_consumption_highway_unit' => 'mi\/l', |
|
| 138 | + 'mpg_city' => 30.28, |
|
| 139 | + 'mpg_highway' => 53, |
|
| 140 | + 'fuel_consumption_city_uf_value' => '8 mi\/l', |
|
| 141 | + 'fuel_consumption_highway_uf_value' => '14 mi\/l' |
|
| 142 | + ]); |
|
| 143 | + |
|
| 144 | + $this->assertEquals($vehicleParameters->toArray(), |
|
| 145 | + [ |
|
| 146 | + 'vehicle_id' => '43B1DC9C2C4DC3A8FE080A126B12ACBD', |
|
| 147 | + 'member_id' => 18154, |
|
| 148 | + 'is_deleted' => false, |
|
| 149 | + 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 150 | + 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 151 | + 'vehicle_reg_country_id' => 223, |
|
| 152 | + 'timestamp_added' => '2020-12-20T17:25:14+00:00', |
|
| 153 | + 'vehicle_make' => 'Ford', |
|
| 154 | + 'vehicle_model_year' => 2013, |
|
| 155 | + 'license_start_date' => '2020-12-20', |
|
| 156 | + 'license_end_date' => '2020-12-20', |
|
| 157 | + 'is_operational' => true, |
|
| 158 | + 'fuel_type' => 'unleaded 93', |
|
| 159 | + 'fuel_consumption_city' => '8', |
|
| 160 | + 'fuel_consumption_highway' => '14', |
|
| 161 | + 'fuel_consumption_city_unit' => 'mi\/l', |
|
| 162 | + 'fuel_consumption_highway_unit' => 'mi\/l', |
|
| 163 | + 'mpg_city' => 30.28, |
|
| 164 | + 'mpg_highway' => 53, |
|
| 165 | + 'fuel_consumption_city_uf_value' => '8 mi\/l', |
|
| 166 | + 'fuel_consumption_highway_uf_value' => '14 mi\/l' |
|
| 167 | + ] |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function testGetVehiclesList() |
|
| 172 | + { |
|
| 173 | + $vehicle = new Vehicle(); |
|
| 174 | + |
|
| 175 | + $vehicleParameters = [ |
|
| 176 | + 'with_pagination' => true, |
|
| 177 | + 'page' => 2, |
|
| 178 | + 'perPage' => 10, |
|
| 179 | + ]; |
|
| 180 | + |
|
| 181 | + $result = $vehicle->getVehicles($vehicleParameters); |
|
| 182 | + |
|
| 183 | + $this->assertNotNull($result); |
|
| 184 | + $this->assertTrue(is_array($result)); |
|
| 185 | + $this->assertInstanceOf( |
|
| 186 | + DataVehicle::class, |
|
| 187 | + DataVehicle::fromArray($result) |
|
| 188 | + ); |
|
| 189 | 189 | |
| 190 | 190 | |
| 191 | 191 | // $this->assertTrue(isset($result['current_page'])); |
| 192 | 192 | // $this->assertTrue(isset($result['data'])); |
| 193 | 193 | // $this->assertTrue(is_array($result['data'])); |
| 194 | - } |
|
| 195 | - |
|
| 196 | - public function testGetVehicle() |
|
| 197 | - { |
|
| 198 | - $vehicle = new VehicleV4(); |
|
| 199 | - |
|
| 200 | - $randomVehicleID = self::$createdVehicles[0]; |
|
| 201 | - |
|
| 202 | - // Get a vehicle by ID |
|
| 203 | - $result = $vehicle->getVehicleByID($randomVehicleID); |
|
| 204 | - |
|
| 205 | - $this->assertNotNull($result); |
|
| 206 | - $this->assertInstanceOf( |
|
| 207 | - VehicleV4::class, |
|
| 208 | - VehicleV4::fromArray($result) |
|
| 209 | - ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - public function testUpdateVehicle() |
|
| 213 | - { |
|
| 214 | - $vehicle = new VehicleV4(); |
|
| 215 | - |
|
| 216 | - $randomVehicleID = self::$createdVehicles[0]; |
|
| 217 | - |
|
| 218 | - // Update the vehicle |
|
| 219 | - $vehicleParameters = Vehicle::fromArray([ |
|
| 220 | - 'vehicle_id' => $randomVehicleID, |
|
| 221 | - 'vehicle_model_year' => 2013, |
|
| 222 | - 'vehicle_year_acquired' => 2016, |
|
| 223 | - 'vehicle_reg_country_id' => '223', |
|
| 224 | - 'vehicle_make' => 'Ford', |
|
| 225 | - 'fuel_type' => 'unleaded 93', |
|
| 226 | - ]); |
|
| 227 | - |
|
| 228 | - $result = $vehicle->updateVehicle($vehicleParameters); |
|
| 229 | - |
|
| 230 | - $this->assertNotNull($result); |
|
| 231 | - $this->assertInstanceOf( |
|
| 232 | - VehicleV4::class, |
|
| 233 | - VehicleV4::fromArray($result) |
|
| 234 | - ); |
|
| 235 | - $this->assertEquals(2013, $result['vehicle_model_year']); |
|
| 236 | - $this->assertEquals(2016, $result['vehicle_year_acquired']); |
|
| 237 | - $this->assertEquals('223', $result['vehicle_reg_country_id']); |
|
| 238 | - $this->assertEquals('Ford', $result['vehicle_make']); |
|
| 239 | - $this->assertEquals('unleaded 93', $result['fuel_type']); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - public function testCreateVehicle() |
|
| 243 | - { |
|
| 244 | - $vehicle = new VehicleV4(); |
|
| 245 | - |
|
| 246 | - $vehicleParameters = Vehicle::fromArray([ |
|
| 247 | - 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 248 | - 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 249 | - 'vehicle_reg_country_id' => '223', |
|
| 250 | - 'vehicle_make' => 'Ford', |
|
| 251 | - 'vehicle_model_year' => 2013, |
|
| 252 | - 'mpg_city' => 8, |
|
| 253 | - 'mpg_highway' => 14, |
|
| 254 | - 'fuel_type' => 'unleaded 93', |
|
| 255 | - ]); |
|
| 256 | - |
|
| 257 | - $result = $vehicle->createVehicle($vehicleParameters); |
|
| 258 | - |
|
| 259 | - self::assertNotNull($result); |
|
| 260 | - self::assertInstanceOf( |
|
| 261 | - VehicleV4::class, |
|
| 262 | - VehicleV4::fromArray($result) |
|
| 263 | - ); |
|
| 264 | - $this->assertEquals('Ford Transit Test 5', $vehicleParameters->vehicle_alias); |
|
| 265 | - $this->assertEquals('JS3TD62V1Y4107898', $vehicleParameters->vehicle_vin); |
|
| 266 | - |
|
| 267 | - self::$createdVehicles[] = $result['vehicle_id']; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - public function testCreateHazmatTruck() |
|
| 271 | - { |
|
| 272 | - $vehicle = new VehicleV4(); |
|
| 273 | - |
|
| 274 | - $vehicleParameters = Vehicle::fromArray([ |
|
| 275 | - 'vehicle_alias' => 'ISUZU FTR', |
|
| 276 | - 'vehicle_vin' => '1NP5DB9X93N507873', |
|
| 277 | - 'vehicle_license_plate' => 'IFT6253', |
|
| 278 | - 'license_start_date' => '2008-05-14', |
|
| 279 | - 'license_end_date' => '2020-09-24', |
|
| 280 | - 'vehicle_model' => 'FTR', |
|
| 281 | - 'vehicle_model_year' => 2008, |
|
| 282 | - 'vehicle_year_acquired' => 2008, |
|
| 283 | - 'vehicle_reg_country_id' => 223, |
|
| 284 | - 'vehicle_type_id' => 'bigrig', |
|
| 285 | - //'has_trailer' => false, |
|
| 286 | - 'mpg_city' => 5, |
|
| 287 | - 'mpg_highway' => 15, |
|
| 288 | - 'fuel_type' => 'diesel', |
|
| 289 | - //'height_inches' => 112, |
|
| 290 | - //'height_metric' => 280, |
|
| 291 | - //'maxWeightPerAxleGroupInPounds' => 19000, |
|
| 292 | - //'max_weight_per_axle_group_metric' => 8620, |
|
| 293 | - //'widthInInches' => 94, |
|
| 294 | - //'width_metric' => 235, |
|
| 295 | - //'lengthInInches' => 384, |
|
| 296 | - //'length_metric' => 960, |
|
| 297 | - //'Use53FootTrailerRouting' => 'NO', |
|
| 298 | - //'UseTruckRestrictions' => 'YES', |
|
| 299 | - //'DividedHighwayAvoidPreference' => 'NEUTRAL', |
|
| 300 | - //'FreewayAvoidPreference' => 'NEUTRAL', |
|
| 301 | - //'TollRoadUsage' => 'ALWAYS_AVOID', |
|
| 302 | - //'truck_config' => '26_STRAIGHT_TRUCK', |
|
| 303 | - //'InternationalBordersOpen' => 'YES', |
|
| 304 | - 'purchased_new' => true, |
|
| 305 | - //'HazmatType' => 'FLAMMABLE', |
|
| 306 | - ]); |
|
| 307 | - |
|
| 308 | - $response = $vehicle->createVehicle($vehicleParameters); |
|
| 309 | - |
|
| 310 | - self::assertNotNull($response); |
|
| 311 | - self::assertInstanceOf( |
|
| 312 | - VehicleCreateResponseV4::class, |
|
| 313 | - VehicleCreateResponseV4::fromArray($response) |
|
| 314 | - ); |
|
| 315 | - |
|
| 316 | - $result = VehicleCreateResponseV4::fromArray($response); |
|
| 317 | - |
|
| 318 | - $this->assertEquals('ISUZU FTR', $result->vehicle_alias); |
|
| 319 | - $this->assertEquals('1NP5DB9X93N507873', $result->vehicle_vin); |
|
| 320 | - $this->assertEquals('IFT6253', $result->vehicle_license_plate); |
|
| 321 | - $this->assertEquals('2008-05-14', $result->license_start_date); |
|
| 322 | - $this->assertEquals('2020-09-24', $result->license_end_date); |
|
| 323 | - $this->assertEquals('FTR', $result->vehicle_model); |
|
| 324 | - $this->assertEquals(2008, $result->vehicle_model_year); |
|
| 325 | - $this->assertEquals(2008, $result->vehicle_year_acquired); |
|
| 326 | - $this->assertEquals(223, $result->vehicle_reg_country_id); |
|
| 327 | - $this->assertEquals('bigrig', $result->vehicle_type_id); |
|
| 328 | - //$this->assertEquals(false, $result->has_trailer); |
|
| 329 | - //$this->assertEquals(5, $result->mpg_city); |
|
| 330 | - //$this->assertEquals(15, $result->mpg_highway); |
|
| 331 | - $this->assertEquals('5', $result->fuel_consumption_city); |
|
| 332 | - $this->assertEquals('15', $result->fuel_consumption_highway); |
|
| 333 | - $this->assertEquals('diesel', $result->fuel_type); |
|
| 334 | - //$this->assertEquals(112, $result->height_inches); |
|
| 335 | - //$this->assertEquals(280, $result->height_metric); |
|
| 336 | - //$this->assertEquals(19000, $result->maxWeightPerAxleGroupInPounds); |
|
| 337 | - //$this->assertEquals(8620, $result->max_weight_per_axle_group_metric); |
|
| 338 | - //$this->assertEquals(94, $result->widthInInches); |
|
| 339 | - //$this->assertEquals(235, $result->width_metric); |
|
| 340 | - //$this->assertEquals(384, $result->lengthInInches); |
|
| 341 | - //$this->assertEquals(960, $result->length_metric); |
|
| 342 | - //$this->assertEquals('NO', $result->Use53FootTrailerRouting); |
|
| 343 | - //$this->assertEquals('YES', $result->UseTruckRestrictions); |
|
| 344 | - //$this->assertEquals('NEUTRAL', $result->DividedHighwayAvoidPreference); |
|
| 345 | - //$this->assertEquals('NEUTRAL', $result->FreewayAvoidPreference); |
|
| 346 | - //$this->assertEquals('ALWAYS_AVOID', $result->TollRoadUsage); |
|
| 347 | - //$this->assertEquals('26_STRAIGHT_TRUCK', $result->truck_config); |
|
| 348 | - //$this->assertEquals('YES', $result->InternationalBordersOpen); |
|
| 349 | - $this->assertEquals(true, $result->purchased_new); |
|
| 350 | - //$this->assertEquals('FLAMMABLE', $result->HazmatType); |
|
| 351 | - |
|
| 352 | - self::$createdVehicles[] = $result->vehicle_id; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - public function testCreateHeavyTruck() |
|
| 356 | - { |
|
| 357 | - $vehicle = new VehicleV4(); |
|
| 358 | - |
|
| 359 | - $vehicleParameters = Vehicle::fromArray([ |
|
| 360 | - 'vehicle_alias' => 'Peterbilt 579', |
|
| 361 | - 'vehicle_vin' => '1NP5DB9X93N507873', |
|
| 362 | - 'vehicle_license_plate' => 'PPV7516', |
|
| 363 | - 'license_start_date' => '2017-06-05', |
|
| 364 | - 'license_end_date' => '2021-08-14', |
|
| 365 | - 'vehicle_model' => '579', |
|
| 366 | - 'vehicle_model_year' => 2015, |
|
| 367 | - 'vehicle_year_acquired' => 2018, |
|
| 368 | - 'vehicle_reg_country_id' => 223, |
|
| 369 | - 'vehicle_type_id' => 'tractor_trailer', |
|
| 370 | - //'has_trailer' => true, |
|
| 371 | - 'mpg_city' => 6, |
|
| 372 | - 'mpg_highway' => 12, |
|
| 373 | - 'fuel_type' => 'diesel', |
|
| 374 | - //'height_inches' => 114, |
|
| 375 | - //'height_metric' => 290, |
|
| 376 | - //'maxWeightPerAxleGroupInPounds' => 40000, |
|
| 377 | - //'max_weight_per_axle_group_metric' => 18000, |
|
| 378 | - //'widthInInches' => 102, |
|
| 379 | - //'width_metric' => 258, |
|
| 380 | - //'lengthInInches' => 640, |
|
| 381 | - //'length_metric' => 1625, |
|
| 382 | - //'Use53FootTrailerRouting' => 'YES', |
|
| 383 | - //'UseTruckRestrictions' => 'YES', |
|
| 384 | - //'DividedHighwayAvoidPreference' => 'STRONG_AVOID', |
|
| 385 | - //'FreewayAvoidPreference' => 'STRONG_AVOID', |
|
| 386 | - //'truck_config' => '53_SEMI_TRAILER', |
|
| 387 | - //'InternationalBordersOpen' => 'YES', |
|
| 388 | - 'purchased_new' => true, |
|
| 389 | - ]); |
|
| 390 | - |
|
| 391 | - $response = $vehicle->createVehicle($vehicleParameters); |
|
| 392 | - |
|
| 393 | - self::assertNotNull($response); |
|
| 394 | - self::assertInstanceOf( |
|
| 395 | - VehicleCreateResponseV4::class, |
|
| 396 | - VehicleCreateResponseV4::fromArray($response) |
|
| 397 | - ); |
|
| 398 | - |
|
| 399 | - $result = VehicleCreateResponseV4::fromArray($response); |
|
| 400 | - |
|
| 401 | - $this->assertEquals('Peterbilt 579', $result->vehicle_alias); |
|
| 402 | - $this->assertEquals('1NP5DB9X93N507873', $result->vehicle_vin); |
|
| 403 | - $this->assertEquals('PPV7516', $result->vehicle_license_plate); |
|
| 404 | - $this->assertEquals('2017-06-05', $result->license_start_date); |
|
| 405 | - $this->assertEquals('2021-08-14', $result->license_end_date); |
|
| 406 | - $this->assertEquals('579', $result->vehicle_model); |
|
| 407 | - $this->assertEquals(2015, $result->vehicle_model_year); |
|
| 408 | - $this->assertEquals(2018, $result->vehicle_year_acquired); |
|
| 409 | - $this->assertEquals(223, $result->vehicle_reg_country_id); |
|
| 410 | - $this->assertEquals('tractor_trailer', $result->vehicle_type_id); |
|
| 411 | - //$this->assertEquals(true, $result->has_trailer); |
|
| 412 | - //'$this->assertEquals(6, $result->mpg_city); |
|
| 413 | - //$this->assertEquals(12, $result->mpg_highway); |
|
| 414 | - $this->assertEquals('6', $result->fuel_consumption_city); |
|
| 415 | - $this->assertEquals('12', $result->fuel_consumption_highway); |
|
| 416 | - $this->assertEquals('diesel', $result->fuel_type); |
|
| 417 | - //$this->assertEquals(114, $result->height_inches); |
|
| 418 | - //$this->assertEquals(290, $result->height_metric); |
|
| 419 | - //$this->assertEquals(40000, $result->maxWeightPerAxleGroupInPounds); |
|
| 420 | - //$this->assertEquals(18000, $result->max_weight_per_axle_group_metric); |
|
| 421 | - //$this->assertEquals(102, $result->widthInInches); |
|
| 422 | - //$this->assertEquals(258, $result->width_metric); |
|
| 423 | - //$this->assertEquals(640, $result->lengthInInches); |
|
| 424 | - //$this->assertEquals(1625, $result->length_metric); |
|
| 425 | - //$this->assertEquals('YES', $result->Use53FootTrailerRouting); |
|
| 426 | - //$this->assertEquals('YES', $result->UseTruckRestrictions); |
|
| 427 | - //$this->assertEquals('STRONG_AVOID', $result->DividedHighwayAvoidPreference); |
|
| 428 | - //$this->assertEquals('STRONG_AVOID', $result->FreewayAvoidPreference); |
|
| 429 | - //$this->assertEquals('ALWAYS_AVOID', $result->TollRoadUsage); |
|
| 430 | - //$this->assertEquals('53_SEMI_TRAILER', $result->truck_config); |
|
| 431 | - //$this->assertEquals('YES', $result->InternationalBordersOpen); |
|
| 432 | - $this->assertEquals(true, $result->purchased_new); |
|
| 433 | - |
|
| 434 | - self::$createdVehicles[] = $result->vehicle_id; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - public static function tearDownAfterClass() |
|
| 438 | - { |
|
| 439 | - if (!is_null(self::$createdVehicles) && sizeof(self::$createdVehicles)>0) { |
|
| 440 | - $vehicle = new VehicleV4(); |
|
| 441 | - |
|
| 442 | - foreach (self::$createdVehicles as $createdVehicleId) { |
|
| 443 | - $vehicleParameters = VehicleV4::fromArray([ |
|
| 444 | - 'vehicle_id' => $createdVehicleId, |
|
| 445 | - ]); |
|
| 446 | - |
|
| 447 | - $result = $vehicle->removeVehicle($vehicleParameters); |
|
| 448 | - |
|
| 449 | - if (!is_null($result) && (VehicleV4::fromArray($result) instanceof VehicleV4)) { |
|
| 450 | - echo "The vehicle ".$result['vehicle_id']." removed <br>"; |
|
| 451 | - } else { |
|
| 452 | - echo "Cannot remove the vehicle ".$result['vehicle_id']." <br>"; |
|
| 453 | - }; |
|
| 454 | - |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + public function testGetVehicle() |
|
| 197 | + { |
|
| 198 | + $vehicle = new VehicleV4(); |
|
| 199 | + |
|
| 200 | + $randomVehicleID = self::$createdVehicles[0]; |
|
| 201 | + |
|
| 202 | + // Get a vehicle by ID |
|
| 203 | + $result = $vehicle->getVehicleByID($randomVehicleID); |
|
| 204 | + |
|
| 205 | + $this->assertNotNull($result); |
|
| 206 | + $this->assertInstanceOf( |
|
| 207 | + VehicleV4::class, |
|
| 208 | + VehicleV4::fromArray($result) |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + public function testUpdateVehicle() |
|
| 213 | + { |
|
| 214 | + $vehicle = new VehicleV4(); |
|
| 215 | + |
|
| 216 | + $randomVehicleID = self::$createdVehicles[0]; |
|
| 217 | + |
|
| 218 | + // Update the vehicle |
|
| 219 | + $vehicleParameters = Vehicle::fromArray([ |
|
| 220 | + 'vehicle_id' => $randomVehicleID, |
|
| 221 | + 'vehicle_model_year' => 2013, |
|
| 222 | + 'vehicle_year_acquired' => 2016, |
|
| 223 | + 'vehicle_reg_country_id' => '223', |
|
| 224 | + 'vehicle_make' => 'Ford', |
|
| 225 | + 'fuel_type' => 'unleaded 93', |
|
| 226 | + ]); |
|
| 227 | + |
|
| 228 | + $result = $vehicle->updateVehicle($vehicleParameters); |
|
| 229 | + |
|
| 230 | + $this->assertNotNull($result); |
|
| 231 | + $this->assertInstanceOf( |
|
| 232 | + VehicleV4::class, |
|
| 233 | + VehicleV4::fromArray($result) |
|
| 234 | + ); |
|
| 235 | + $this->assertEquals(2013, $result['vehicle_model_year']); |
|
| 236 | + $this->assertEquals(2016, $result['vehicle_year_acquired']); |
|
| 237 | + $this->assertEquals('223', $result['vehicle_reg_country_id']); |
|
| 238 | + $this->assertEquals('Ford', $result['vehicle_make']); |
|
| 239 | + $this->assertEquals('unleaded 93', $result['fuel_type']); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + public function testCreateVehicle() |
|
| 243 | + { |
|
| 244 | + $vehicle = new VehicleV4(); |
|
| 245 | + |
|
| 246 | + $vehicleParameters = Vehicle::fromArray([ |
|
| 247 | + 'vehicle_alias' => 'Ford Transit Test 5', |
|
| 248 | + 'vehicle_vin' => 'JS3TD62V1Y4107898', |
|
| 249 | + 'vehicle_reg_country_id' => '223', |
|
| 250 | + 'vehicle_make' => 'Ford', |
|
| 251 | + 'vehicle_model_year' => 2013, |
|
| 252 | + 'mpg_city' => 8, |
|
| 253 | + 'mpg_highway' => 14, |
|
| 254 | + 'fuel_type' => 'unleaded 93', |
|
| 255 | + ]); |
|
| 256 | + |
|
| 257 | + $result = $vehicle->createVehicle($vehicleParameters); |
|
| 258 | + |
|
| 259 | + self::assertNotNull($result); |
|
| 260 | + self::assertInstanceOf( |
|
| 261 | + VehicleV4::class, |
|
| 262 | + VehicleV4::fromArray($result) |
|
| 263 | + ); |
|
| 264 | + $this->assertEquals('Ford Transit Test 5', $vehicleParameters->vehicle_alias); |
|
| 265 | + $this->assertEquals('JS3TD62V1Y4107898', $vehicleParameters->vehicle_vin); |
|
| 266 | + |
|
| 267 | + self::$createdVehicles[] = $result['vehicle_id']; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + public function testCreateHazmatTruck() |
|
| 271 | + { |
|
| 272 | + $vehicle = new VehicleV4(); |
|
| 273 | + |
|
| 274 | + $vehicleParameters = Vehicle::fromArray([ |
|
| 275 | + 'vehicle_alias' => 'ISUZU FTR', |
|
| 276 | + 'vehicle_vin' => '1NP5DB9X93N507873', |
|
| 277 | + 'vehicle_license_plate' => 'IFT6253', |
|
| 278 | + 'license_start_date' => '2008-05-14', |
|
| 279 | + 'license_end_date' => '2020-09-24', |
|
| 280 | + 'vehicle_model' => 'FTR', |
|
| 281 | + 'vehicle_model_year' => 2008, |
|
| 282 | + 'vehicle_year_acquired' => 2008, |
|
| 283 | + 'vehicle_reg_country_id' => 223, |
|
| 284 | + 'vehicle_type_id' => 'bigrig', |
|
| 285 | + //'has_trailer' => false, |
|
| 286 | + 'mpg_city' => 5, |
|
| 287 | + 'mpg_highway' => 15, |
|
| 288 | + 'fuel_type' => 'diesel', |
|
| 289 | + //'height_inches' => 112, |
|
| 290 | + //'height_metric' => 280, |
|
| 291 | + //'maxWeightPerAxleGroupInPounds' => 19000, |
|
| 292 | + //'max_weight_per_axle_group_metric' => 8620, |
|
| 293 | + //'widthInInches' => 94, |
|
| 294 | + //'width_metric' => 235, |
|
| 295 | + //'lengthInInches' => 384, |
|
| 296 | + //'length_metric' => 960, |
|
| 297 | + //'Use53FootTrailerRouting' => 'NO', |
|
| 298 | + //'UseTruckRestrictions' => 'YES', |
|
| 299 | + //'DividedHighwayAvoidPreference' => 'NEUTRAL', |
|
| 300 | + //'FreewayAvoidPreference' => 'NEUTRAL', |
|
| 301 | + //'TollRoadUsage' => 'ALWAYS_AVOID', |
|
| 302 | + //'truck_config' => '26_STRAIGHT_TRUCK', |
|
| 303 | + //'InternationalBordersOpen' => 'YES', |
|
| 304 | + 'purchased_new' => true, |
|
| 305 | + //'HazmatType' => 'FLAMMABLE', |
|
| 306 | + ]); |
|
| 307 | + |
|
| 308 | + $response = $vehicle->createVehicle($vehicleParameters); |
|
| 309 | + |
|
| 310 | + self::assertNotNull($response); |
|
| 311 | + self::assertInstanceOf( |
|
| 312 | + VehicleCreateResponseV4::class, |
|
| 313 | + VehicleCreateResponseV4::fromArray($response) |
|
| 314 | + ); |
|
| 315 | + |
|
| 316 | + $result = VehicleCreateResponseV4::fromArray($response); |
|
| 317 | + |
|
| 318 | + $this->assertEquals('ISUZU FTR', $result->vehicle_alias); |
|
| 319 | + $this->assertEquals('1NP5DB9X93N507873', $result->vehicle_vin); |
|
| 320 | + $this->assertEquals('IFT6253', $result->vehicle_license_plate); |
|
| 321 | + $this->assertEquals('2008-05-14', $result->license_start_date); |
|
| 322 | + $this->assertEquals('2020-09-24', $result->license_end_date); |
|
| 323 | + $this->assertEquals('FTR', $result->vehicle_model); |
|
| 324 | + $this->assertEquals(2008, $result->vehicle_model_year); |
|
| 325 | + $this->assertEquals(2008, $result->vehicle_year_acquired); |
|
| 326 | + $this->assertEquals(223, $result->vehicle_reg_country_id); |
|
| 327 | + $this->assertEquals('bigrig', $result->vehicle_type_id); |
|
| 328 | + //$this->assertEquals(false, $result->has_trailer); |
|
| 329 | + //$this->assertEquals(5, $result->mpg_city); |
|
| 330 | + //$this->assertEquals(15, $result->mpg_highway); |
|
| 331 | + $this->assertEquals('5', $result->fuel_consumption_city); |
|
| 332 | + $this->assertEquals('15', $result->fuel_consumption_highway); |
|
| 333 | + $this->assertEquals('diesel', $result->fuel_type); |
|
| 334 | + //$this->assertEquals(112, $result->height_inches); |
|
| 335 | + //$this->assertEquals(280, $result->height_metric); |
|
| 336 | + //$this->assertEquals(19000, $result->maxWeightPerAxleGroupInPounds); |
|
| 337 | + //$this->assertEquals(8620, $result->max_weight_per_axle_group_metric); |
|
| 338 | + //$this->assertEquals(94, $result->widthInInches); |
|
| 339 | + //$this->assertEquals(235, $result->width_metric); |
|
| 340 | + //$this->assertEquals(384, $result->lengthInInches); |
|
| 341 | + //$this->assertEquals(960, $result->length_metric); |
|
| 342 | + //$this->assertEquals('NO', $result->Use53FootTrailerRouting); |
|
| 343 | + //$this->assertEquals('YES', $result->UseTruckRestrictions); |
|
| 344 | + //$this->assertEquals('NEUTRAL', $result->DividedHighwayAvoidPreference); |
|
| 345 | + //$this->assertEquals('NEUTRAL', $result->FreewayAvoidPreference); |
|
| 346 | + //$this->assertEquals('ALWAYS_AVOID', $result->TollRoadUsage); |
|
| 347 | + //$this->assertEquals('26_STRAIGHT_TRUCK', $result->truck_config); |
|
| 348 | + //$this->assertEquals('YES', $result->InternationalBordersOpen); |
|
| 349 | + $this->assertEquals(true, $result->purchased_new); |
|
| 350 | + //$this->assertEquals('FLAMMABLE', $result->HazmatType); |
|
| 351 | + |
|
| 352 | + self::$createdVehicles[] = $result->vehicle_id; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + public function testCreateHeavyTruck() |
|
| 356 | + { |
|
| 357 | + $vehicle = new VehicleV4(); |
|
| 358 | + |
|
| 359 | + $vehicleParameters = Vehicle::fromArray([ |
|
| 360 | + 'vehicle_alias' => 'Peterbilt 579', |
|
| 361 | + 'vehicle_vin' => '1NP5DB9X93N507873', |
|
| 362 | + 'vehicle_license_plate' => 'PPV7516', |
|
| 363 | + 'license_start_date' => '2017-06-05', |
|
| 364 | + 'license_end_date' => '2021-08-14', |
|
| 365 | + 'vehicle_model' => '579', |
|
| 366 | + 'vehicle_model_year' => 2015, |
|
| 367 | + 'vehicle_year_acquired' => 2018, |
|
| 368 | + 'vehicle_reg_country_id' => 223, |
|
| 369 | + 'vehicle_type_id' => 'tractor_trailer', |
|
| 370 | + //'has_trailer' => true, |
|
| 371 | + 'mpg_city' => 6, |
|
| 372 | + 'mpg_highway' => 12, |
|
| 373 | + 'fuel_type' => 'diesel', |
|
| 374 | + //'height_inches' => 114, |
|
| 375 | + //'height_metric' => 290, |
|
| 376 | + //'maxWeightPerAxleGroupInPounds' => 40000, |
|
| 377 | + //'max_weight_per_axle_group_metric' => 18000, |
|
| 378 | + //'widthInInches' => 102, |
|
| 379 | + //'width_metric' => 258, |
|
| 380 | + //'lengthInInches' => 640, |
|
| 381 | + //'length_metric' => 1625, |
|
| 382 | + //'Use53FootTrailerRouting' => 'YES', |
|
| 383 | + //'UseTruckRestrictions' => 'YES', |
|
| 384 | + //'DividedHighwayAvoidPreference' => 'STRONG_AVOID', |
|
| 385 | + //'FreewayAvoidPreference' => 'STRONG_AVOID', |
|
| 386 | + //'truck_config' => '53_SEMI_TRAILER', |
|
| 387 | + //'InternationalBordersOpen' => 'YES', |
|
| 388 | + 'purchased_new' => true, |
|
| 389 | + ]); |
|
| 390 | + |
|
| 391 | + $response = $vehicle->createVehicle($vehicleParameters); |
|
| 392 | + |
|
| 393 | + self::assertNotNull($response); |
|
| 394 | + self::assertInstanceOf( |
|
| 395 | + VehicleCreateResponseV4::class, |
|
| 396 | + VehicleCreateResponseV4::fromArray($response) |
|
| 397 | + ); |
|
| 398 | + |
|
| 399 | + $result = VehicleCreateResponseV4::fromArray($response); |
|
| 400 | + |
|
| 401 | + $this->assertEquals('Peterbilt 579', $result->vehicle_alias); |
|
| 402 | + $this->assertEquals('1NP5DB9X93N507873', $result->vehicle_vin); |
|
| 403 | + $this->assertEquals('PPV7516', $result->vehicle_license_plate); |
|
| 404 | + $this->assertEquals('2017-06-05', $result->license_start_date); |
|
| 405 | + $this->assertEquals('2021-08-14', $result->license_end_date); |
|
| 406 | + $this->assertEquals('579', $result->vehicle_model); |
|
| 407 | + $this->assertEquals(2015, $result->vehicle_model_year); |
|
| 408 | + $this->assertEquals(2018, $result->vehicle_year_acquired); |
|
| 409 | + $this->assertEquals(223, $result->vehicle_reg_country_id); |
|
| 410 | + $this->assertEquals('tractor_trailer', $result->vehicle_type_id); |
|
| 411 | + //$this->assertEquals(true, $result->has_trailer); |
|
| 412 | + //'$this->assertEquals(6, $result->mpg_city); |
|
| 413 | + //$this->assertEquals(12, $result->mpg_highway); |
|
| 414 | + $this->assertEquals('6', $result->fuel_consumption_city); |
|
| 415 | + $this->assertEquals('12', $result->fuel_consumption_highway); |
|
| 416 | + $this->assertEquals('diesel', $result->fuel_type); |
|
| 417 | + //$this->assertEquals(114, $result->height_inches); |
|
| 418 | + //$this->assertEquals(290, $result->height_metric); |
|
| 419 | + //$this->assertEquals(40000, $result->maxWeightPerAxleGroupInPounds); |
|
| 420 | + //$this->assertEquals(18000, $result->max_weight_per_axle_group_metric); |
|
| 421 | + //$this->assertEquals(102, $result->widthInInches); |
|
| 422 | + //$this->assertEquals(258, $result->width_metric); |
|
| 423 | + //$this->assertEquals(640, $result->lengthInInches); |
|
| 424 | + //$this->assertEquals(1625, $result->length_metric); |
|
| 425 | + //$this->assertEquals('YES', $result->Use53FootTrailerRouting); |
|
| 426 | + //$this->assertEquals('YES', $result->UseTruckRestrictions); |
|
| 427 | + //$this->assertEquals('STRONG_AVOID', $result->DividedHighwayAvoidPreference); |
|
| 428 | + //$this->assertEquals('STRONG_AVOID', $result->FreewayAvoidPreference); |
|
| 429 | + //$this->assertEquals('ALWAYS_AVOID', $result->TollRoadUsage); |
|
| 430 | + //$this->assertEquals('53_SEMI_TRAILER', $result->truck_config); |
|
| 431 | + //$this->assertEquals('YES', $result->InternationalBordersOpen); |
|
| 432 | + $this->assertEquals(true, $result->purchased_new); |
|
| 433 | + |
|
| 434 | + self::$createdVehicles[] = $result->vehicle_id; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + public static function tearDownAfterClass() |
|
| 438 | + { |
|
| 439 | + if (!is_null(self::$createdVehicles) && sizeof(self::$createdVehicles)>0) { |
|
| 440 | + $vehicle = new VehicleV4(); |
|
| 441 | + |
|
| 442 | + foreach (self::$createdVehicles as $createdVehicleId) { |
|
| 443 | + $vehicleParameters = VehicleV4::fromArray([ |
|
| 444 | + 'vehicle_id' => $createdVehicleId, |
|
| 445 | + ]); |
|
| 446 | + |
|
| 447 | + $result = $vehicle->removeVehicle($vehicleParameters); |
|
| 448 | + |
|
| 449 | + if (!is_null($result) && (VehicleV4::fromArray($result) instanceof VehicleV4)) { |
|
| 450 | + echo "The vehicle ".$result['vehicle_id']." removed <br>"; |
|
| 451 | + } else { |
|
| 452 | + echo "Cannot remove the vehicle ".$result['vehicle_id']." <br>"; |
|
| 453 | + }; |
|
| 454 | + |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | 458 | } |
| 459 | 459 | \ No newline at end of file |
@@ -10,198 +10,198 @@ |
||
| 10 | 10 | |
| 11 | 11 | class GeocodingUnitTests extends \PHPUnit\Framework\TestCase |
| 12 | 12 | { |
| 13 | - public static function setUpBeforeClass() |
|
| 14 | - { |
|
| 15 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 16 | - } |
|
| 13 | + public static function setUpBeforeClass() |
|
| 14 | + { |
|
| 15 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function testFromArray() |
|
| 19 | - { |
|
| 20 | - $geocoding = Geocoding::fromArray([ |
|
| 21 | - 'strExportFormat' => 'json', |
|
| 22 | - 'addresses' => 'Los20%Angeles20%International20%Airport,20%CA', |
|
| 23 | - ]); |
|
| 18 | + public function testFromArray() |
|
| 19 | + { |
|
| 20 | + $geocoding = Geocoding::fromArray([ |
|
| 21 | + 'strExportFormat' => 'json', |
|
| 22 | + 'addresses' => 'Los20%Angeles20%International20%Airport,20%CA', |
|
| 23 | + ]); |
|
| 24 | 24 | |
| 25 | - $this->assertEquals('json', $geocoding->strExportFormat); |
|
| 26 | - $this->assertEquals('Los20%Angeles20%International20%Airport,20%CA', $geocoding->addresses); |
|
| 27 | - } |
|
| 25 | + $this->assertEquals('json', $geocoding->strExportFormat); |
|
| 26 | + $this->assertEquals('Los20%Angeles20%International20%Airport,20%CA', $geocoding->addresses); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function testForwardGeocoding() |
|
| 30 | - { |
|
| 31 | - $geoCodingParameters = [ |
|
| 32 | - 'strExportFormat' => 'json', |
|
| 33 | - 'addresses' => 'Los20%Angeles20%International20%Airport,20%CA', |
|
| 34 | - ]; |
|
| 29 | + public function testForwardGeocoding() |
|
| 30 | + { |
|
| 31 | + $geoCodingParameters = [ |
|
| 32 | + 'strExportFormat' => 'json', |
|
| 33 | + 'addresses' => 'Los20%Angeles20%International20%Airport,20%CA', |
|
| 34 | + ]; |
|
| 35 | 35 | |
| 36 | - $fGeocoding = new Geocoding(); |
|
| 36 | + $fGeocoding = new Geocoding(); |
|
| 37 | 37 | |
| 38 | - $result = $fGeocoding->forwardGeocoding($geoCodingParameters); |
|
| 38 | + $result = $fGeocoding->forwardGeocoding($geoCodingParameters); |
|
| 39 | 39 | |
| 40 | - $this->assertNotNull($result); |
|
| 41 | - $this->assertTrue(sizeof($result)>0); |
|
| 40 | + $this->assertNotNull($result); |
|
| 41 | + $this->assertTrue(sizeof($result)>0); |
|
| 42 | 42 | |
| 43 | - $firstGeocoding = GeocodingResponse::fromArray( |
|
| 44 | - $result[0] |
|
| 45 | - ); |
|
| 43 | + $firstGeocoding = GeocodingResponse::fromArray( |
|
| 44 | + $result[0] |
|
| 45 | + ); |
|
| 46 | 46 | |
| 47 | - $this->assertContainsOnlyInstancesOf(GeocodingResponse::class, [$firstGeocoding]); |
|
| 48 | - } |
|
| 47 | + $this->assertContainsOnlyInstancesOf(GeocodingResponse::class, [$firstGeocoding]); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function testReverseGeocoding() |
|
| 51 | - { |
|
| 52 | - $geoCodingParameters = [ |
|
| 53 | - 'strExportFormat' => 'json', |
|
| 54 | - 'addresses' => '42.35863,-71.05670', |
|
| 55 | - ]; |
|
| 50 | + public function testReverseGeocoding() |
|
| 51 | + { |
|
| 52 | + $geoCodingParameters = [ |
|
| 53 | + 'strExportFormat' => 'json', |
|
| 54 | + 'addresses' => '42.35863,-71.05670', |
|
| 55 | + ]; |
|
| 56 | 56 | |
| 57 | - $rGeocoding = new Geocoding(); |
|
| 57 | + $rGeocoding = new Geocoding(); |
|
| 58 | 58 | |
| 59 | - $result = $rGeocoding->reverseGeocoding($geoCodingParameters); |
|
| 59 | + $result = $rGeocoding->reverseGeocoding($geoCodingParameters); |
|
| 60 | 60 | |
| 61 | - $this->assertNotNull($result); |
|
| 62 | - $this->assertTrue(sizeof($result)>0); |
|
| 61 | + $this->assertNotNull($result); |
|
| 62 | + $this->assertTrue(sizeof($result)>0); |
|
| 63 | 63 | |
| 64 | - $firstGeocoding = GeocodingResponse::fromArray( |
|
| 65 | - $result["destination"] |
|
| 66 | - ); |
|
| 64 | + $firstGeocoding = GeocodingResponse::fromArray( |
|
| 65 | + $result["destination"] |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - $this->assertContainsOnlyInstancesOf(GeocodingResponse::class, [$firstGeocoding]); |
|
| 69 | - } |
|
| 68 | + $this->assertContainsOnlyInstancesOf(GeocodingResponse::class, [$firstGeocoding]); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function testGetStreetData() |
|
| 72 | - { |
|
| 73 | - $this->markTestSkipped('must be revisited.'); |
|
| 71 | + public function testGetStreetData() |
|
| 72 | + { |
|
| 73 | + $this->markTestSkipped('must be revisited.'); |
|
| 74 | 74 | |
| 75 | - if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 76 | - $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 77 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 78 | - } |
|
| 75 | + if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 76 | + $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 77 | + self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - //region Get Single Street Address |
|
| 81 | - $result = RapidAddressSearchResponse::fromArray( |
|
| 82 | - Geocoding::getStreetData(['pk' => 4]) |
|
| 83 | - ); |
|
| 80 | + //region Get Single Street Address |
|
| 81 | + $result = RapidAddressSearchResponse::fromArray( |
|
| 82 | + Geocoding::getStreetData(['pk' => 4]) |
|
| 83 | + ); |
|
| 84 | 84 | |
| 85 | - $this->assertNotNull($result); |
|
| 86 | - $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$result]); |
|
| 87 | - //endregion |
|
| 88 | - |
|
| 89 | - //region Get All Street Data |
|
| 90 | - $resultAll = Geocoding::getStreetData([]); |
|
| 85 | + $this->assertNotNull($result); |
|
| 86 | + $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$result]); |
|
| 87 | + //endregion |
|
| 88 | + |
|
| 89 | + //region Get All Street Data |
|
| 90 | + $resultAll = Geocoding::getStreetData([]); |
|
| 91 | 91 | |
| 92 | - $this->assertNotNull($resultAll); |
|
| 93 | - $this->assertTrue(sizeof($resultAll)>0); |
|
| 92 | + $this->assertNotNull($resultAll); |
|
| 93 | + $this->assertTrue(sizeof($resultAll)>0); |
|
| 94 | 94 | |
| 95 | - $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 96 | - $resultAll[0] |
|
| 97 | - ); |
|
| 95 | + $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 96 | + $resultAll[0] |
|
| 97 | + ); |
|
| 98 | 98 | |
| 99 | - $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 100 | - //endregion |
|
| 101 | - |
|
| 102 | - //region Get Street Data Limited |
|
| 103 | - $resultLimited = Geocoding::getStreetData([ |
|
| 104 | - 'offset' => 0, |
|
| 105 | - 'limit' => 5, |
|
| 106 | - ]); |
|
| 99 | + $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 100 | + //endregion |
|
| 101 | + |
|
| 102 | + //region Get Street Data Limited |
|
| 103 | + $resultLimited = Geocoding::getStreetData([ |
|
| 104 | + 'offset' => 0, |
|
| 105 | + 'limit' => 5, |
|
| 106 | + ]); |
|
| 107 | 107 | |
| 108 | - $this->assertNotNull($resultLimited); |
|
| 109 | - $this->assertTrue(sizeof($resultLimited)>0); |
|
| 108 | + $this->assertNotNull($resultLimited); |
|
| 109 | + $this->assertTrue(sizeof($resultLimited)>0); |
|
| 110 | 110 | |
| 111 | - $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 112 | - $resultLimited[0] |
|
| 113 | - ); |
|
| 111 | + $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 112 | + $resultLimited[0] |
|
| 113 | + ); |
|
| 114 | 114 | |
| 115 | - $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 116 | - //endregion |
|
| 117 | - } |
|
| 115 | + $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 116 | + //endregion |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - public function testGetZipCode() |
|
| 120 | - { |
|
| 121 | - $this->markTestSkipped('must be revisited.'); |
|
| 119 | + public function testGetZipCode() |
|
| 120 | + { |
|
| 121 | + $this->markTestSkipped('must be revisited.'); |
|
| 122 | 122 | |
| 123 | - if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 124 | - $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 125 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 126 | - } |
|
| 123 | + if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 124 | + $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 125 | + self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - //region Get All Geocodings With Specified Zipcode |
|
| 129 | - $resultZipAll = Geocoding::getZipCode(['zipcode' => '00601']); |
|
| 128 | + //region Get All Geocodings With Specified Zipcode |
|
| 129 | + $resultZipAll = Geocoding::getZipCode(['zipcode' => '00601']); |
|
| 130 | 130 | |
| 131 | - $this->assertNotNull($resultZipAll); |
|
| 132 | - $this->assertTrue(sizeof($resultZipAll)>0); |
|
| 131 | + $this->assertNotNull($resultZipAll); |
|
| 132 | + $this->assertTrue(sizeof($resultZipAll)>0); |
|
| 133 | 133 | |
| 134 | - $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 135 | - $resultZipAll[0] |
|
| 136 | - ); |
|
| 134 | + $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 135 | + $resultZipAll[0] |
|
| 136 | + ); |
|
| 137 | 137 | |
| 138 | - $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 139 | - //endregion |
|
| 138 | + $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 139 | + //endregion |
|
| 140 | 140 | |
| 141 | - //region Get Limited Geocodings With Specified Zipcode |
|
| 142 | - $resultZipLimited = Geocoding::getZipCode([ |
|
| 143 | - 'zipcode' => '00601', |
|
| 144 | - 'offset' => 0, |
|
| 145 | - 'limit' => 20, |
|
| 146 | - ]); |
|
| 141 | + //region Get Limited Geocodings With Specified Zipcode |
|
| 142 | + $resultZipLimited = Geocoding::getZipCode([ |
|
| 143 | + 'zipcode' => '00601', |
|
| 144 | + 'offset' => 0, |
|
| 145 | + 'limit' => 20, |
|
| 146 | + ]); |
|
| 147 | 147 | |
| 148 | - $this->assertNotNull($resultZipLimited); |
|
| 149 | - $this->assertTrue(sizeof($resultZipLimited)>0); |
|
| 148 | + $this->assertNotNull($resultZipLimited); |
|
| 149 | + $this->assertTrue(sizeof($resultZipLimited)>0); |
|
| 150 | 150 | |
| 151 | - $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 152 | - $resultZipLimited[0] |
|
| 153 | - ); |
|
| 151 | + $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 152 | + $resultZipLimited[0] |
|
| 153 | + ); |
|
| 154 | 154 | |
| 155 | - $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 156 | - //endregion |
|
| 157 | - } |
|
| 155 | + $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 156 | + //endregion |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - public function testGetService() |
|
| 160 | - { |
|
| 161 | - $this->markTestSkipped('must be revisited.'); |
|
| 159 | + public function testGetService() |
|
| 160 | + { |
|
| 161 | + $this->markTestSkipped('must be revisited.'); |
|
| 162 | 162 | |
| 163 | - if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 164 | - $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 165 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 166 | - } |
|
| 163 | + if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 164 | + $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 165 | + self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - //region Get All Geocodings With Specified Zipcode And House Number |
|
| 169 | - $resultZipHouseAll = Geocoding::getService([ |
|
| 170 | - 'zipcode' => '00601', |
|
| 171 | - 'housenumber' => 17, |
|
| 172 | - ]); |
|
| 168 | + //region Get All Geocodings With Specified Zipcode And House Number |
|
| 169 | + $resultZipHouseAll = Geocoding::getService([ |
|
| 170 | + 'zipcode' => '00601', |
|
| 171 | + 'housenumber' => 17, |
|
| 172 | + ]); |
|
| 173 | 173 | |
| 174 | - $this->assertNotNull($resultZipHouseAll); |
|
| 175 | - $this->assertTrue(sizeof($resultZipHouseAll)>0); |
|
| 174 | + $this->assertNotNull($resultZipHouseAll); |
|
| 175 | + $this->assertTrue(sizeof($resultZipHouseAll)>0); |
|
| 176 | 176 | |
| 177 | - $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 178 | - $resultZipHouseAll[0] |
|
| 179 | - ); |
|
| 177 | + $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 178 | + $resultZipHouseAll[0] |
|
| 179 | + ); |
|
| 180 | 180 | |
| 181 | - $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 182 | - //endregion |
|
| 181 | + $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 182 | + //endregion |
|
| 183 | 183 | |
| 184 | - //region Get Limited Geocodings With Specified Zipcode And House Number |
|
| 185 | - $resultZipHouseLimited = Geocoding::getService([ |
|
| 186 | - 'zipcode' => '00601', |
|
| 187 | - 'housenumber' => 17, |
|
| 188 | - 'offset' => 0, |
|
| 189 | - 'limit' => 10, |
|
| 190 | - ]); |
|
| 184 | + //region Get Limited Geocodings With Specified Zipcode And House Number |
|
| 185 | + $resultZipHouseLimited = Geocoding::getService([ |
|
| 186 | + 'zipcode' => '00601', |
|
| 187 | + 'housenumber' => 17, |
|
| 188 | + 'offset' => 0, |
|
| 189 | + 'limit' => 10, |
|
| 190 | + ]); |
|
| 191 | 191 | |
| 192 | - $this->assertNotNull($resultZipHouseLimited); |
|
| 193 | - $this->assertTrue(sizeof($resultZipHouseLimited)>0); |
|
| 192 | + $this->assertNotNull($resultZipHouseLimited); |
|
| 193 | + $this->assertTrue(sizeof($resultZipHouseLimited)>0); |
|
| 194 | 194 | |
| 195 | - $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 196 | - $resultZipHouseLimited[0] |
|
| 197 | - ); |
|
| 195 | + $firstGeocoding = RapidAddressSearchResponse::fromArray( |
|
| 196 | + $resultZipHouseLimited[0] |
|
| 197 | + ); |
|
| 198 | 198 | |
| 199 | - $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 200 | - //endregion |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - public static function tearDownAfterClass() |
|
| 204 | - { |
|
| 199 | + $this->assertContainsOnlyInstancesOf(RapidAddressSearchResponse::class, [$firstGeocoding]); |
|
| 200 | + //endregion |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + public static function tearDownAfterClass() |
|
| 204 | + { |
|
| 205 | 205 | |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | } |
| 208 | 208 | \ No newline at end of file |