GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( fd5711...77a95b )
by Igor
09:00 queued 13s
created
UnitTestFiles/Test/GeocodingUnitTests.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -10,198 +10,198 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
UnitTestFiles/Test/AdvancedConstraintsUnitTests.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -14,79 +14,79 @@
 block discarded – undo
14 14
 use Route4Me\V5\Addresses\RouteAdvancedConstraints;
15 15
 
16 16
 class AdvancedConstraintsUnitTests extends \PHPUnit\Framework\TestCase {
17
-    public static $problem;
17
+	public static $problem;
18 18
 
19
-    public static function setUpBeforeClass()
20
-    {
21
-        Route4Me::setApiKey(Constants::API_KEY);
22
-        self::$problem = null;
23
-    }
19
+	public static function setUpBeforeClass()
20
+	{
21
+		Route4Me::setApiKey(Constants::API_KEY);
22
+		self::$problem = null;
23
+	}
24 24
 
25
-    public function testAdvancedConstraintsExample12()
26
-    {
27
-        $addresses = array_map('str_getcsv', file(dirname(__FILE__).'/data/locations.csv'));
28
-        array_walk($addresses, function(&$a) use ($addresses) { $a = Address::fromArray(array_combine($addresses[0], $a)); });
29
-        array_shift($addresses);
25
+	public function testAdvancedConstraintsExample12()
26
+	{
27
+		$addresses = array_map('str_getcsv', file(dirname(__FILE__).'/data/locations.csv'));
28
+		array_walk($addresses, function(&$a) use ($addresses) { $a = Address::fromArray(array_combine($addresses[0], $a)); });
29
+		array_shift($addresses);
30 30
 
31
-        $parameters = RouteParameters::fromArray([
32
-            'algorithm_type' => AlgorithmType::ADVANCED_CVRP_TW,
33
-            'store_route' => false,
34
-            'rt' => true,
35
-            'parts' => 30,
36
-            'metric' => Metric::MATRIX,
37
-            'member_id' => 444333,
38
-            'route_name' => "Drivers Schedules - 3 Territories",
39
-            'optimize' => "Distance",
40
-            'distance_unit' => "mi",
41
-            'device_type' => DeviceType::WEB,
42
-            'travel_mode' => "Driving",
43
-            'advanced_constraints' => []
44
-        ]);
31
+		$parameters = RouteParameters::fromArray([
32
+			'algorithm_type' => AlgorithmType::ADVANCED_CVRP_TW,
33
+			'store_route' => false,
34
+			'rt' => true,
35
+			'parts' => 30,
36
+			'metric' => Metric::MATRIX,
37
+			'member_id' => 444333,
38
+			'route_name' => "Drivers Schedules - 3 Territories",
39
+			'optimize' => "Distance",
40
+			'distance_unit' => "mi",
41
+			'device_type' => DeviceType::WEB,
42
+			'travel_mode' => "Driving",
43
+			'advanced_constraints' => []
44
+		]);
45 45
 
46
-        $zones = [["ZONE 01"], ["ZONE 02"], ["ZONE 03"]];
46
+		$zones = [["ZONE 01"], ["ZONE 02"], ["ZONE 03"]];
47 47
 
48
-        for($i = 0; $i < 30; ++$i)
49
-        {
50
-            $parameters->advanced_constraints[] = RouteAdvancedConstraints::fromArray([
51
-                'tags' => [$zones[$i % 3]],
52
-                'members_count' => 1,
53
-                'available_time_windows' => [[(8 + 5) * 3600, (11 + 5) * 3600]],
54
-                'location_sequence_pattern' => [Address::fromArray([
55
-                    'address' => "RETAIL LOCATION",
56
-                    'alias' => "RETAIL LOCATION",
57
-                    'lat' => 25.8741751,
58
-                    'lng' => -80.1288583,
59
-                    'time' => 300
60
-                ])]
61
-            ]);
62
-        }
48
+		for($i = 0; $i < 30; ++$i)
49
+		{
50
+			$parameters->advanced_constraints[] = RouteAdvancedConstraints::fromArray([
51
+				'tags' => [$zones[$i % 3]],
52
+				'members_count' => 1,
53
+				'available_time_windows' => [[(8 + 5) * 3600, (11 + 5) * 3600]],
54
+				'location_sequence_pattern' => [Address::fromArray([
55
+					'address' => "RETAIL LOCATION",
56
+					'alias' => "RETAIL LOCATION",
57
+					'lat' => 25.8741751,
58
+					'lng' => -80.1288583,
59
+					'time' => 300
60
+				])]
61
+			]);
62
+		}
63 63
     
64
-        $optimizationParameters = new OptimizationProblemParams();
65
-        $optimizationParameters->setAddresses($addresses);
66
-        $optimizationParameters->setParameters($parameters);
64
+		$optimizationParameters = new OptimizationProblemParams();
65
+		$optimizationParameters->setAddresses($addresses);
66
+		$optimizationParameters->setParameters($parameters);
67 67
 
68
-        self::$problem = OptimizationProblem::optimize($optimizationParameters);
68
+		self::$problem = OptimizationProblem::optimize($optimizationParameters);
69 69
 
70
-        $this->assertNotNull(self::$problem->optimization_problem_id);
71
-        $this->assertEquals(self::$problem->parameters->route_name, 'Drivers Schedules - 3 Territories');
72
-    }
70
+		$this->assertNotNull(self::$problem->optimization_problem_id);
71
+		$this->assertEquals(self::$problem->parameters->route_name, 'Drivers Schedules - 3 Territories');
72
+	}
73 73
 
74
-    public static function tearDownAfterClass()
75
-    {
76
-        if(!is_null(self::$problem->optimization_problem_id))
77
-        {
78
-            $params = [
79
-                'optimization_problem_ids' => ['0' => self::$problem->optimization_problem_id],
80
-                'redirect' => 0,
81
-            ];
74
+	public static function tearDownAfterClass()
75
+	{
76
+		if(!is_null(self::$problem->optimization_problem_id))
77
+		{
78
+			$params = [
79
+				'optimization_problem_ids' => ['0' => self::$problem->optimization_problem_id],
80
+				'redirect' => 0,
81
+			];
82 82
 
83
-            $result = self:: $problem->removeOptimization($params);
83
+			$result = self:: $problem->removeOptimization($params);
84 84
 
85
-            if ($result!=null && $result['status']==true) {
86
-                echo "The test optimization was removed <br>";
87
-            } else {
88
-                echo "Cannot remove the test optimization <br>";
89
-            }
90
-        }
91
-    }
85
+			if ($result!=null && $result['status']==true) {
86
+				echo "The test optimization was removed <br>";
87
+			} else {
88
+				echo "Cannot remove the test optimization <br>";
89
+			}
90
+		}
91
+	}
92 92
 }
Please login to merge, or discard this patch.
UnitTestFiles/Test/AddressBookLocationUnitTests.php 1 patch
Indentation   +434 added lines, -434 removed lines patch added patch discarded remove patch
@@ -9,450 +9,450 @@
 block discarded – undo
9 9
 
10 10
 class AddressBookLocationUnitTests extends \PHPUnit\Framework\TestCase
11 11
 {
12
-    public static $createdContacts=[];
13
-
14
-    public static $csvImportedAddressIDs=[];
15
-
16
-    public static function setUpBeforeClass()
17
-    {
18
-        Route4Me::setApiKey(Constants::API_KEY);
19
-
20
-        $abl = new AddressBookLocation();
21
-
22
-        $AddressBookLocationParameters = AddressBookLocation::fromArray([
23
-            'address_1'             => '1407 MCCOY, Louisville, KY, 40215',
24
-            'address_alias'         => '1407 MCCOY 40215',
25
-            'address_group'         => 'Scheduled weekly',
26
-            'first_name'            => 'Bart',
27
-            'last_name'             => 'Douglas',
28
-            'address_email'         => '[email protected]',
29
-            'address_phone_number'  => '95487454',
30
-            'cached_lat'            => 38.202496,
31
-            'cached_lng'            => -85.786514,
32
-            'curbside_lat'          => 38.202496,
33
-            'curbside_lng'          => -85.786514,
34
-            'address_city'          => 'Louisville',
35
-            'schedule' => [[
36
-                'enabled'   => true,
37
-                'mode'      => 'weekly',
38
-                'weekly'    => [
39
-                    'every'    => 1,
40
-                    'weekdays' => [1, 2, 3, 4, 5],
41
-                ],
42
-            ]],
43
-            'service_time' => 600,
44
-        ]);
45
-
46
-        self::$createdContacts[] = AddressBookLocation::fromArray(
47
-            $abl->addAdressBookLocation($AddressBookLocationParameters)
48
-         );
49
-
50
-        $AddressBookLocationParameters = AddressBookLocation::fromArray([
51
-            'address_1'             => '4805 BELLEVUE AVE, Louisville, KY, 40215',
52
-            'address_2'             => '4806 BELLEVUE AVE, Louisville, KY, 40215',
53
-            'address_alias'         => '4805 BELLEVUE AVE 40215',
54
-            'address_group'         => 'Scheduled monthly',
55
-            'first_name'            => 'Bart',
56
-            'last_name'             => 'Douglas',
57
-            'address_email'         => '[email protected]',
58
-            'address_phone_number'  => '95487454',
59
-            'cached_lat'            => 38.178844,
60
-            'cached_lng'            => -85.774864,
61
-            'curbside_lat'          => 38.178844,
62
-            'curbside_lng'          => -85.774864,
63
-            'address_city'          => 'Louisville',
64
-            'address_country_id'    => 'US',
65
-            'address_state_id'      => 'KY',
66
-            'address_zip'           => '40215',
67
-            'schedule' => [[
68
-                'enabled'   => true,
69
-                'mode'      => 'monthly',
70
-                'monthly'   => [
71
-                    'every' => 1,
72
-                    'mode'  => 'dates',
73
-                    'dates' => [20, 22, 23, 24, 25],
74
-                ],
75
-            ]],
76
-            'service_time' => 750,
77
-            'color'        => 'red',
78
-        ]);
79
-
80
-        self::$createdContacts[] = AddressBookLocation::fromArray(
81
-            $abl->addAdressBookLocation($AddressBookLocationParameters)
82
-        );
83
-    }
84
-
85
-    public function testAddressBookLocationFromArray()
86
-    {
87
-        $location = AddressBookLocation::fromArray([
88
-            'address_1'             => '1604 PARKRIDGE PKWY, Louisville, KY, 40214',
89
-            'cached_lat'            => 38.141598,
90
-            'cached_lng'            => -85.793846,
91
-            'address_alias'         => '1604 PARKRIDGE PKWY 40214',
92
-            'address_group'         => 'Scheduled daily',
93
-            'first_name'            => 'Peter',
94
-            'last_name'             => 'Newman',
95
-            'address_email'         => '[email protected]',
96
-            'address_phone_number'  => '65432178',
97
-            'address_city'          => 'Louisville',
98
-            'address_custom_data'   => ['scheduled'     => 'yes',
99
-                                        'serice type'   => 'publishing', ],
100
-            'schedule' => [[
101
-                'enabled'   => true,
102
-                'mode'      => 'daily',
103
-                'daily'     => ['every' => 1],
104
-            ]],
105
-            'service_time'          => 900,
106
-        ]);
107
-
108
-        $this->assertEquals('1604 PARKRIDGE PKWY, Louisville, KY, 40214', $location->address_1);
109
-        $this->assertEquals(38.141598, $location->cached_lat);
110
-        $this->assertEquals(-85.793846, $location->cached_lng);
111
-        $this->assertEquals('1604 PARKRIDGE PKWY 40214', $location->address_alias);
112
-
113
-        $this->assertEquals('Peter', $location->first_name);
114
-        $this->assertEquals('Newman', $location->last_name);
115
-        $this->assertEquals('[email protected]', $location->address_email);
116
-        $this->assertEquals('65432178', $location->address_phone_number);
117
-        $this->assertEquals('Louisville', $location->address_city);
118
-    }
119
-
120
-    public function testToArray()
121
-    {
122
-        $location = AddressBookLocation::fromArray([
123
-            'address_1'             => '1604 PARKRIDGE PKWY, Louisville, KY, 40214',
124
-            'cached_lat'            => 38.141598,
125
-            'cached_lng'            => -85.793846,
126
-            'address_alias'         => '1604 PARKRIDGE PKWY 40214',
127
-            'address_group'         => 'Scheduled daily',
128
-            'first_name'            => 'Peter',
129
-            'last_name'             => 'Newman',
130
-            'address_email'         => '[email protected]',
131
-            'address_phone_number'  => '65432178',
132
-            'address_city'          => 'Louisville',
133
-            'address_custom_data'   => ['scheduled'     => 'yes',
134
-                'serice type'   => 'publishing', ],
135
-            'schedule' => [[
136
-                'enabled'   => true,
137
-                'mode'      => 'daily',
138
-                'daily'     => ['every' => 1],
139
-            ]],
140
-            'service_time'          => 900,
141
-        ]);
142
-
143
-        $this->assertEquals($location->toArray(),
144
-            [
145
-                'address_1'             => '1604 PARKRIDGE PKWY, Louisville, KY, 40214',
146
-                'cached_lat'            => 38.141598,
147
-                'cached_lng'            => -85.793846,
148
-                'address_alias'         => '1604 PARKRIDGE PKWY 40214',
149
-                'address_group'         => 'Scheduled daily',
150
-                'first_name'            => 'Peter',
151
-                'last_name'             => 'Newman',
152
-                'address_email'         => '[email protected]',
153
-                'address_phone_number'  => '65432178',
154
-                'address_city'          => 'Louisville',
155
-                'address_custom_data'   => ['scheduled'     => 'yes',
156
-                    'serice type'   => 'publishing', ],
157
-                'schedule' => [[
158
-                    'enabled'   => true,
159
-                    'mode'      => 'daily',
160
-                    'daily'     => ['every' => 1],
161
-                ]],
162
-                'service_time'          => 900,
163
-            ]
164
-        );
165
-    }
166
-
167
-    public function testGetAddressBookLocation()
168
-    {
169
-        $abl = new AddressBookLocation();
170
-
171
-        $addressID = self::$createdContacts[0]->address_id;
172
-
173
-        $result = AddressBookLocation::fromArray(
174
-            $abl->getAddressBookLocation($addressID)
175
-        );
176
-
177
-        $this->assertNotNull($addressID);
178
-        $this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$result]);
179
-
180
-    }
181
-
182
-    public function testSearchAddressBookLocations()
183
-    {
184
-        $abl = new AddressBookLocation();
185
-
186
-        $params = [
187
-            'query'  => 'Douglas',
188
-            'fields' => 'first_name,address_email,schedule_blacklist,schedule,address_custom_data,address_1',
189
-            'offset' => 0,
190
-            'limit'  => 5,
191
-        ];
12
+	public static $createdContacts=[];
13
+
14
+	public static $csvImportedAddressIDs=[];
15
+
16
+	public static function setUpBeforeClass()
17
+	{
18
+		Route4Me::setApiKey(Constants::API_KEY);
19
+
20
+		$abl = new AddressBookLocation();
21
+
22
+		$AddressBookLocationParameters = AddressBookLocation::fromArray([
23
+			'address_1'             => '1407 MCCOY, Louisville, KY, 40215',
24
+			'address_alias'         => '1407 MCCOY 40215',
25
+			'address_group'         => 'Scheduled weekly',
26
+			'first_name'            => 'Bart',
27
+			'last_name'             => 'Douglas',
28
+			'address_email'         => '[email protected]',
29
+			'address_phone_number'  => '95487454',
30
+			'cached_lat'            => 38.202496,
31
+			'cached_lng'            => -85.786514,
32
+			'curbside_lat'          => 38.202496,
33
+			'curbside_lng'          => -85.786514,
34
+			'address_city'          => 'Louisville',
35
+			'schedule' => [[
36
+				'enabled'   => true,
37
+				'mode'      => 'weekly',
38
+				'weekly'    => [
39
+					'every'    => 1,
40
+					'weekdays' => [1, 2, 3, 4, 5],
41
+				],
42
+			]],
43
+			'service_time' => 600,
44
+		]);
45
+
46
+		self::$createdContacts[] = AddressBookLocation::fromArray(
47
+			$abl->addAdressBookLocation($AddressBookLocationParameters)
48
+		 );
49
+
50
+		$AddressBookLocationParameters = AddressBookLocation::fromArray([
51
+			'address_1'             => '4805 BELLEVUE AVE, Louisville, KY, 40215',
52
+			'address_2'             => '4806 BELLEVUE AVE, Louisville, KY, 40215',
53
+			'address_alias'         => '4805 BELLEVUE AVE 40215',
54
+			'address_group'         => 'Scheduled monthly',
55
+			'first_name'            => 'Bart',
56
+			'last_name'             => 'Douglas',
57
+			'address_email'         => '[email protected]',
58
+			'address_phone_number'  => '95487454',
59
+			'cached_lat'            => 38.178844,
60
+			'cached_lng'            => -85.774864,
61
+			'curbside_lat'          => 38.178844,
62
+			'curbside_lng'          => -85.774864,
63
+			'address_city'          => 'Louisville',
64
+			'address_country_id'    => 'US',
65
+			'address_state_id'      => 'KY',
66
+			'address_zip'           => '40215',
67
+			'schedule' => [[
68
+				'enabled'   => true,
69
+				'mode'      => 'monthly',
70
+				'monthly'   => [
71
+					'every' => 1,
72
+					'mode'  => 'dates',
73
+					'dates' => [20, 22, 23, 24, 25],
74
+				],
75
+			]],
76
+			'service_time' => 750,
77
+			'color'        => 'red',
78
+		]);
79
+
80
+		self::$createdContacts[] = AddressBookLocation::fromArray(
81
+			$abl->addAdressBookLocation($AddressBookLocationParameters)
82
+		);
83
+	}
84
+
85
+	public function testAddressBookLocationFromArray()
86
+	{
87
+		$location = AddressBookLocation::fromArray([
88
+			'address_1'             => '1604 PARKRIDGE PKWY, Louisville, KY, 40214',
89
+			'cached_lat'            => 38.141598,
90
+			'cached_lng'            => -85.793846,
91
+			'address_alias'         => '1604 PARKRIDGE PKWY 40214',
92
+			'address_group'         => 'Scheduled daily',
93
+			'first_name'            => 'Peter',
94
+			'last_name'             => 'Newman',
95
+			'address_email'         => '[email protected]',
96
+			'address_phone_number'  => '65432178',
97
+			'address_city'          => 'Louisville',
98
+			'address_custom_data'   => ['scheduled'     => 'yes',
99
+										'serice type'   => 'publishing', ],
100
+			'schedule' => [[
101
+				'enabled'   => true,
102
+				'mode'      => 'daily',
103
+				'daily'     => ['every' => 1],
104
+			]],
105
+			'service_time'          => 900,
106
+		]);
107
+
108
+		$this->assertEquals('1604 PARKRIDGE PKWY, Louisville, KY, 40214', $location->address_1);
109
+		$this->assertEquals(38.141598, $location->cached_lat);
110
+		$this->assertEquals(-85.793846, $location->cached_lng);
111
+		$this->assertEquals('1604 PARKRIDGE PKWY 40214', $location->address_alias);
112
+
113
+		$this->assertEquals('Peter', $location->first_name);
114
+		$this->assertEquals('Newman', $location->last_name);
115
+		$this->assertEquals('[email protected]', $location->address_email);
116
+		$this->assertEquals('65432178', $location->address_phone_number);
117
+		$this->assertEquals('Louisville', $location->address_city);
118
+	}
119
+
120
+	public function testToArray()
121
+	{
122
+		$location = AddressBookLocation::fromArray([
123
+			'address_1'             => '1604 PARKRIDGE PKWY, Louisville, KY, 40214',
124
+			'cached_lat'            => 38.141598,
125
+			'cached_lng'            => -85.793846,
126
+			'address_alias'         => '1604 PARKRIDGE PKWY 40214',
127
+			'address_group'         => 'Scheduled daily',
128
+			'first_name'            => 'Peter',
129
+			'last_name'             => 'Newman',
130
+			'address_email'         => '[email protected]',
131
+			'address_phone_number'  => '65432178',
132
+			'address_city'          => 'Louisville',
133
+			'address_custom_data'   => ['scheduled'     => 'yes',
134
+				'serice type'   => 'publishing', ],
135
+			'schedule' => [[
136
+				'enabled'   => true,
137
+				'mode'      => 'daily',
138
+				'daily'     => ['every' => 1],
139
+			]],
140
+			'service_time'          => 900,
141
+		]);
142
+
143
+		$this->assertEquals($location->toArray(),
144
+			[
145
+				'address_1'             => '1604 PARKRIDGE PKWY, Louisville, KY, 40214',
146
+				'cached_lat'            => 38.141598,
147
+				'cached_lng'            => -85.793846,
148
+				'address_alias'         => '1604 PARKRIDGE PKWY 40214',
149
+				'address_group'         => 'Scheduled daily',
150
+				'first_name'            => 'Peter',
151
+				'last_name'             => 'Newman',
152
+				'address_email'         => '[email protected]',
153
+				'address_phone_number'  => '65432178',
154
+				'address_city'          => 'Louisville',
155
+				'address_custom_data'   => ['scheduled'     => 'yes',
156
+					'serice type'   => 'publishing', ],
157
+				'schedule' => [[
158
+					'enabled'   => true,
159
+					'mode'      => 'daily',
160
+					'daily'     => ['every' => 1],
161
+				]],
162
+				'service_time'          => 900,
163
+			]
164
+		);
165
+	}
166
+
167
+	public function testGetAddressBookLocation()
168
+	{
169
+		$abl = new AddressBookLocation();
170
+
171
+		$addressID = self::$createdContacts[0]->address_id;
172
+
173
+		$result = AddressBookLocation::fromArray(
174
+			$abl->getAddressBookLocation($addressID)
175
+		);
176
+
177
+		$this->assertNotNull($addressID);
178
+		$this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$result]);
179
+
180
+	}
181
+
182
+	public function testSearchAddressBookLocations()
183
+	{
184
+		$abl = new AddressBookLocation();
185
+
186
+		$params = [
187
+			'query'  => 'Douglas',
188
+			'fields' => 'first_name,address_email,schedule_blacklist,schedule,address_custom_data,address_1',
189
+			'offset' => 0,
190
+			'limit'  => 5,
191
+		];
192 192
                                                                                                                                 
193
-        $result =  SearchResponse::fromArray(
194
-            $abl->searchAddressBookLocations($params)
195
-        );
193
+		$result =  SearchResponse::fromArray(
194
+			$abl->searchAddressBookLocations($params)
195
+		);
196 196
 
197
-        $this->assertNotNull($result);
198
-        $this->assertTrue(sizeof($result->fields)==6);
199
-        $this->assertContains('first_name',$result->fields);
200
-        $this->assertContains('address_email',$result->fields);
197
+		$this->assertNotNull($result);
198
+		$this->assertTrue(sizeof($result->fields)==6);
199
+		$this->assertContains('first_name',$result->fields);
200
+		$this->assertContains('address_email',$result->fields);
201 201
 
202
-        $this->assertNotNull($result->results);
202
+		$this->assertNotNull($result->results);
203 203
 
204
-        $txt = json_encode($result->results[0]);
204
+		$txt = json_encode($result->results[0]);
205 205
 
206
-        $firstRecord = strtolower($txt);
206
+		$firstRecord = strtolower($txt);
207 207
         
208
-        $this->assertTrue(strpos($firstRecord, 'douglas')>=0);
209
-    }
208
+		$this->assertTrue(strpos($firstRecord, 'douglas')>=0);
209
+	}
210 210
 
211
-    public function testGetAddressBookLocations()
212
-    {
213
-        $abl = new AddressBookLocation();
211
+	public function testGetAddressBookLocations()
212
+	{
213
+		$abl = new AddressBookLocation();
214 214
 
215
-        $AddressBookLocationParameters = [
216
-            'limit'  => 5,
217
-            'offset' => 0,
218
-        ];
215
+		$AddressBookLocationParameters = [
216
+			'limit'  => 5,
217
+			'offset' => 0,
218
+		];
219 219
 
220
-        $result = SearchResponse::fromArray(
221
-            $abl->getAddressBookLocations($AddressBookLocationParameters)
222
-        );
220
+		$result = SearchResponse::fromArray(
221
+			$abl->getAddressBookLocations($AddressBookLocationParameters)
222
+		);
223 223
 
224
-        $firstLocation = AddressBookLocation::fromArray(
225
-            $result->results[0]
226
-        );
224
+		$firstLocation = AddressBookLocation::fromArray(
225
+			$result->results[0]
226
+		);
227 227
 
228
-        $this->assertNotNull($result);
229
-        $this->assertNotNull($result->results);
230
-        $this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$firstLocation]);
231
-    }
228
+		$this->assertNotNull($result);
229
+		$this->assertNotNull($result->results);
230
+		$this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$firstLocation]);
231
+	}
232 232
 
233
-    public function testGetRandomAddressBookLocation()
234
-    {
235
-        $AddressBookLocationParameters = [
236
-            'limit'  => 30,
237
-            'offset' => 0,
238
-        ];
239
-
240
-        $result = AddressBookLocation::fromArray(
241
-            AddressBookLocation::getRandomAddressBookLocation($AddressBookLocationParameters)
242
-        );
243
-
244
-        $this->assertNotNull($result);
245
-        $this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$result]);
246
-    }
247
-
248
-    public function testAddAdressBookLocation()
249
-    {
250
-        $abl = new AddressBookLocation();
251
-
252
-        $AddressBookLocationParameters = AddressBookLocation::fromArray([
253
-            'first_name'    => 'Test FirstName '.strval(rand(10000, 99999)),
254
-            'address_1'     => 'Test Address1 '.strval(rand(10000, 99999)),
255
-            'cached_lat'    => 38.024654,
256
-            'cached_lng'    => -77.338814,
257
-        ]);
258
-
259
-        $result = AddressBookLocation::fromArray(
260
-            $abl->addAdressBookLocation($AddressBookLocationParameters)
261
-        );
262
-
263
-        $this->assertNotNull($result);
264
-        $this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$result]);
265
-
266
-        self::$createdContacts[] = $result;
267
-    }
268
-
269
-    public function testDeleteAdressBookLocation()
270
-    {
271
-        $abl = new AddressBookLocation();
272
-
273
-        $lastContact = end(self::$createdContacts);
274
-
275
-        $deleteResult = $abl->deleteAdressBookLocation([$lastContact->address_id]);
276
-
277
-        $this->assertTrue(isset($deleteResult['status']), 'Address Book Location delete operation failed!.. <br>');
278
-        $this->assertTrue($deleteResult['status'], 'Address Book Location delete operation failed!.. <br>');
279
-
280
-        self::$createdContacts[] = array_pop(self::$createdContacts);
281
-    }
282
-
283
-    public function testUpdateAddressBookLocation()
284
-    {
285
-        $abl = new AddressBookLocation();
286
-
287
-        reset(self::$createdContacts);
288
-
289
-        $firstContact = self::$createdContacts[0];
290
-
291
-        $firstContact->first_name = $firstContact->first_name.' updated';
292
-
293
-        $result = AddressBookLocation::fromArray(
294
-            $abl->updateAddressBookLocation($firstContact)
295
-        );
296
-
297
-        $this->assertNotNull($result);
298
-        $this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$result]);
299
-        $this->assertEquals($firstContact->first_name, $result->first_name);
300
-    }
301
-
302
-    public function testValidateScheduleMode()
303
-    {
304
-        $this->assertTrue(AddressBookLocation::validateScheduleMode('daily'));
305
-        $this->assertTrue(AddressBookLocation::validateScheduleMode('weekly'));
306
-        $this->assertTrue(AddressBookLocation::validateScheduleMode('monthly'));
307
-        $this->assertTrue(AddressBookLocation::validateScheduleMode('annually'));
308
-
309
-        $this->assertFalse(AddressBookLocation::validateScheduleMode('wrongMode'));
310
-    }
311
-
312
-    public function testValidateScheduleEnable()
313
-    {
314
-        $this->assertTrue(AddressBookLocation::validateScheduleEnable(true));
315
-        $this->assertTrue(AddressBookLocation::validateScheduleEnable(false));
316
-
317
-        $this->assertFalse(AddressBookLocation::validateScheduleEnable('wrongValue'));
318
-        $this->assertFalse(AddressBookLocation::validateScheduleEnable(null));
319
-    }
320
-
321
-    public function testValidateScheduleEvery()
322
-    {
323
-        $this->assertTrue(AddressBookLocation::validateScheduleEvery(1));
324
-        $this->assertTrue(AddressBookLocation::validateScheduleEvery(8));
325
-
326
-        $this->assertFalse(AddressBookLocation::validateScheduleEvery(0));
327
-        $this->assertFalse(AddressBookLocation::validateScheduleEvery(-1));
328
-        $this->assertFalse(AddressBookLocation::validateScheduleEvery('stringValue'));
329
-        $this->assertFalse(AddressBookLocation::validateScheduleEvery(true));
330
-        $this->assertFalse(AddressBookLocation::validateScheduleEvery(null));
331
-    }
332
-
333
-    public function testValidateScheduleWeekDays()
334
-    {
335
-        $this->assertTrue(AddressBookLocation::validateScheduleWeekDays('1,2,3,4,5,6,7'));
336
-
337
-        $this->assertFalse(AddressBookLocation::validateScheduleWeekDays('1,2,3,4,5,6,7,8'));
338
-        $this->assertFalse(AddressBookLocation::validateScheduleWeekDays('1,-2,3,4,5,6,7'));
339
-        $this->assertFalse(AddressBookLocation::validateScheduleWeekDays(true));
340
-        $this->assertTrue(AddressBookLocation::validateScheduleWeekDays(4));
341
-        $this->assertFalse(AddressBookLocation::validateScheduleWeekDays('dds'));
342
-    }
343
-
344
-    public function testValidateScheduleMonthlyMode()
345
-    {
346
-        $this->assertTrue(AddressBookLocation::validateScheduleMonthlyMode('dates'));
347
-        $this->assertTrue(AddressBookLocation::validateScheduleMonthlyMode('nth' ));
348
-
349
-        $this->assertFalse(AddressBookLocation::validateScheduleMonthlyMode('wrongParam' ));
350
-        $this->assertFalse(AddressBookLocation::validateScheduleMonthlyMode(4 ));
351
-        $this->assertFalse(AddressBookLocation::validateScheduleMonthlyMode(true ));
352
-    }
353
-
354
-    public function testValidateScheduleMonthlyDates()
355
-    {
356
-        $this->assertTrue(AddressBookLocation::validateScheduleMonthlyDates('1,2,3,7,31'));
357
-        $this->assertTrue(AddressBookLocation::validateScheduleMonthlyDates('12,21,23,24,28'));
358
-
359
-        $this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates('0,2,3,7,31'));
360
-        $this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates('0,2,3,7,33'));
361
-        $this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates('-1,2,3,7'));
362
-        $this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates('wrongText'));
363
-        $this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates(true));
364
-        $this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates(false));
365
-    }
366
-
367
-    public function testValidateScheduleNthN()
368
-    {
369
-        $this->assertTrue(AddressBookLocation::validateScheduleNthN(1));
370
-        $this->assertTrue(AddressBookLocation::validateScheduleNthN(2));
371
-        $this->assertTrue(AddressBookLocation::validateScheduleNthN(3));
372
-        $this->assertTrue(AddressBookLocation::validateScheduleNthN(4));
373
-        $this->assertTrue(AddressBookLocation::validateScheduleNthN(5));
374
-        $this->assertTrue(AddressBookLocation::validateScheduleNthN(-1));
375
-
376
-        $this->assertFalse(AddressBookLocation::validateScheduleNthN(-5));
377
-        $this->assertFalse(AddressBookLocation::validateScheduleNthN(0));
378
-        $this->assertFalse(AddressBookLocation::validateScheduleNthN(7));
379
-        $this->assertFalse(AddressBookLocation::validateScheduleNthN(true));
380
-        $this->assertFalse(AddressBookLocation::validateScheduleNthN(false));
381
-        $this->assertFalse(AddressBookLocation::validateScheduleNthN('wrongText'));
382
-    }
383
-
384
-    public function testValidateScheduleNthWhat()
385
-    {
386
-        for ($i=1;$i<11;$i++) $this->assertTrue(AddressBookLocation::validateScheduleNthWhat($i));
387
-
388
-        $this->assertFalse(AddressBookLocation::validateScheduleNthWhat(0));
389
-        $this->assertFalse(AddressBookLocation::validateScheduleNthWhat(14));
390
-        $this->assertFalse(AddressBookLocation::validateScheduleNthWhat(true));
391
-        $this->assertFalse(AddressBookLocation::validateScheduleNthWhat(false));
392
-        $this->assertFalse(AddressBookLocation::validateScheduleNthWhat('wrongText'));
393
-    }
394
-
395
-    public function testAddLocationsFromCsvFile()
396
-    {
397
-        $root = realpath(dirname(__FILE__).'/../../');
398
-        $source_file = $root.'/UnitTestFiles/Test/data/addresses_10.csv';
399
-
400
-        $locationsFieldsMapping['cached_lat'] = 0;
401
-        $locationsFieldsMapping['cached_lng'] = 1;
402
-        $locationsFieldsMapping['address_alias'] = 2;
403
-        $locationsFieldsMapping['address_1'] = 3;
404
-        $locationsFieldsMapping['address_city'] = 4;
405
-        $locationsFieldsMapping['address_state_id'] = 5;
406
-        $locationsFieldsMapping['address_zip'] = 6;
407
-        $locationsFieldsMapping['address_phone_number'] = 7;
408
-        $locationsFieldsMapping['schedule_mode'] = 8;
409
-        $locationsFieldsMapping['schedule_enabled'] = 9;
410
-        $locationsFieldsMapping['schedule_every'] = 10;
411
-        $locationsFieldsMapping['schedule_weekdays'] = 11;
412
-        $locationsFieldsMapping['monthly_mode'] = 12;
413
-        $locationsFieldsMapping['monthly_dates'] = 13;
414
-        $locationsFieldsMapping['monthly_nth_n'] = 14;
415
-        $locationsFieldsMapping['monthly_nth_what'] = 15;
416
-        $locationsFieldsMapping['anually_nth_n'] = 16;
417
-        $locationsFieldsMapping['anually_nth_what'] = 17;
418
-
419
-        $handle = fopen("$source_file", 'r');
420
-
421
-        $this->assertNotNull($handle);
422
-
423
-        $abl = new AddressBookLocation();
424
-
425
-        $results = $abl->addLocationsFromCsvFile($handle, $locationsFieldsMapping);
426
-
427
-        $this->assertNotNull($results);
428
-
429
-        $this->assertTrue(isset($results['success']));
430
-
431
-        $this->assertTrue(isset($results['fail']));
432
-
433
-        foreach ($results['success'] as $sc) {
434
-            self::$csvImportedAddressIDs[] = filter_var($sc, FILTER_SANITIZE_NUMBER_INT);
435
-        }
436
-
437
-        $this->assertTrue(sizeof(self::$csvImportedAddressIDs)==10);
438
-    }
439
-
440
-    public static function tearDownAfterClass()
441
-    {
442
-        $addressBookLocations=[];
443
-
444
-        foreach (self::$createdContacts as $createdContact) {
445
-            $addressBookLocations[] = $createdContact->address_id;
446
-        }
447
-
448
-        $addressBookLocations = array_merge($addressBookLocations,self::$csvImportedAddressIDs);
449
-
450
-        $abl = new AddressBookLocation();
451
-
452
-        $deleteResult = $abl->deleteAdressBookLocation($addressBookLocations);
453
-
454
-        if (isset($deleteResult['status']) && $deleteResult['status']) {
455
-            echo "Created contacts were removed.<br>";
456
-        }
457
-    }
233
+	public function testGetRandomAddressBookLocation()
234
+	{
235
+		$AddressBookLocationParameters = [
236
+			'limit'  => 30,
237
+			'offset' => 0,
238
+		];
239
+
240
+		$result = AddressBookLocation::fromArray(
241
+			AddressBookLocation::getRandomAddressBookLocation($AddressBookLocationParameters)
242
+		);
243
+
244
+		$this->assertNotNull($result);
245
+		$this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$result]);
246
+	}
247
+
248
+	public function testAddAdressBookLocation()
249
+	{
250
+		$abl = new AddressBookLocation();
251
+
252
+		$AddressBookLocationParameters = AddressBookLocation::fromArray([
253
+			'first_name'    => 'Test FirstName '.strval(rand(10000, 99999)),
254
+			'address_1'     => 'Test Address1 '.strval(rand(10000, 99999)),
255
+			'cached_lat'    => 38.024654,
256
+			'cached_lng'    => -77.338814,
257
+		]);
258
+
259
+		$result = AddressBookLocation::fromArray(
260
+			$abl->addAdressBookLocation($AddressBookLocationParameters)
261
+		);
262
+
263
+		$this->assertNotNull($result);
264
+		$this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$result]);
265
+
266
+		self::$createdContacts[] = $result;
267
+	}
268
+
269
+	public function testDeleteAdressBookLocation()
270
+	{
271
+		$abl = new AddressBookLocation();
272
+
273
+		$lastContact = end(self::$createdContacts);
274
+
275
+		$deleteResult = $abl->deleteAdressBookLocation([$lastContact->address_id]);
276
+
277
+		$this->assertTrue(isset($deleteResult['status']), 'Address Book Location delete operation failed!.. <br>');
278
+		$this->assertTrue($deleteResult['status'], 'Address Book Location delete operation failed!.. <br>');
279
+
280
+		self::$createdContacts[] = array_pop(self::$createdContacts);
281
+	}
282
+
283
+	public function testUpdateAddressBookLocation()
284
+	{
285
+		$abl = new AddressBookLocation();
286
+
287
+		reset(self::$createdContacts);
288
+
289
+		$firstContact = self::$createdContacts[0];
290
+
291
+		$firstContact->first_name = $firstContact->first_name.' updated';
292
+
293
+		$result = AddressBookLocation::fromArray(
294
+			$abl->updateAddressBookLocation($firstContact)
295
+		);
296
+
297
+		$this->assertNotNull($result);
298
+		$this->assertContainsOnlyInstancesOf(AddressBookLocation::class, [$result]);
299
+		$this->assertEquals($firstContact->first_name, $result->first_name);
300
+	}
301
+
302
+	public function testValidateScheduleMode()
303
+	{
304
+		$this->assertTrue(AddressBookLocation::validateScheduleMode('daily'));
305
+		$this->assertTrue(AddressBookLocation::validateScheduleMode('weekly'));
306
+		$this->assertTrue(AddressBookLocation::validateScheduleMode('monthly'));
307
+		$this->assertTrue(AddressBookLocation::validateScheduleMode('annually'));
308
+
309
+		$this->assertFalse(AddressBookLocation::validateScheduleMode('wrongMode'));
310
+	}
311
+
312
+	public function testValidateScheduleEnable()
313
+	{
314
+		$this->assertTrue(AddressBookLocation::validateScheduleEnable(true));
315
+		$this->assertTrue(AddressBookLocation::validateScheduleEnable(false));
316
+
317
+		$this->assertFalse(AddressBookLocation::validateScheduleEnable('wrongValue'));
318
+		$this->assertFalse(AddressBookLocation::validateScheduleEnable(null));
319
+	}
320
+
321
+	public function testValidateScheduleEvery()
322
+	{
323
+		$this->assertTrue(AddressBookLocation::validateScheduleEvery(1));
324
+		$this->assertTrue(AddressBookLocation::validateScheduleEvery(8));
325
+
326
+		$this->assertFalse(AddressBookLocation::validateScheduleEvery(0));
327
+		$this->assertFalse(AddressBookLocation::validateScheduleEvery(-1));
328
+		$this->assertFalse(AddressBookLocation::validateScheduleEvery('stringValue'));
329
+		$this->assertFalse(AddressBookLocation::validateScheduleEvery(true));
330
+		$this->assertFalse(AddressBookLocation::validateScheduleEvery(null));
331
+	}
332
+
333
+	public function testValidateScheduleWeekDays()
334
+	{
335
+		$this->assertTrue(AddressBookLocation::validateScheduleWeekDays('1,2,3,4,5,6,7'));
336
+
337
+		$this->assertFalse(AddressBookLocation::validateScheduleWeekDays('1,2,3,4,5,6,7,8'));
338
+		$this->assertFalse(AddressBookLocation::validateScheduleWeekDays('1,-2,3,4,5,6,7'));
339
+		$this->assertFalse(AddressBookLocation::validateScheduleWeekDays(true));
340
+		$this->assertTrue(AddressBookLocation::validateScheduleWeekDays(4));
341
+		$this->assertFalse(AddressBookLocation::validateScheduleWeekDays('dds'));
342
+	}
343
+
344
+	public function testValidateScheduleMonthlyMode()
345
+	{
346
+		$this->assertTrue(AddressBookLocation::validateScheduleMonthlyMode('dates'));
347
+		$this->assertTrue(AddressBookLocation::validateScheduleMonthlyMode('nth' ));
348
+
349
+		$this->assertFalse(AddressBookLocation::validateScheduleMonthlyMode('wrongParam' ));
350
+		$this->assertFalse(AddressBookLocation::validateScheduleMonthlyMode(4 ));
351
+		$this->assertFalse(AddressBookLocation::validateScheduleMonthlyMode(true ));
352
+	}
353
+
354
+	public function testValidateScheduleMonthlyDates()
355
+	{
356
+		$this->assertTrue(AddressBookLocation::validateScheduleMonthlyDates('1,2,3,7,31'));
357
+		$this->assertTrue(AddressBookLocation::validateScheduleMonthlyDates('12,21,23,24,28'));
358
+
359
+		$this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates('0,2,3,7,31'));
360
+		$this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates('0,2,3,7,33'));
361
+		$this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates('-1,2,3,7'));
362
+		$this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates('wrongText'));
363
+		$this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates(true));
364
+		$this->assertFalse(AddressBookLocation::validateScheduleMonthlyDates(false));
365
+	}
366
+
367
+	public function testValidateScheduleNthN()
368
+	{
369
+		$this->assertTrue(AddressBookLocation::validateScheduleNthN(1));
370
+		$this->assertTrue(AddressBookLocation::validateScheduleNthN(2));
371
+		$this->assertTrue(AddressBookLocation::validateScheduleNthN(3));
372
+		$this->assertTrue(AddressBookLocation::validateScheduleNthN(4));
373
+		$this->assertTrue(AddressBookLocation::validateScheduleNthN(5));
374
+		$this->assertTrue(AddressBookLocation::validateScheduleNthN(-1));
375
+
376
+		$this->assertFalse(AddressBookLocation::validateScheduleNthN(-5));
377
+		$this->assertFalse(AddressBookLocation::validateScheduleNthN(0));
378
+		$this->assertFalse(AddressBookLocation::validateScheduleNthN(7));
379
+		$this->assertFalse(AddressBookLocation::validateScheduleNthN(true));
380
+		$this->assertFalse(AddressBookLocation::validateScheduleNthN(false));
381
+		$this->assertFalse(AddressBookLocation::validateScheduleNthN('wrongText'));
382
+	}
383
+
384
+	public function testValidateScheduleNthWhat()
385
+	{
386
+		for ($i=1;$i<11;$i++) $this->assertTrue(AddressBookLocation::validateScheduleNthWhat($i));
387
+
388
+		$this->assertFalse(AddressBookLocation::validateScheduleNthWhat(0));
389
+		$this->assertFalse(AddressBookLocation::validateScheduleNthWhat(14));
390
+		$this->assertFalse(AddressBookLocation::validateScheduleNthWhat(true));
391
+		$this->assertFalse(AddressBookLocation::validateScheduleNthWhat(false));
392
+		$this->assertFalse(AddressBookLocation::validateScheduleNthWhat('wrongText'));
393
+	}
394
+
395
+	public function testAddLocationsFromCsvFile()
396
+	{
397
+		$root = realpath(dirname(__FILE__).'/../../');
398
+		$source_file = $root.'/UnitTestFiles/Test/data/addresses_10.csv';
399
+
400
+		$locationsFieldsMapping['cached_lat'] = 0;
401
+		$locationsFieldsMapping['cached_lng'] = 1;
402
+		$locationsFieldsMapping['address_alias'] = 2;
403
+		$locationsFieldsMapping['address_1'] = 3;
404
+		$locationsFieldsMapping['address_city'] = 4;
405
+		$locationsFieldsMapping['address_state_id'] = 5;
406
+		$locationsFieldsMapping['address_zip'] = 6;
407
+		$locationsFieldsMapping['address_phone_number'] = 7;
408
+		$locationsFieldsMapping['schedule_mode'] = 8;
409
+		$locationsFieldsMapping['schedule_enabled'] = 9;
410
+		$locationsFieldsMapping['schedule_every'] = 10;
411
+		$locationsFieldsMapping['schedule_weekdays'] = 11;
412
+		$locationsFieldsMapping['monthly_mode'] = 12;
413
+		$locationsFieldsMapping['monthly_dates'] = 13;
414
+		$locationsFieldsMapping['monthly_nth_n'] = 14;
415
+		$locationsFieldsMapping['monthly_nth_what'] = 15;
416
+		$locationsFieldsMapping['anually_nth_n'] = 16;
417
+		$locationsFieldsMapping['anually_nth_what'] = 17;
418
+
419
+		$handle = fopen("$source_file", 'r');
420
+
421
+		$this->assertNotNull($handle);
422
+
423
+		$abl = new AddressBookLocation();
424
+
425
+		$results = $abl->addLocationsFromCsvFile($handle, $locationsFieldsMapping);
426
+
427
+		$this->assertNotNull($results);
428
+
429
+		$this->assertTrue(isset($results['success']));
430
+
431
+		$this->assertTrue(isset($results['fail']));
432
+
433
+		foreach ($results['success'] as $sc) {
434
+			self::$csvImportedAddressIDs[] = filter_var($sc, FILTER_SANITIZE_NUMBER_INT);
435
+		}
436
+
437
+		$this->assertTrue(sizeof(self::$csvImportedAddressIDs)==10);
438
+	}
439
+
440
+	public static function tearDownAfterClass()
441
+	{
442
+		$addressBookLocations=[];
443
+
444
+		foreach (self::$createdContacts as $createdContact) {
445
+			$addressBookLocations[] = $createdContact->address_id;
446
+		}
447
+
448
+		$addressBookLocations = array_merge($addressBookLocations,self::$csvImportedAddressIDs);
449
+
450
+		$abl = new AddressBookLocation();
451
+
452
+		$deleteResult = $abl->deleteAdressBookLocation($addressBookLocations);
453
+
454
+		if (isset($deleteResult['status']) && $deleteResult['status']) {
455
+			echo "Created contacts were removed.<br>";
456
+		}
457
+	}
458 458
 }
459 459
\ No newline at end of file
Please login to merge, or discard this patch.
UnitTestFiles/Test/AddressUnitTests.php 1 patch
Indentation   +328 added lines, -328 removed lines patch added patch discarded remove patch
@@ -12,339 +12,339 @@
 block discarded – undo
12 12
 use Route4Me\RouteParameters;
13 13
 
14 14
 class AddressUnitTests extends \PHPUnit\Framework\TestCase {
15
-    protected $address;
16
-    public static $createdAddresses;
17
-
18
-    public static $problem;
19
-    public static $problemDest;
20
-
21
-    public static $route_id = null;
22
-    public static $address_id = null;
23
-    public static $address_address = null;
24
-    public static $address_lat = null;
25
-    public static $address_lng = null;
26
-    public static $address_is_depot = null;
27
-
28
-    public static $addresIdMarkedAsVisited;
29
-
30
-    public static $afterAddressId;
31
-    public static $route_id_dest;
32
-
33
-    public static function setUpBeforeClass()
34
-    {
35
-        if (Constants::API_KEY == Constants::DEMO_API_KEY) {
36
-            $className = str_replace('UnitTestFiles\\Test\\','',get_class());
37
-            self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" );
38
-        }
39
-
40
-        Route4Me::setApiKey(Constants::API_KEY);
41
-
42
-        //<editor-fold desc="Prepare Addresses">
43
-        $addresses = [];
44
-        $addresses[] = Address::fromArray([
45
-            'address'           => '11497 Columbia Park Dr W, Jacksonville, FL 32258',
46
-            'is_depot'          => true,
47
-            'lat'               => 30.159341812134,
48
-            'lng'               => -81.538619995117,
49
-            'time'              => 300,
50
-            'time_window_start' => 28800,
51
-            'time_window_end'   => 32400,
52
-        ]);
53
-
54
-        $addresses[] = Address::fromArray([
55
-            'address'           => '214 Edgewater Branch Drive 32259',
56
-            'lat'               => 30.103567123413,
57
-            'lng'               => -81.595352172852,
58
-            'time'              => 300,
59
-            'time_window_start' => 36000,
60
-            'time_window_end'   => 37200,
61
-        ]);
62
-
63
-        $addresses[] = Address::fromArray([
64
-            'address'           => '756 eagle point dr 32092',
65
-            'lat'               => 30.046422958374,
66
-            'lng'               => -81.508758544922,
67
-            'time'              => 300,
68
-            'time_window_start' => 39600,
69
-            'time_window_end'   => 41400,
70
-        ]);
71
-
72
-        $addresses[] = Address::fromArray([
73
-            'address'           => '63 Stone Creek Cir St Johns, FL 32259, USA',
74
-            'lat'               => 30.048496,
75
-            'lng'               => -81.558716,
76
-            'time'              => 300,
77
-            'time_window_start' => 43200,
78
-            'time_window_end'   => 45000,
79
-        ]);
80
-
81
-        $addresses[] = Address::fromArray([
82
-            'address'           => 'St Johns Florida 32259, USA',
83
-            'lat'               => 30.099642,
84
-            'lng'               => -81.547201,
85
-            'time'              => 300,
86
-            'time_window_start' => 46800,
87
-            'time_window_end'   => 48600,
88
-        ]);
89
-
90
-        $parameters = RouteParameters::fromArray([
91
-            'device_type'           => DeviceType::IPAD,
92
-            'disable_optimization'  => false,
93
-            'route_name'            => 'phpunit test '.date('Y-m-d H:i'),
94
-        ]);
95
-        //</editor-fold>
96
-
97
-        $optimizationParameters = new OptimizationProblemParams();
98
-        $optimizationParameters->setAddresses($addresses);
99
-        $optimizationParameters->setParameters($parameters);
100
-
101
-        self::$problem = OptimizationProblem::optimize($optimizationParameters);
102
-        $routes = self::$problem->getRoutes();
103
-        self::$route_id = $routes[0]->route_id;
104
-        self::$createdAddresses = $routes[0]->addresses;
105
-
106
-        self::$problemDest = OptimizationProblem::optimize($optimizationParameters);
107
-        $routesDest = self::$problemDest->getRoutes();
108
-        $addressesDest = $routesDest[0]->addresses;
109
-        self::$route_id_dest = $routesDest[0]->route_id;
110
-        self::$afterAddressId = $addressesDest[2]->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
-        self::$addresIdMarkedAsVisited = $addresses[2]->getAddressId();
120
-
121
-        $params = [
122
-            'route_id'      =>  self::$route_id,
123
-            'address_id'    =>  self::$addresIdMarkedAsVisited,
124
-            'is_visited'    => 1
125
-        ];
126
-
127
-        $result =  $addresses[2]->markAsVisited($params);
128
-
129
-    }
130
-
131
-    public function testAddressFromArray()
132
-    {
133
-        $address = Address::fromArray([
134
-            'address'           => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407',
135
-            'lat'               => 38.2513427734,
136
-            'lng'               => -77.5993652344,
137
-            'time'              => 300,
138
-            'time_window_end'   => 75600,
139
-            'time_window_start' => 28800,
140
-        ]);
141
-
142
-        $this->assertEquals($address->address, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407');
143
-        $this->assertEquals($address->lat, 38.2513427734);
144
-        $this->assertEquals($address->lng, -77.5993652344);
145
-        $this->assertEquals($address->time, 300);
146
-        $this->assertEquals($address->time_window_start, 28800);
147
-        $this->assertEquals($address->time_window_end, 75600);
148
-    }
149
-
150
-    public function testToArray()
151
-    {
152
-        $address = Address::fromArray([
153
-            'address'           => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407',
154
-            'lat'               => 38.2513427734,
155
-            'lng'               => -77.5993652344,
156
-            'time'              => 300,
157
-            'time_window_end'   => 75600,
158
-            'time_window_start' => 28800,
159
-            'custom_fields'     => [
160
-                'cf_1' => 1,
161
-            ],
162
-        ]);
163
-
164
-        $this->assertEquals($address->toArray(), [
165
-            'address'           => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407',
166
-            'lat'               => 38.2513427734,
167
-            'lng'               => -77.5993652344,
168
-            'is_depot'          => false,
169
-            'time'              => 300,
170
-            'time_window_end'   => 75600,
171
-            'time_window_start' => 28800,
172
-            'custom_fields'     => [
173
-                'cf_1' => 1,
174
-            ],
175
-        ]);
176
-    }
177
-
178
-    public function testBadParameter()
179
-    {
180
-        $this->expectException(BadParam::class);
181
-
182
-        $address = Address::fromArray([
183
-            'lat1' => 38.2513427734,
184
-            'lng1' => -77.5993652344,
185
-        ]);
186
-
187
-        echo "address: ".$address->lat." <br>";
188
-    }
189
-
190
-    public function testAddressFromArrayWithBadKeys()
191
-    {
192
-        $this->expectException(BadParam::class);
193
-
194
-        $address = Address::fromArray([
195
-            'address'       => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407',
196
-            'lat'           => 38.2513427734,
197
-            'lng'           => -77.5993652344,
198
-            'demoaddress'   => '333333',
199
-        ]);
200
-
201
-        $this->assertNotNull($address->address);
202
-        $this->assertEquals($address->address, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407');
203
-        $this->assertEquals($address->lat, 38.2513427734);
204
-        $this->assertEquals($address->lng, -77.5993652344);
205
-
206
-        $this->assertFalse(property_exists($address, 'demoaddress'));
207
-    }
208
-
209
-    public function testGetAddress()
210
-    {
211
-        $address = Address::getAddress(self::$route_id, self::$address_id);
212
-
213
-        $this->assertNotNull($address);
214
-        $this->assertNotNull($address->address);
215
-        $this->assertEquals($address->address, self::$address_address);
216
-        $this->assertEquals($address->lat, self::$address_lat);
217
-        $this->assertEquals($address->lng, self::$address_lng);
218
-        $this->assertEquals($address->is_depot, self::$address_is_depot);
219
-
220
-        return $address;
221
-    }
222
-
223
-    public function testUpdateAddress()
224
-    {
225
-        $address = Address::getAddress(self::$route_id, self::$address_id);
226
-        $this->assertNotNull($address);
227
-
228
-        $address->route_id = self::$route_id;
229
-
230
-        $address->address = 'Updated address';
231
-        $newAddress = $address->update();
232
-
233
-        $this->assertEquals($newAddress->address, 'Updated address');
234
-    }
235
-
236
-    public function testMarkAsDeparted()
237
-    {
238
-        $address = new Address();
239
-
240
-        $params = [
241
-            'route_id'      =>  self::$route_id,
242
-            'address_id'    =>  self::$addresIdMarkedAsVisited,
243
-            'is_departed'   => 1
244
-        ];
245
-
246
-        $result = $address->markAsDeparted($params);
247
-
248
-        $this->assertNotNull($result);
249
-        $this->assertIsBool($result['status']);
250
-        $this->assertTrue($result['status']);
251
-    }
252
-
253
-    public function testMarkAsVisited()
254
-    {
255
-        $address = new Address();
256
-
257
-        $params = [
258
-            'route_id'   =>  self::$route_id,
259
-            'address_id' =>  self::$address_id,
260
-            'is_visited' => 1
261
-        ];
262
-
263
-        $result = $address->markAsVisited($params);
264
-
265
-        $this->assertNotNull($result);
266
-        $this->assertIsInt($result);
267
-        $this->assertEquals(1,$result);
268
-    }
269
-
270
-    public function testDeleteAddress()
271
-    {
272
-        $lastAddressId = self::$createdAddresses[sizeof(self::$createdAddresses)-1]->route_destination_id;
273
-
274
-        $address = Address::getAddress(self::$route_id, $lastAddressId);
275
-        $this->assertNotNull($address);
276
-
277
-        $state = $address->deleteAddress();
278
-        $this->assertTrue($state);
279
-
280
-        array_pop(self::$createdAddresses);
281
-    }
282
-
283
-    public function testMoveDestinationToRoute()
284
-    {
285
-        $lastAddressId = self::$createdAddresses[sizeof(self::$createdAddresses)-1]->route_destination_id;
286
-
287
-        // Move the destination to the route
288
-        $routeParams = [
289
-            'to_route_id'           => self::$route_id_dest,
290
-            'route_destination_id'  => $lastAddressId,
291
-            'after_destination_id'  => self::$afterAddressId,
292
-        ];
293
-
294
-        $address = new Address();
295
-        $result = $address->moveDestinationToRoute($routeParams);
296
-
297
-        $this->assertNotNull($result);
298
-        $this->assertNotNull($result['success']);
299
-        $this->assertEquals(true,$result['success']);
300
-    }
301
-
302
-    public function testChangeRouteDepote()
303
-    {
304
-        $address1 = Address::getAddress(
305
-            self::$route_id,
306
-            self::$createdAddresses[0]->route_destination_id);
15
+	protected $address;
16
+	public static $createdAddresses;
17
+
18
+	public static $problem;
19
+	public static $problemDest;
20
+
21
+	public static $route_id = null;
22
+	public static $address_id = null;
23
+	public static $address_address = null;
24
+	public static $address_lat = null;
25
+	public static $address_lng = null;
26
+	public static $address_is_depot = null;
27
+
28
+	public static $addresIdMarkedAsVisited;
29
+
30
+	public static $afterAddressId;
31
+	public static $route_id_dest;
32
+
33
+	public static function setUpBeforeClass()
34
+	{
35
+		if (Constants::API_KEY == Constants::DEMO_API_KEY) {
36
+			$className = str_replace('UnitTestFiles\\Test\\','',get_class());
37
+			self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" );
38
+		}
39
+
40
+		Route4Me::setApiKey(Constants::API_KEY);
41
+
42
+		//<editor-fold desc="Prepare Addresses">
43
+		$addresses = [];
44
+		$addresses[] = Address::fromArray([
45
+			'address'           => '11497 Columbia Park Dr W, Jacksonville, FL 32258',
46
+			'is_depot'          => true,
47
+			'lat'               => 30.159341812134,
48
+			'lng'               => -81.538619995117,
49
+			'time'              => 300,
50
+			'time_window_start' => 28800,
51
+			'time_window_end'   => 32400,
52
+		]);
53
+
54
+		$addresses[] = Address::fromArray([
55
+			'address'           => '214 Edgewater Branch Drive 32259',
56
+			'lat'               => 30.103567123413,
57
+			'lng'               => -81.595352172852,
58
+			'time'              => 300,
59
+			'time_window_start' => 36000,
60
+			'time_window_end'   => 37200,
61
+		]);
62
+
63
+		$addresses[] = Address::fromArray([
64
+			'address'           => '756 eagle point dr 32092',
65
+			'lat'               => 30.046422958374,
66
+			'lng'               => -81.508758544922,
67
+			'time'              => 300,
68
+			'time_window_start' => 39600,
69
+			'time_window_end'   => 41400,
70
+		]);
71
+
72
+		$addresses[] = Address::fromArray([
73
+			'address'           => '63 Stone Creek Cir St Johns, FL 32259, USA',
74
+			'lat'               => 30.048496,
75
+			'lng'               => -81.558716,
76
+			'time'              => 300,
77
+			'time_window_start' => 43200,
78
+			'time_window_end'   => 45000,
79
+		]);
80
+
81
+		$addresses[] = Address::fromArray([
82
+			'address'           => 'St Johns Florida 32259, USA',
83
+			'lat'               => 30.099642,
84
+			'lng'               => -81.547201,
85
+			'time'              => 300,
86
+			'time_window_start' => 46800,
87
+			'time_window_end'   => 48600,
88
+		]);
89
+
90
+		$parameters = RouteParameters::fromArray([
91
+			'device_type'           => DeviceType::IPAD,
92
+			'disable_optimization'  => false,
93
+			'route_name'            => 'phpunit test '.date('Y-m-d H:i'),
94
+		]);
95
+		//</editor-fold>
96
+
97
+		$optimizationParameters = new OptimizationProblemParams();
98
+		$optimizationParameters->setAddresses($addresses);
99
+		$optimizationParameters->setParameters($parameters);
100
+
101
+		self::$problem = OptimizationProblem::optimize($optimizationParameters);
102
+		$routes = self::$problem->getRoutes();
103
+		self::$route_id = $routes[0]->route_id;
104
+		self::$createdAddresses = $routes[0]->addresses;
105
+
106
+		self::$problemDest = OptimizationProblem::optimize($optimizationParameters);
107
+		$routesDest = self::$problemDest->getRoutes();
108
+		$addressesDest = $routesDest[0]->addresses;
109
+		self::$route_id_dest = $routesDest[0]->route_id;
110
+		self::$afterAddressId = $addressesDest[2]->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
+		self::$addresIdMarkedAsVisited = $addresses[2]->getAddressId();
120
+
121
+		$params = [
122
+			'route_id'      =>  self::$route_id,
123
+			'address_id'    =>  self::$addresIdMarkedAsVisited,
124
+			'is_visited'    => 1
125
+		];
126
+
127
+		$result =  $addresses[2]->markAsVisited($params);
128
+
129
+	}
130
+
131
+	public function testAddressFromArray()
132
+	{
133
+		$address = Address::fromArray([
134
+			'address'           => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407',
135
+			'lat'               => 38.2513427734,
136
+			'lng'               => -77.5993652344,
137
+			'time'              => 300,
138
+			'time_window_end'   => 75600,
139
+			'time_window_start' => 28800,
140
+		]);
141
+
142
+		$this->assertEquals($address->address, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407');
143
+		$this->assertEquals($address->lat, 38.2513427734);
144
+		$this->assertEquals($address->lng, -77.5993652344);
145
+		$this->assertEquals($address->time, 300);
146
+		$this->assertEquals($address->time_window_start, 28800);
147
+		$this->assertEquals($address->time_window_end, 75600);
148
+	}
149
+
150
+	public function testToArray()
151
+	{
152
+		$address = Address::fromArray([
153
+			'address'           => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407',
154
+			'lat'               => 38.2513427734,
155
+			'lng'               => -77.5993652344,
156
+			'time'              => 300,
157
+			'time_window_end'   => 75600,
158
+			'time_window_start' => 28800,
159
+			'custom_fields'     => [
160
+				'cf_1' => 1,
161
+			],
162
+		]);
163
+
164
+		$this->assertEquals($address->toArray(), [
165
+			'address'           => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407',
166
+			'lat'               => 38.2513427734,
167
+			'lng'               => -77.5993652344,
168
+			'is_depot'          => false,
169
+			'time'              => 300,
170
+			'time_window_end'   => 75600,
171
+			'time_window_start' => 28800,
172
+			'custom_fields'     => [
173
+				'cf_1' => 1,
174
+			],
175
+		]);
176
+	}
177
+
178
+	public function testBadParameter()
179
+	{
180
+		$this->expectException(BadParam::class);
181
+
182
+		$address = Address::fromArray([
183
+			'lat1' => 38.2513427734,
184
+			'lng1' => -77.5993652344,
185
+		]);
186
+
187
+		echo "address: ".$address->lat." <br>";
188
+	}
189
+
190
+	public function testAddressFromArrayWithBadKeys()
191
+	{
192
+		$this->expectException(BadParam::class);
193
+
194
+		$address = Address::fromArray([
195
+			'address'       => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407',
196
+			'lat'           => 38.2513427734,
197
+			'lng'           => -77.5993652344,
198
+			'demoaddress'   => '333333',
199
+		]);
200
+
201
+		$this->assertNotNull($address->address);
202
+		$this->assertEquals($address->address, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407');
203
+		$this->assertEquals($address->lat, 38.2513427734);
204
+		$this->assertEquals($address->lng, -77.5993652344);
205
+
206
+		$this->assertFalse(property_exists($address, 'demoaddress'));
207
+	}
208
+
209
+	public function testGetAddress()
210
+	{
211
+		$address = Address::getAddress(self::$route_id, self::$address_id);
212
+
213
+		$this->assertNotNull($address);
214
+		$this->assertNotNull($address->address);
215
+		$this->assertEquals($address->address, self::$address_address);
216
+		$this->assertEquals($address->lat, self::$address_lat);
217
+		$this->assertEquals($address->lng, self::$address_lng);
218
+		$this->assertEquals($address->is_depot, self::$address_is_depot);
219
+
220
+		return $address;
221
+	}
222
+
223
+	public function testUpdateAddress()
224
+	{
225
+		$address = Address::getAddress(self::$route_id, self::$address_id);
226
+		$this->assertNotNull($address);
227
+
228
+		$address->route_id = self::$route_id;
229
+
230
+		$address->address = 'Updated address';
231
+		$newAddress = $address->update();
232
+
233
+		$this->assertEquals($newAddress->address, 'Updated address');
234
+	}
235
+
236
+	public function testMarkAsDeparted()
237
+	{
238
+		$address = new Address();
239
+
240
+		$params = [
241
+			'route_id'      =>  self::$route_id,
242
+			'address_id'    =>  self::$addresIdMarkedAsVisited,
243
+			'is_departed'   => 1
244
+		];
245
+
246
+		$result = $address->markAsDeparted($params);
247
+
248
+		$this->assertNotNull($result);
249
+		$this->assertIsBool($result['status']);
250
+		$this->assertTrue($result['status']);
251
+	}
252
+
253
+	public function testMarkAsVisited()
254
+	{
255
+		$address = new Address();
256
+
257
+		$params = [
258
+			'route_id'   =>  self::$route_id,
259
+			'address_id' =>  self::$address_id,
260
+			'is_visited' => 1
261
+		];
262
+
263
+		$result = $address->markAsVisited($params);
264
+
265
+		$this->assertNotNull($result);
266
+		$this->assertIsInt($result);
267
+		$this->assertEquals(1,$result);
268
+	}
269
+
270
+	public function testDeleteAddress()
271
+	{
272
+		$lastAddressId = self::$createdAddresses[sizeof(self::$createdAddresses)-1]->route_destination_id;
273
+
274
+		$address = Address::getAddress(self::$route_id, $lastAddressId);
275
+		$this->assertNotNull($address);
276
+
277
+		$state = $address->deleteAddress();
278
+		$this->assertTrue($state);
279
+
280
+		array_pop(self::$createdAddresses);
281
+	}
282
+
283
+	public function testMoveDestinationToRoute()
284
+	{
285
+		$lastAddressId = self::$createdAddresses[sizeof(self::$createdAddresses)-1]->route_destination_id;
286
+
287
+		// Move the destination to the route
288
+		$routeParams = [
289
+			'to_route_id'           => self::$route_id_dest,
290
+			'route_destination_id'  => $lastAddressId,
291
+			'after_destination_id'  => self::$afterAddressId,
292
+		];
293
+
294
+		$address = new Address();
295
+		$result = $address->moveDestinationToRoute($routeParams);
296
+
297
+		$this->assertNotNull($result);
298
+		$this->assertNotNull($result['success']);
299
+		$this->assertEquals(true,$result['success']);
300
+	}
301
+
302
+	public function testChangeRouteDepote()
303
+	{
304
+		$address1 = Address::getAddress(
305
+			self::$route_id,
306
+			self::$createdAddresses[0]->route_destination_id);
307 307
 
308
-        $address1->route_id = self::$route_id;
309
-
310
-        $address2 = Address::getAddress(
311
-            self::$route_id,
312
-            self::$createdAddresses[1]->route_destination_id);
313
-
314
-        $address2->route_id = self::$route_id;
308
+		$address1->route_id = self::$route_id;
309
+
310
+		$address2 = Address::getAddress(
311
+			self::$route_id,
312
+			self::$createdAddresses[1]->route_destination_id);
313
+
314
+		$address2->route_id = self::$route_id;
315 315
 
316
-        $this->assertEquals(true, $address1->is_depot);
317
-        $this->assertEquals(false, $address2->is_depot);
316
+		$this->assertEquals(true, $address1->is_depot);
317
+		$this->assertEquals(false, $address2->is_depot);
318 318
 
319
-        $address1->is_depot = false;
320
-        $updatedAddress1 = $address1->update();
319
+		$address1->is_depot = false;
320
+		$updatedAddress1 = $address1->update();
321 321
 
322
-        $address2->is_depot = true;
323
-        $updatedAddress2 = $address2->update();
322
+		$address2->is_depot = true;
323
+		$updatedAddress2 = $address2->update();
324 324
 
325
-        $this->assertEquals(false, $updatedAddress1->is_depot);
326
-        $this->assertEquals(true, $updatedAddress2->is_depot);
327
-    }
325
+		$this->assertEquals(false, $updatedAddress1->is_depot);
326
+		$this->assertEquals(true, $updatedAddress2->is_depot);
327
+	}
328 328
 
329
-    public static function tearDownAfterClass()
330
-    {
331
-        $optimizationProblemId = self:: $problem->optimization_problem_id;
332
-        $destOptimizationProblemId = self::$problemDest->optimization_problem_id;
333
-
334
-        $params = [
335
-            'optimization_problem_ids' => [
336
-                '0' => $optimizationProblemId,
337
-                '1' => $destOptimizationProblemId
338
-            ],
339
-            'redirect' => 0,
340
-        ];
341
-
342
-        $result = self:: $problem->removeOptimization($params);
329
+	public static function tearDownAfterClass()
330
+	{
331
+		$optimizationProblemId = self:: $problem->optimization_problem_id;
332
+		$destOptimizationProblemId = self::$problemDest->optimization_problem_id;
333
+
334
+		$params = [
335
+			'optimization_problem_ids' => [
336
+				'0' => $optimizationProblemId,
337
+				'1' => $destOptimizationProblemId
338
+			],
339
+			'redirect' => 0,
340
+		];
341
+
342
+		$result = self:: $problem->removeOptimization($params);
343 343
 
344
-        if ($result!=null && $result['status']==true) {
345
-            echo "The test optimization was removed <br>";
346
-        } else {
347
-            echo "Cannot remove the test optimization <br>";
348
-        }
349
-    }
344
+		if ($result!=null && $result['status']==true) {
345
+			echo "The test optimization was removed <br>";
346
+		} else {
347
+			echo "Cannot remove the test optimization <br>";
348
+		}
349
+	}
350 350
 }
Please login to merge, or discard this patch.
UnitTestFiles/Test/TrackingTests.php 1 patch
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -26,260 +26,260 @@
 block discarded – undo
26 26
 
27 27
 class TrackingTests extends \PHPUnit\Framework\TestCase
28 28
 {
29
-    public static $createdProblems = [];
30
-    public static $testRoutes = [];
31
-
32
-    public static function setUpBeforeClass()
33
-    {
34
-        Route4Me::setApiKey(Constants::API_KEY);
35
-
36
-        $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true);
37
-
38
-        $addresses = [];
39
-        foreach ($json as $address) {
40
-            $addresses[] = Address::fromArray($address);
41
-        }
42
-
43
-        $parameters = RouteParameters::fromArray([
44
-            'algorithm_type'            => AlgorithmType::CVRP_TW_MD,
45
-            'distance_unit'             => DistanceUnit::MILES,
46
-            'device_type'               => DeviceType::WEB,
47
-            'optimize'                  => OptimizationType::DISTANCE,
48
-            'metric'                    => Metric::GEODESIC,
49
-            'route_max_duration'        => 86400 * 2,
50
-            'travel_mode'               => TravelMode::DRIVING,
51
-            'vehicle_capacity'          => 50,
52
-            'vehicle_max_distance_mi'   => 10000,
53
-            'parts'                     => 50,
54
-        ]);
55
-        //endregion
56
-
57
-        $optimizationParameters = new OptimizationProblemParams();
58
-        $optimizationParameters->setAddresses($addresses);
59
-        $optimizationParameters->setParameters($parameters);
60
-
61
-        self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters);
62
-
63
-        self::$testRoutes = self::$createdProblems[0]->routes;
64
-
65
-        $params = TrackSetParams::fromArray([
66
-            'format'            => Format::SERIALIZED,
67
-            'route_id'          => self::$testRoutes[0]->route_id,
68
-            'member_id'         => self::$testRoutes[0]->parameters->member_id,
69
-            'course'            => 1,
70
-            'speed'             => 120,
71
-            'lat'               => 41.8927521,
72
-            'lng'               => -109.0803888,
73
-            'device_type'       => 'android_phone',
74
-            'device_guid'       => 'qweqweqwe',
75
-            'device_timestamp'  => date('Y-m-d H:i:s', strtotime('-2 day')),
76
-        ]);
77
-
78
-        $status = Track ::set($params);
79
-
80
-        self::assertNotNull($status, "Cannot send GPS position to the selected route");
81
-        self::assertTrue(isset($status['status']), "Cannot send GPS position to the selected route");
82
-        self::assertTrue($status['status'], "Cannot send GPS position to the selected route");
83
-    }
84
-
85
-    public function testFromArray()
86
-    {
87
-        $trackingParams = TrackSetParams::fromArray([
88
-            'member_id'     => 44444,
89
-            'format'        => 'json',
90
-            'route_id'      => '489D597EE62534C906096F1AAC278D26',
91
-            'course'        => 72,
92
-            'speed'         => 65,
93
-            'lat'           => 38.218662,
94
-            'lng'           => -85.789032,
95
-            'device_type'   => 'android_phone',
96
-            'device_guid'   => 'HK5454H0K454564WWER445'
97
-        ]);
98
-
99
-        $this->assertEquals(44444, $trackingParams->member_id);
100
-        $this->assertEquals('489D597EE62534C906096F1AAC278D26', $trackingParams->route_id);
101
-
102
-        $this->assertEquals(72, $trackingParams->course);
103
-        $this->assertEquals(65, $trackingParams->speed);
104
-        $this->assertEquals(38.218662, $trackingParams->lat);
105
-        $this->assertEquals(-85.789032, $trackingParams->lng);
106
-        $this->assertEquals('android_phone', $trackingParams->device_type);
107
-        $this->assertEquals('HK5454H0K454564WWER445', $trackingParams->device_guid);
108
-    }
109
-
110
-    public function testFindAsset()
111
-    {
112
-        $trackingNumber = null;
113
-
114
-        //region -- Get a tracking number from a random route destination --
115
-        $routeId = self::$testRoutes[0]->route_id;
116
-
117
-        $addresses = self::$testRoutes[0]->addresses;
118
-        assert(!is_null($addresses), "Cannot retrieve a random route ID");
119
-
120
-        foreach ($addresses as $addr1) {
121
-            if (!is_null($addr1->tracking_number)) {
122
-                $trackingNumber = $addr1->tracking_number;
123
-                break;
124
-            }
125
-        }
126
-
127
-        $this->assertNotNull($trackingNumber, "Cannot select a tracking number");
128
-
129
-        //endregion
130
-
131
-        $params = [
132
-            'tracking' => $trackingNumber,
133
-        ];
134
-
135
-        $route = new Route();
136
-
137
-        $result = $route->GetAssetTracking($params);
138
-
139
-        $this->assertNotNull($result);
140
-        $this->assertInstanceOf(FindAssetResponse::class, FindAssetResponse::fromArray($result));
141
-    }
142
-
143
-    public function testGetAllUserLocations()
144
-    {
145
-        $track = new Track();
146
-
147
-        $userLocations = $track->getUserLocations();
148
-
149
-        $this->assertNotNull($userLocations);
150
-        $this->assertTrue(is_array($userLocations));
151
-        $this->assertTrue(sizeof($userLocations)>0);
152
-        $this->assertInstanceOf(
153
-            UserLocation::class,
154
-            UserLocation::fromArray($userLocations[0]));
155
-        $this->assertInstanceOf(
156
-            MemberData::class,
157
-            MemberData::fromArray($userLocations[0]['member_data']));
158
-        $this->assertInstanceOf(
159
-            UserTracking::class,
160
-            UserTracking::fromArray($userLocations[0]['tracking']));
161
-    }
162
-
163
-    public function testQueryUserLocations()
164
-    {
165
-        $track = new Track();
166
-        $userLocations = $track->getUserLocations();
167
-        $userLocation = reset($userLocations);
168
-
169
-        $email = $userLocation['member_data']['member_email'];
170
-
171
-        $queriedUserLocations = $track->getUserLocations($email);
172
-
173
-        $this->assertNotNull($queriedUserLocations);
174
-        $this->assertTrue(is_array($queriedUserLocations));
175
-        $this->assertTrue(sizeof($queriedUserLocations)>0);
176
-        $this->assertInstanceOf(
177
-            UserLocation::class,
178
-            UserLocation::fromArray($queriedUserLocations[0])
179
-        );
180
-        $this->assertInstanceOf(
181
-            MemberData::class,
182
-            MemberData::fromArray($queriedUserLocations[0]['member_data'])
183
-        );
184
-        $this->assertInstanceOf(
185
-            UserTracking::class,
186
-            UserTracking::fromArray($queriedUserLocations[0]['tracking'])
187
-        );
188
-    }
189
-
190
-    public function testGetDeviceHistoryTimeRange()
191
-    {
192
-        $startDate = time() - 30 * 24 * 3600;
193
-        $endDate = time() + 1 * 24 * 3600;
194
-
195
-        $params = [
196
-            'route_id'      => self::$testRoutes[0]->route_id,
197
-            'format'        => Format::JSON,
198
-            'time_period'   => 'custom',
199
-            'start_date'    => $startDate,
200
-            'end_date'      => $endDate,
201
-        ];
202
-
203
-        $route = new Route();
204
-
205
-        $result = $route->GetTrackingHistoryFromTimeRange($params);
206
-
207
-        $this->assertNotNull($result);
208
-    }
209
-
210
-    public function testSetGPSPosition()
211
-    {
212
-        $route = new Route();
213
-
214
-        $routeId = self::$testRoutes[0]->route_id;
215
-
216
-        // Set GPS postion to the selected route
217
-        // Set right member_id corresponding to the API key
218
-        $params = TrackSetParams::fromArray([
219
-            'format'            => Format::CSV,
220
-            'route_id'          => $routeId,
221
-            'member_id'         => self::$testRoutes[0]->parameters->member_id,
222
-            'course'            => 1,
223
-            'speed'             => 120,
224
-            'lat'               => 41.8927521,
225
-            'lng'               => -109.0803888,
226
-            'device_type'       => 'android_phone',
227
-            'device_guid'       => 'qweqweqwe',
228
-            'device_timestamp'  => date('Y-m-d H:i:s', strtotime('-1 day')),
229
-        ]);
230
-
231
-        $status = Track::set($params);
232
-
233
-        $this->assertNotNull($status);
234
-        $this->assertInstanceOf(
235
-            SetGpsResponse::class,
236
-            SetGpsResponse::fromArray($status)
237
-        );
238
-        $this->assertTrue($status['status']);
239
-    }
240
-
241
-    public function testTrackDeviceLastLocationHistory()
242
-    {
243
-        $route = new Route();
244
-
245
-        $routeId = self::$testRoutes[0]->route_id;
246
-
247
-        $params = [
248
-            'route_id'                  => $routeId,
249
-            'device_tracking_history'   => '1',
250
-        ];
251
-
252
-        $result = $route->GetLastLocation($params);
253
-
254
-        $this->assertNotNull($result);
255
-        $this->assertInstanceOf(Route::class, $result);
256
-        $this->assertTrue(isset($result->tracking_history));
257
-    }
258
-
259
-    public static function tearDownAfterClass()
260
-    {
261
-        if (sizeof(self::$createdProblems)>0) {
262
-            $optimizationProblemIDs = [];
263
-
264
-            foreach (self::$createdProblems as $problem) {
265
-                $optimizationProblemId = $problem->optimization_problem_id;
266
-
267
-                $optimizationProblemIDs[] = $optimizationProblemId;
268
-            }
269
-
270
-            $params = [
271
-                'optimization_problem_ids' => $optimizationProblemIDs,
272
-                'redirect'                 => 0,
273
-            ];
274
-
275
-            $problem = new OptimizationProblem();
276
-            $result = $problem->removeOptimization($params);
277
-
278
-            if ($result!=null && $result['status']==true) {
279
-                echo "The test optimizations were removed <br>";
280
-            } else {
281
-                echo "Cannot remove the test optimizations <br>";
282
-            }
283
-        }
284
-    }
29
+	public static $createdProblems = [];
30
+	public static $testRoutes = [];
31
+
32
+	public static function setUpBeforeClass()
33
+	{
34
+		Route4Me::setApiKey(Constants::API_KEY);
35
+
36
+		$json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true);
37
+
38
+		$addresses = [];
39
+		foreach ($json as $address) {
40
+			$addresses[] = Address::fromArray($address);
41
+		}
42
+
43
+		$parameters = RouteParameters::fromArray([
44
+			'algorithm_type'            => AlgorithmType::CVRP_TW_MD,
45
+			'distance_unit'             => DistanceUnit::MILES,
46
+			'device_type'               => DeviceType::WEB,
47
+			'optimize'                  => OptimizationType::DISTANCE,
48
+			'metric'                    => Metric::GEODESIC,
49
+			'route_max_duration'        => 86400 * 2,
50
+			'travel_mode'               => TravelMode::DRIVING,
51
+			'vehicle_capacity'          => 50,
52
+			'vehicle_max_distance_mi'   => 10000,
53
+			'parts'                     => 50,
54
+		]);
55
+		//endregion
56
+
57
+		$optimizationParameters = new OptimizationProblemParams();
58
+		$optimizationParameters->setAddresses($addresses);
59
+		$optimizationParameters->setParameters($parameters);
60
+
61
+		self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters);
62
+
63
+		self::$testRoutes = self::$createdProblems[0]->routes;
64
+
65
+		$params = TrackSetParams::fromArray([
66
+			'format'            => Format::SERIALIZED,
67
+			'route_id'          => self::$testRoutes[0]->route_id,
68
+			'member_id'         => self::$testRoutes[0]->parameters->member_id,
69
+			'course'            => 1,
70
+			'speed'             => 120,
71
+			'lat'               => 41.8927521,
72
+			'lng'               => -109.0803888,
73
+			'device_type'       => 'android_phone',
74
+			'device_guid'       => 'qweqweqwe',
75
+			'device_timestamp'  => date('Y-m-d H:i:s', strtotime('-2 day')),
76
+		]);
77
+
78
+		$status = Track ::set($params);
79
+
80
+		self::assertNotNull($status, "Cannot send GPS position to the selected route");
81
+		self::assertTrue(isset($status['status']), "Cannot send GPS position to the selected route");
82
+		self::assertTrue($status['status'], "Cannot send GPS position to the selected route");
83
+	}
84
+
85
+	public function testFromArray()
86
+	{
87
+		$trackingParams = TrackSetParams::fromArray([
88
+			'member_id'     => 44444,
89
+			'format'        => 'json',
90
+			'route_id'      => '489D597EE62534C906096F1AAC278D26',
91
+			'course'        => 72,
92
+			'speed'         => 65,
93
+			'lat'           => 38.218662,
94
+			'lng'           => -85.789032,
95
+			'device_type'   => 'android_phone',
96
+			'device_guid'   => 'HK5454H0K454564WWER445'
97
+		]);
98
+
99
+		$this->assertEquals(44444, $trackingParams->member_id);
100
+		$this->assertEquals('489D597EE62534C906096F1AAC278D26', $trackingParams->route_id);
101
+
102
+		$this->assertEquals(72, $trackingParams->course);
103
+		$this->assertEquals(65, $trackingParams->speed);
104
+		$this->assertEquals(38.218662, $trackingParams->lat);
105
+		$this->assertEquals(-85.789032, $trackingParams->lng);
106
+		$this->assertEquals('android_phone', $trackingParams->device_type);
107
+		$this->assertEquals('HK5454H0K454564WWER445', $trackingParams->device_guid);
108
+	}
109
+
110
+	public function testFindAsset()
111
+	{
112
+		$trackingNumber = null;
113
+
114
+		//region -- Get a tracking number from a random route destination --
115
+		$routeId = self::$testRoutes[0]->route_id;
116
+
117
+		$addresses = self::$testRoutes[0]->addresses;
118
+		assert(!is_null($addresses), "Cannot retrieve a random route ID");
119
+
120
+		foreach ($addresses as $addr1) {
121
+			if (!is_null($addr1->tracking_number)) {
122
+				$trackingNumber = $addr1->tracking_number;
123
+				break;
124
+			}
125
+		}
126
+
127
+		$this->assertNotNull($trackingNumber, "Cannot select a tracking number");
128
+
129
+		//endregion
130
+
131
+		$params = [
132
+			'tracking' => $trackingNumber,
133
+		];
134
+
135
+		$route = new Route();
136
+
137
+		$result = $route->GetAssetTracking($params);
138
+
139
+		$this->assertNotNull($result);
140
+		$this->assertInstanceOf(FindAssetResponse::class, FindAssetResponse::fromArray($result));
141
+	}
142
+
143
+	public function testGetAllUserLocations()
144
+	{
145
+		$track = new Track();
146
+
147
+		$userLocations = $track->getUserLocations();
148
+
149
+		$this->assertNotNull($userLocations);
150
+		$this->assertTrue(is_array($userLocations));
151
+		$this->assertTrue(sizeof($userLocations)>0);
152
+		$this->assertInstanceOf(
153
+			UserLocation::class,
154
+			UserLocation::fromArray($userLocations[0]));
155
+		$this->assertInstanceOf(
156
+			MemberData::class,
157
+			MemberData::fromArray($userLocations[0]['member_data']));
158
+		$this->assertInstanceOf(
159
+			UserTracking::class,
160
+			UserTracking::fromArray($userLocations[0]['tracking']));
161
+	}
162
+
163
+	public function testQueryUserLocations()
164
+	{
165
+		$track = new Track();
166
+		$userLocations = $track->getUserLocations();
167
+		$userLocation = reset($userLocations);
168
+
169
+		$email = $userLocation['member_data']['member_email'];
170
+
171
+		$queriedUserLocations = $track->getUserLocations($email);
172
+
173
+		$this->assertNotNull($queriedUserLocations);
174
+		$this->assertTrue(is_array($queriedUserLocations));
175
+		$this->assertTrue(sizeof($queriedUserLocations)>0);
176
+		$this->assertInstanceOf(
177
+			UserLocation::class,
178
+			UserLocation::fromArray($queriedUserLocations[0])
179
+		);
180
+		$this->assertInstanceOf(
181
+			MemberData::class,
182
+			MemberData::fromArray($queriedUserLocations[0]['member_data'])
183
+		);
184
+		$this->assertInstanceOf(
185
+			UserTracking::class,
186
+			UserTracking::fromArray($queriedUserLocations[0]['tracking'])
187
+		);
188
+	}
189
+
190
+	public function testGetDeviceHistoryTimeRange()
191
+	{
192
+		$startDate = time() - 30 * 24 * 3600;
193
+		$endDate = time() + 1 * 24 * 3600;
194
+
195
+		$params = [
196
+			'route_id'      => self::$testRoutes[0]->route_id,
197
+			'format'        => Format::JSON,
198
+			'time_period'   => 'custom',
199
+			'start_date'    => $startDate,
200
+			'end_date'      => $endDate,
201
+		];
202
+
203
+		$route = new Route();
204
+
205
+		$result = $route->GetTrackingHistoryFromTimeRange($params);
206
+
207
+		$this->assertNotNull($result);
208
+	}
209
+
210
+	public function testSetGPSPosition()
211
+	{
212
+		$route = new Route();
213
+
214
+		$routeId = self::$testRoutes[0]->route_id;
215
+
216
+		// Set GPS postion to the selected route
217
+		// Set right member_id corresponding to the API key
218
+		$params = TrackSetParams::fromArray([
219
+			'format'            => Format::CSV,
220
+			'route_id'          => $routeId,
221
+			'member_id'         => self::$testRoutes[0]->parameters->member_id,
222
+			'course'            => 1,
223
+			'speed'             => 120,
224
+			'lat'               => 41.8927521,
225
+			'lng'               => -109.0803888,
226
+			'device_type'       => 'android_phone',
227
+			'device_guid'       => 'qweqweqwe',
228
+			'device_timestamp'  => date('Y-m-d H:i:s', strtotime('-1 day')),
229
+		]);
230
+
231
+		$status = Track::set($params);
232
+
233
+		$this->assertNotNull($status);
234
+		$this->assertInstanceOf(
235
+			SetGpsResponse::class,
236
+			SetGpsResponse::fromArray($status)
237
+		);
238
+		$this->assertTrue($status['status']);
239
+	}
240
+
241
+	public function testTrackDeviceLastLocationHistory()
242
+	{
243
+		$route = new Route();
244
+
245
+		$routeId = self::$testRoutes[0]->route_id;
246
+
247
+		$params = [
248
+			'route_id'                  => $routeId,
249
+			'device_tracking_history'   => '1',
250
+		];
251
+
252
+		$result = $route->GetLastLocation($params);
253
+
254
+		$this->assertNotNull($result);
255
+		$this->assertInstanceOf(Route::class, $result);
256
+		$this->assertTrue(isset($result->tracking_history));
257
+	}
258
+
259
+	public static function tearDownAfterClass()
260
+	{
261
+		if (sizeof(self::$createdProblems)>0) {
262
+			$optimizationProblemIDs = [];
263
+
264
+			foreach (self::$createdProblems as $problem) {
265
+				$optimizationProblemId = $problem->optimization_problem_id;
266
+
267
+				$optimizationProblemIDs[] = $optimizationProblemId;
268
+			}
269
+
270
+			$params = [
271
+				'optimization_problem_ids' => $optimizationProblemIDs,
272
+				'redirect'                 => 0,
273
+			];
274
+
275
+			$problem = new OptimizationProblem();
276
+			$result = $problem->removeOptimization($params);
277
+
278
+			if ($result!=null && $result['status']==true) {
279
+				echo "The test optimizations were removed <br>";
280
+			} else {
281
+				echo "Cannot remove the test optimizations <br>";
282
+			}
283
+		}
284
+	}
285 285
 }
286 286
\ No newline at end of file
Please login to merge, or discard this patch.
UnitTestFiles/Test/TelematicsGateWayApiTests.php 1 patch
Indentation   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -15,490 +15,490 @@
 block discarded – undo
15 15
 
16 16
 class TelematicsGateWayApiTests extends \PHPUnit\Framework\TestCase
17 17
 {
18
-    static $createdConnections = [];
19
-    static $firstMemberId;
18
+	static $createdConnections = [];
19
+	static $firstMemberId;
20 20
 
21
-    static $api_token;
22
-    static $tomtom_vendor;
21
+	static $api_token;
22
+	static $tomtom_vendor;
23 23
     
24
-    public static function setUpBeforeClass()
25
-    {
26
-        Route4Me::setApiKey(Constants::API_KEY);
24
+	public static function setUpBeforeClass()
25
+	{
26
+		Route4Me::setApiKey(Constants::API_KEY);
27 27
         
28
-        $member = new Member();
28
+		$member = new Member();
29 29
         
30
-        $results = $member->getUsers();
30
+		$results = $member->getUsers();
31 31
 
32
-        self::$firstMemberId = Member::fromArray($results['results'][0])->member_id;
32
+		self::$firstMemberId = Member::fromArray($results['results'][0])->member_id;
33 33
         
34
-        print_r("\n member_id = ".self::$firstMemberId."\n");
35
-
36
-        //region Get API token
37
-
38
-        $vendorParameters = new TelematicsVendorParameters();
39
-        $vendorParameters->member_id = self::$firstMemberId;
40
-        $vendorParameters->api_key = Constants::API_KEY;
41
-
42
-        $vendors = new TelematicsVendor();
43
-        $result = $vendors->RegisterTelematicsMember($vendorParameters);
44
-
45
-        self::assertNotNull($result);
46
-        self::assertInstanceOf(
47
-            TelematicsRegisterMemberResponse::class,
48
-            TelematicsRegisterMemberResponse::fromArray($result)
49
-        );
50
-
51
-        self::$api_token = TelematicsRegisterMemberResponse::fromArray(
52
-            $result
53
-        )->api_token;
54
-
55
-        //endregion
56
-
57
-        //region Get TomTom vendor
58
-
59
-        $vendorsParameters = TelematicsVendorParameters::fromArray([
60
-            //"country"     => "GB",  // uncomment this line for searching by Country
61
-            'is_integrated' => 1,
62
-            //"feature"     => "satellite",  // uncomment this line for searching by Feature
63
-            'search'        => 'tomtom',
64
-            'page'          => 1,
65
-            'per_page'      => 5,
66
-        ]);
67
-
68
-        $vendors = new TelematicsVendor();
69
-        $vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters);
70
-
71
-        self::assertNotNull($vendorsResults);
72
-        self::assertTrue(is_array($vendorsResults));
73
-        self::assertTrue(sizeof($vendorsResults)>0);
74
-        self::assertTrue(
75
-            TelematicsVendor::fromArray($vendorsResults['vendors'][0])
76
-                instanceof
77
-                TelematicsVendor);
78
-
79
-        self::$tomtom_vendor = TelematicsVendor::fromArray($vendorsResults['vendors'][0]);
80
-        //endregion
81
-
82
-        //region Create Test Connection
83
-
84
-        $vendParams = new TelematicsConnectionParameters();
85
-
86
-        $vendParams->vendor       = TelematicsVendorsTypes::GEOTAB;
87
-        $vendParams->account_id   = '54321';
88
-        $vendParams->username     = 'John Doe 0';
89
-        $vendParams->password     = 'password0';
90
-        $vendParams->vehicle_position_refresh_rate    = 60;
91
-        $vendParams->name         = 'Test Geotab Connection from php SDK';
92
-        $vendParams->validate_remote_credentials      = 0;
93
-
94
-        $teleConnection = new TelematicsConnection();
95
-
96
-        $result2 = $teleConnection->createTelematicsConnection(
97
-            self::$api_token,
98
-            $vendParams->toArray()
99
-        );
100
-
101
-        self::assertNotNull($result2);
102
-        self::assertTrue( CreateConnectionResponse::fromArray($result2) instanceof CreateConnectionResponse);
103
-
104
-        self::$createdConnections[] = TelematicsConnection::fromArray($result2);
105
-        //endregion
106
-    }
107
-
108
-    public function testFromArray()
109
-    {
110
-        $vendorParameters = TelematicsVendor::fromArray([
111
-            'id'            => 14,
112
-            'name'          => 'Borea',
113
-            'slug'          => 'borea',
114
-            'description'   => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
115
-            'logo_url'      => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
116
-            'website_url'   => 'https:\/\/www.borea.com\/',
117
-            'api_docs_url'  => 'https:\/\/www.borea.com\/docs\/',
118
-            'is_integrated' => true,
119
-            'size'          => 'regional',
120
-            'features'      => [
121
-                0 => [
122
-                    'id'    => '1',
123
-                    'name'  => 'Customizable Reports',
124
-                    'slug'  => 'customizable-reports',
125
-                    'feature_group' => 'Analytics & Reporting'
126
-                ],
127
-                1 => [
128
-                    'id'            => '2',
129
-                    'name'          => 'Publicly Accessible API Documention',
130
-                    'slug'          => 'publicly-accessible-api-doc',
131
-                    'feature_group' => 'API & SDK'
132
-                ]
133
-            ],
134
-            'countries' => [
135
-                0 => [
136
-                    'id'            => '38',
137
-                    'country_code'  => 'CA',
138
-                    'country_name'  => 'Canada'
139
-                ],
140
-                1 => [
141
-                    'id'            => '230',
142
-                    'country_code'  => 'USA',
143
-                    'country_name'  => 'United States'
144
-                ]
145
-            ]
146
-        ]);
147
-
148
-        $this->assertEquals(14, $vendorParameters->id);
149
-        $this->assertEquals('Borea', $vendorParameters->name);
150
-        $this->assertEquals('borea', $vendorParameters->slug);
151
-        $this->assertEquals(
152
-            'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
153
-            $vendorParameters->description
154
-        );
155
-        $this->assertEquals(
156
-            'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
157
-            $vendorParameters->logo_url
158
-        );
159
-        $this->assertEquals('https:\/\/www.borea.com\/', $vendorParameters->website_url);
160
-        $this->assertEquals('https:\/\/www.borea.com\/docs\/', $vendorParameters->api_docs_url);
161
-        $this->assertEquals(true, $vendorParameters->is_integrated);
162
-        $this->assertEquals('regional', $vendorParameters->size);
163
-        $this->assertEquals(
164
-            [
165
-                0 => [
166
-                    'id'            => '1',
167
-                    'name'          => 'Customizable Reports',
168
-                    'slug'          => 'customizable-reports',
169
-                    'feature_group' => 'Analytics & Reporting'
170
-                ],
171
-                1 => [
172
-                    'id'            => '2',
173
-                    'name'          => 'Publicly Accessible API Documention',
174
-                    'slug'          => 'publicly-accessible-api-doc',
175
-                    'feature_group' => 'API & SDK'
176
-                ]
177
-            ],
178
-            $vendorParameters->features
179
-        );
180
-        $this->assertEquals(
181
-            [
182
-                0 => [
183
-                    'id'            => '38',
184
-                    'country_code'  => 'CA',
185
-                    'country_name'  => 'Canada'
186
-                ],
187
-                1 => [
188
-                    'id'            => '230',
189
-                    'country_code'  => 'USA',
190
-                    'country_name'  => 'United States'
191
-                ]
192
-            ],
193
-            $vendorParameters->countries
194
-        );
195
-    }
196
-
197
-    public function testToArray()
198
-    {
199
-        $vendorParameters = TelematicsVendor::fromArray([
200
-            'id'            => 14,
201
-            'name'          => 'Borea',
202
-            'slug'          => 'borea',
203
-            'description'   => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
204
-            'logo_url'      => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
205
-            'website_url'   => 'https:\/\/www.borea.com\/',
206
-            'api_docs_url'  => 'https:\/\/www.borea.com\/docs\/',
207
-            'is_integrated' => true,
208
-            'size'          => 'regional',
209
-            'features'      => [
210
-                0 => [
211
-                    'id'            => '1',
212
-                    'name'          => 'Customizable Reports',
213
-                    'slug'          => 'customizable-reports',
214
-                    'feature_group' => 'Analytics & Reporting'
215
-                ],
216
-                1 => [
217
-                    'id'            => '2',
218
-                    'name'          => 'Publicly Accessible API Documention',
219
-                    'slug'          => 'publicly-accessible-api-doc',
220
-                    'feature_group' => 'API & SDK'
221
-                ]
222
-            ],
223
-            'countries' => [
224
-                0 => [
225
-                    'id'            => '38',
226
-                    'country_code'  => 'CA',
227
-                    'country_name'  => 'Canada'
228
-                ],
229
-                1 => [
230
-                    'id'            => '230',
231
-                    'country_code'  => 'USA',
232
-                    'country_name'  => 'United States'
233
-                ]
234
-            ]
235
-        ]);
236
-
237
-        $this->assertEquals(14, $vendorParameters->id);
238
-        $this->assertEquals('Borea', $vendorParameters->name);
239
-        $this->assertEquals('borea', $vendorParameters->slug);
240
-        $this->assertEquals(
241
-            'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
242
-            $vendorParameters->description
243
-        );
244
-        $this->assertEquals(
245
-            'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
246
-            $vendorParameters->logo_url
247
-        );
248
-        $this->assertEquals('https:\/\/www.borea.com\/', $vendorParameters->website_url);
249
-        $this->assertEquals('https:\/\/www.borea.com\/docs\/', $vendorParameters->api_docs_url);
250
-        $this->assertEquals(true, $vendorParameters->is_integrated);
251
-        $this->assertEquals('regional', $vendorParameters->size);
252
-        $this->assertEquals(
253
-            [
254
-                0 => [
255
-                    'id'            => '1',
256
-                    'name'          => 'Customizable Reports',
257
-                    'slug'          => 'customizable-reports',
258
-                    'feature_group' => 'Analytics & Reporting'
259
-                ],
260
-                1 => [
261
-                    'id'            => '2',
262
-                    'name'          => 'Publicly Accessible API Documention',
263
-                    'slug'          => 'publicly-accessible-api-doc',
264
-                    'feature_group' => 'API & SDK'
265
-                ]
266
-            ],
267
-            $vendorParameters->features
268
-        );
269
-        $this->assertEquals(
270
-            [
271
-                0 => [
272
-                    'id'            => '38',
273
-                    'country_code'  => 'CA',
274
-                    'country_name'  => 'Canada'
275
-                ],
276
-                1 => [
277
-                    'id'            => '230',
278
-                    'country_code'  => 'USA',
279
-                    'country_name'  => 'United States'
280
-                ]
281
-            ],
282
-            $vendorParameters->countries
283
-        );
284
-
285
-        $this->assertEquals($vendorParameters->toArray(),
286
-            [
287
-                'id'            => 14,
288
-                'name'          => 'Borea',
289
-                'slug'          => 'borea',
290
-                'description'   => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
291
-                'logo_url'      => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
292
-                'website_url'   => 'https:\/\/www.borea.com\/',
293
-                'api_docs_url'  => 'https:\/\/www.borea.com\/docs\/',
294
-                'is_integrated' => true,
295
-                'size'          => 'regional',
296
-                'features'      => [
297
-                    0 => [
298
-                        'id'            => '1',
299
-                        'name'          => 'Customizable Reports',
300
-                        'slug'          => 'customizable-reports',
301
-                        'feature_group' => 'Analytics & Reporting'
302
-                    ],
303
-                    1 => [
304
-                        'id'            => '2',
305
-                        'name'          => 'Publicly Accessible API Documention',
306
-                        'slug'          => 'publicly-accessible-api-doc',
307
-                        'feature_group' => 'API & SDK'
308
-                    ]
309
-                ],
310
-                'countries' => [
311
-                    0 => [
312
-                        'id'            => '38',
313
-                        'country_code'  => 'CA',
314
-                        'country_name'  => 'Canada'
315
-                    ],
316
-                    1 => [
317
-                        'id'            => '230',
318
-                        'country_code'  => 'USA',
319
-                        'country_name'  => 'United States'
320
-                    ]
321
-                ]
322
-            ]
323
-        );
324
-    }
325
-
326
-    public function testGetAllVendors()
327
-    {
328
-        $vendorsParameters = TelematicsVendor::fromArray( [ ] );
329
-
330
-        $vendors = new TelematicsVendor();
331
-        $vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters);
332
-
333
-        $this->assertNotNull($vendorsResults);
334
-        $this->assertTrue(is_array($vendorsResults));
335
-        $this->assertTrue(sizeof($vendorsResults)>0);
336
-        $this->assertInstanceOf(
337
-            TelematicsVendor::class,
338
-            TelematicsVendor::fromArray($vendorsResults['vendors'][0])
339
-        );
340
-    }
341
-
342
-    public function testGetVendor()
343
-    {
344
-        $vendorResult = TelematicsVendor::getVendorById(self::$tomtom_vendor->id);
345
-
346
-        $this->assertNotNull($vendorResult);
347
-        $this->assertTrue(is_array($vendorResult));
348
-        $this->assertInstanceOf(
349
-            TelematicsVendor::class,
350
-            TelematicsVendor::fromArray($vendorResult)
351
-        );
352
-    }
353
-
354
-    public function testSearchVendors()
355
-    {
356
-        $vendorsParameters = TelematicsVendorParameters::fromArray([
357
-            //"country"     => "GB",  // uncomment this line for searching by Country
358
-            'is_integrated' => 1,
359
-            //"feature"     => "satellite",  // uncomment this line for searching by Feature
360
-            'search'        => 'Fleet',
361
-            'page'          => 1,
362
-            'per_page'      => 5,
363
-        ]);
364
-
365
-        $vendors = new TelematicsVendor();
366
-        $vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters);
367
-
368
-        $this->assertNotNull($vendorsResults);
369
-        $this->assertTrue(is_array($vendorsResults));
370
-        $this->assertTrue(sizeof($vendorsResults)>0);
371
-        $this->assertInstanceOf(
372
-            TelematicsVendor::class,
373
-            TelematicsVendor::fromArray($vendorsResults['vendors'][0])
374
-        );
375
-    }
376
-
377
-    public function testVendorsComparison()
378
-    {
379
-        $vendorsParameters = TelematicsVendorParameters::fromArray([
380
-            'vendors' => '55,56,57',
381
-        ]);
382
-
383
-        $vendors = new TelematicsVendor();
384
-        $comparisonResults = $vendors->GetTelematicsVendors($vendorsParameters);
385
-
386
-        $this->assertNotNull($comparisonResults);
387
-        $this->assertTrue(is_array($comparisonResults));
388
-        $this->assertTrue(sizeof($comparisonResults)>0);
389
-        $this->assertInstanceOf(
390
-            TelematicsVendor::class,
391
-            TelematicsVendor::fromArray($comparisonResults['vendors'][0])
392
-        );
393
-    }
34
+		print_r("\n member_id = ".self::$firstMemberId."\n");
35
+
36
+		//region Get API token
37
+
38
+		$vendorParameters = new TelematicsVendorParameters();
39
+		$vendorParameters->member_id = self::$firstMemberId;
40
+		$vendorParameters->api_key = Constants::API_KEY;
41
+
42
+		$vendors = new TelematicsVendor();
43
+		$result = $vendors->RegisterTelematicsMember($vendorParameters);
44
+
45
+		self::assertNotNull($result);
46
+		self::assertInstanceOf(
47
+			TelematicsRegisterMemberResponse::class,
48
+			TelematicsRegisterMemberResponse::fromArray($result)
49
+		);
50
+
51
+		self::$api_token = TelematicsRegisterMemberResponse::fromArray(
52
+			$result
53
+		)->api_token;
54
+
55
+		//endregion
56
+
57
+		//region Get TomTom vendor
58
+
59
+		$vendorsParameters = TelematicsVendorParameters::fromArray([
60
+			//"country"     => "GB",  // uncomment this line for searching by Country
61
+			'is_integrated' => 1,
62
+			//"feature"     => "satellite",  // uncomment this line for searching by Feature
63
+			'search'        => 'tomtom',
64
+			'page'          => 1,
65
+			'per_page'      => 5,
66
+		]);
67
+
68
+		$vendors = new TelematicsVendor();
69
+		$vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters);
70
+
71
+		self::assertNotNull($vendorsResults);
72
+		self::assertTrue(is_array($vendorsResults));
73
+		self::assertTrue(sizeof($vendorsResults)>0);
74
+		self::assertTrue(
75
+			TelematicsVendor::fromArray($vendorsResults['vendors'][0])
76
+				instanceof
77
+				TelematicsVendor);
78
+
79
+		self::$tomtom_vendor = TelematicsVendor::fromArray($vendorsResults['vendors'][0]);
80
+		//endregion
81
+
82
+		//region Create Test Connection
83
+
84
+		$vendParams = new TelematicsConnectionParameters();
85
+
86
+		$vendParams->vendor       = TelematicsVendorsTypes::GEOTAB;
87
+		$vendParams->account_id   = '54321';
88
+		$vendParams->username     = 'John Doe 0';
89
+		$vendParams->password     = 'password0';
90
+		$vendParams->vehicle_position_refresh_rate    = 60;
91
+		$vendParams->name         = 'Test Geotab Connection from php SDK';
92
+		$vendParams->validate_remote_credentials      = 0;
93
+
94
+		$teleConnection = new TelematicsConnection();
95
+
96
+		$result2 = $teleConnection->createTelematicsConnection(
97
+			self::$api_token,
98
+			$vendParams->toArray()
99
+		);
100
+
101
+		self::assertNotNull($result2);
102
+		self::assertTrue( CreateConnectionResponse::fromArray($result2) instanceof CreateConnectionResponse);
103
+
104
+		self::$createdConnections[] = TelematicsConnection::fromArray($result2);
105
+		//endregion
106
+	}
107
+
108
+	public function testFromArray()
109
+	{
110
+		$vendorParameters = TelematicsVendor::fromArray([
111
+			'id'            => 14,
112
+			'name'          => 'Borea',
113
+			'slug'          => 'borea',
114
+			'description'   => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
115
+			'logo_url'      => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
116
+			'website_url'   => 'https:\/\/www.borea.com\/',
117
+			'api_docs_url'  => 'https:\/\/www.borea.com\/docs\/',
118
+			'is_integrated' => true,
119
+			'size'          => 'regional',
120
+			'features'      => [
121
+				0 => [
122
+					'id'    => '1',
123
+					'name'  => 'Customizable Reports',
124
+					'slug'  => 'customizable-reports',
125
+					'feature_group' => 'Analytics & Reporting'
126
+				],
127
+				1 => [
128
+					'id'            => '2',
129
+					'name'          => 'Publicly Accessible API Documention',
130
+					'slug'          => 'publicly-accessible-api-doc',
131
+					'feature_group' => 'API & SDK'
132
+				]
133
+			],
134
+			'countries' => [
135
+				0 => [
136
+					'id'            => '38',
137
+					'country_code'  => 'CA',
138
+					'country_name'  => 'Canada'
139
+				],
140
+				1 => [
141
+					'id'            => '230',
142
+					'country_code'  => 'USA',
143
+					'country_name'  => 'United States'
144
+				]
145
+			]
146
+		]);
147
+
148
+		$this->assertEquals(14, $vendorParameters->id);
149
+		$this->assertEquals('Borea', $vendorParameters->name);
150
+		$this->assertEquals('borea', $vendorParameters->slug);
151
+		$this->assertEquals(
152
+			'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
153
+			$vendorParameters->description
154
+		);
155
+		$this->assertEquals(
156
+			'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
157
+			$vendorParameters->logo_url
158
+		);
159
+		$this->assertEquals('https:\/\/www.borea.com\/', $vendorParameters->website_url);
160
+		$this->assertEquals('https:\/\/www.borea.com\/docs\/', $vendorParameters->api_docs_url);
161
+		$this->assertEquals(true, $vendorParameters->is_integrated);
162
+		$this->assertEquals('regional', $vendorParameters->size);
163
+		$this->assertEquals(
164
+			[
165
+				0 => [
166
+					'id'            => '1',
167
+					'name'          => 'Customizable Reports',
168
+					'slug'          => 'customizable-reports',
169
+					'feature_group' => 'Analytics & Reporting'
170
+				],
171
+				1 => [
172
+					'id'            => '2',
173
+					'name'          => 'Publicly Accessible API Documention',
174
+					'slug'          => 'publicly-accessible-api-doc',
175
+					'feature_group' => 'API & SDK'
176
+				]
177
+			],
178
+			$vendorParameters->features
179
+		);
180
+		$this->assertEquals(
181
+			[
182
+				0 => [
183
+					'id'            => '38',
184
+					'country_code'  => 'CA',
185
+					'country_name'  => 'Canada'
186
+				],
187
+				1 => [
188
+					'id'            => '230',
189
+					'country_code'  => 'USA',
190
+					'country_name'  => 'United States'
191
+				]
192
+			],
193
+			$vendorParameters->countries
194
+		);
195
+	}
196
+
197
+	public function testToArray()
198
+	{
199
+		$vendorParameters = TelematicsVendor::fromArray([
200
+			'id'            => 14,
201
+			'name'          => 'Borea',
202
+			'slug'          => 'borea',
203
+			'description'   => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
204
+			'logo_url'      => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
205
+			'website_url'   => 'https:\/\/www.borea.com\/',
206
+			'api_docs_url'  => 'https:\/\/www.borea.com\/docs\/',
207
+			'is_integrated' => true,
208
+			'size'          => 'regional',
209
+			'features'      => [
210
+				0 => [
211
+					'id'            => '1',
212
+					'name'          => 'Customizable Reports',
213
+					'slug'          => 'customizable-reports',
214
+					'feature_group' => 'Analytics & Reporting'
215
+				],
216
+				1 => [
217
+					'id'            => '2',
218
+					'name'          => 'Publicly Accessible API Documention',
219
+					'slug'          => 'publicly-accessible-api-doc',
220
+					'feature_group' => 'API & SDK'
221
+				]
222
+			],
223
+			'countries' => [
224
+				0 => [
225
+					'id'            => '38',
226
+					'country_code'  => 'CA',
227
+					'country_name'  => 'Canada'
228
+				],
229
+				1 => [
230
+					'id'            => '230',
231
+					'country_code'  => 'USA',
232
+					'country_name'  => 'United States'
233
+				]
234
+			]
235
+		]);
236
+
237
+		$this->assertEquals(14, $vendorParameters->id);
238
+		$this->assertEquals('Borea', $vendorParameters->name);
239
+		$this->assertEquals('borea', $vendorParameters->slug);
240
+		$this->assertEquals(
241
+			'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
242
+			$vendorParameters->description
243
+		);
244
+		$this->assertEquals(
245
+			'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
246
+			$vendorParameters->logo_url
247
+		);
248
+		$this->assertEquals('https:\/\/www.borea.com\/', $vendorParameters->website_url);
249
+		$this->assertEquals('https:\/\/www.borea.com\/docs\/', $vendorParameters->api_docs_url);
250
+		$this->assertEquals(true, $vendorParameters->is_integrated);
251
+		$this->assertEquals('regional', $vendorParameters->size);
252
+		$this->assertEquals(
253
+			[
254
+				0 => [
255
+					'id'            => '1',
256
+					'name'          => 'Customizable Reports',
257
+					'slug'          => 'customizable-reports',
258
+					'feature_group' => 'Analytics & Reporting'
259
+				],
260
+				1 => [
261
+					'id'            => '2',
262
+					'name'          => 'Publicly Accessible API Documention',
263
+					'slug'          => 'publicly-accessible-api-doc',
264
+					'feature_group' => 'API & SDK'
265
+				]
266
+			],
267
+			$vendorParameters->features
268
+		);
269
+		$this->assertEquals(
270
+			[
271
+				0 => [
272
+					'id'            => '38',
273
+					'country_code'  => 'CA',
274
+					'country_name'  => 'Canada'
275
+				],
276
+				1 => [
277
+					'id'            => '230',
278
+					'country_code'  => 'USA',
279
+					'country_name'  => 'United States'
280
+				]
281
+			],
282
+			$vendorParameters->countries
283
+		);
284
+
285
+		$this->assertEquals($vendorParameters->toArray(),
286
+			[
287
+				'id'            => 14,
288
+				'name'          => 'Borea',
289
+				'slug'          => 'borea',
290
+				'description'   => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence',
291
+				'logo_url'      => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png',
292
+				'website_url'   => 'https:\/\/www.borea.com\/',
293
+				'api_docs_url'  => 'https:\/\/www.borea.com\/docs\/',
294
+				'is_integrated' => true,
295
+				'size'          => 'regional',
296
+				'features'      => [
297
+					0 => [
298
+						'id'            => '1',
299
+						'name'          => 'Customizable Reports',
300
+						'slug'          => 'customizable-reports',
301
+						'feature_group' => 'Analytics & Reporting'
302
+					],
303
+					1 => [
304
+						'id'            => '2',
305
+						'name'          => 'Publicly Accessible API Documention',
306
+						'slug'          => 'publicly-accessible-api-doc',
307
+						'feature_group' => 'API & SDK'
308
+					]
309
+				],
310
+				'countries' => [
311
+					0 => [
312
+						'id'            => '38',
313
+						'country_code'  => 'CA',
314
+						'country_name'  => 'Canada'
315
+					],
316
+					1 => [
317
+						'id'            => '230',
318
+						'country_code'  => 'USA',
319
+						'country_name'  => 'United States'
320
+					]
321
+				]
322
+			]
323
+		);
324
+	}
325
+
326
+	public function testGetAllVendors()
327
+	{
328
+		$vendorsParameters = TelematicsVendor::fromArray( [ ] );
329
+
330
+		$vendors = new TelematicsVendor();
331
+		$vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters);
332
+
333
+		$this->assertNotNull($vendorsResults);
334
+		$this->assertTrue(is_array($vendorsResults));
335
+		$this->assertTrue(sizeof($vendorsResults)>0);
336
+		$this->assertInstanceOf(
337
+			TelematicsVendor::class,
338
+			TelematicsVendor::fromArray($vendorsResults['vendors'][0])
339
+		);
340
+	}
341
+
342
+	public function testGetVendor()
343
+	{
344
+		$vendorResult = TelematicsVendor::getVendorById(self::$tomtom_vendor->id);
345
+
346
+		$this->assertNotNull($vendorResult);
347
+		$this->assertTrue(is_array($vendorResult));
348
+		$this->assertInstanceOf(
349
+			TelematicsVendor::class,
350
+			TelematicsVendor::fromArray($vendorResult)
351
+		);
352
+	}
353
+
354
+	public function testSearchVendors()
355
+	{
356
+		$vendorsParameters = TelematicsVendorParameters::fromArray([
357
+			//"country"     => "GB",  // uncomment this line for searching by Country
358
+			'is_integrated' => 1,
359
+			//"feature"     => "satellite",  // uncomment this line for searching by Feature
360
+			'search'        => 'Fleet',
361
+			'page'          => 1,
362
+			'per_page'      => 5,
363
+		]);
364
+
365
+		$vendors = new TelematicsVendor();
366
+		$vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters);
367
+
368
+		$this->assertNotNull($vendorsResults);
369
+		$this->assertTrue(is_array($vendorsResults));
370
+		$this->assertTrue(sizeof($vendorsResults)>0);
371
+		$this->assertInstanceOf(
372
+			TelematicsVendor::class,
373
+			TelematicsVendor::fromArray($vendorsResults['vendors'][0])
374
+		);
375
+	}
376
+
377
+	public function testVendorsComparison()
378
+	{
379
+		$vendorsParameters = TelematicsVendorParameters::fromArray([
380
+			'vendors' => '55,56,57',
381
+		]);
382
+
383
+		$vendors = new TelematicsVendor();
384
+		$comparisonResults = $vendors->GetTelematicsVendors($vendorsParameters);
385
+
386
+		$this->assertNotNull($comparisonResults);
387
+		$this->assertTrue(is_array($comparisonResults));
388
+		$this->assertTrue(sizeof($comparisonResults)>0);
389
+		$this->assertInstanceOf(
390
+			TelematicsVendor::class,
391
+			TelematicsVendor::fromArray($comparisonResults['vendors'][0])
392
+		);
393
+	}
394 394
     
395
-    public function testRegisterTelematicsVendor() 
396
-    {
397
-        $vendorParameters = new TelematicsVendorParameters();
398
-        $vendorParameters->member_id = self::$firstMemberId;
399
-        $vendorParameters->api_key = Constants::API_KEY;
395
+	public function testRegisterTelematicsVendor() 
396
+	{
397
+		$vendorParameters = new TelematicsVendorParameters();
398
+		$vendorParameters->member_id = self::$firstMemberId;
399
+		$vendorParameters->api_key = Constants::API_KEY;
400 400
         
401
-        $vendors = new TelematicsVendor();
402
-        $result = $vendors->RegisterTelematicsMember($vendorParameters);
401
+		$vendors = new TelematicsVendor();
402
+		$result = $vendors->RegisterTelematicsMember($vendorParameters);
403 403
         
404
-        $this->assertNotNull($result);
405
-        $this->assertInstanceOf(
406
-            TelematicsRegisterMemberResponse::class,
407
-            TelematicsRegisterMemberResponse::fromArray($result)
408
-        );
409
-    }
410
-
411
-    public function testGetTelematicsConnections()
412
-    {
413
-        $teleConnection = new TelematicsConnection();
414
-
415
-        $connections = $teleConnection->getTelematicsConnections(self::$api_token);
416
-
417
-        $this->assertNotNull($connections);
418
-        $this->assertTrue(
419
-            TelematicsConnection::fromArray($connections[0])
420
-            instanceof
421
-            TelematicsConnection);
422
-    }
423
-
424
-    public function testGetTelematicsConnection()
425
-    {
426
-        $teleConnection = new TelematicsConnection();
427
-
428
-        $connection = $teleConnection->getTelematicsConnection(
429
-            self::$api_token,
430
-            self::$createdConnections[sizeof(self::$createdConnections)-1]->connection_token
431
-        );
432
-
433
-        $this->assertNotNull($connection);
434
-        $this->assertTrue(
435
-            TelematicsConnection::fromArray($connection)
436
-            instanceof
437
-            TelematicsConnection);
438
-    }
439
-
440
-    public function testCreateTelematicsConnection()
441
-    {
442
-        $vendorParameters = new TelematicsConnectionParameters();
443
-
444
-        $vendorParameters->vendor_id    = self::$tomtom_vendor->id;
445
-        $vendorParameters->vendor       = self::$tomtom_vendor->slug;
446
-        $vendorParameters->account_id   = '12345';
447
-        $vendorParameters->username     = 'John Doe';
448
-        $vendorParameters->password     = 'password';
449
-        $vendorParameters->vehicle_position_refresh_rate    = 60;
450
-        $vendorParameters->name         = 'Test Telematics Connection from php SDK';
451
-        $vendorParameters->validate_remote_credentials      = 0;
452
-
453
-        $teleConnection = new TelematicsConnection();
454
-
455
-       $result = $teleConnection->createTelematicsConnection(
456
-           self::$api_token,
457
-           $vendorParameters->toArray()
458
-       );
459
-
460
-        $this->assertNotNull($result);
461
-        $this->assertTrue( CreateConnectionResponse::fromArray($result) instanceof CreateConnectionResponse);
462
-
463
-        self::$createdConnections[] = TelematicsConnection::fromArray($result);
464
-    }
465
-
466
-    public function testUpdateTelematicsConnection()
467
-    {
468
-        $teleConParams = new TelematicsConnectionParameters();
469
-
470
-        $teleConParams->vehicle_position_refresh_rate    = 50;
471
-        $teleConParams->name         = 'Test Telematics Connection from php SDK Updated';
472
-        $teleConParams->validate_remote_credentials      = 0;
473
-
474
-        $teleConnection = new TelematicsConnection();
475
-
476
-        $result = $teleConnection->updateTelematicsConnection(
477
-            self::$api_token,
478
-            self::$createdConnections[0]->connection_token,
479
-            $teleConParams->toArray()
480
-        );
481
-
482
-        $this->assertNotNull($result);
483
-        $this->assertTrue(
484
-            TelematicsConnection::fromArray($result)
485
-            instanceof
486
-            TelematicsConnection);
487
-    }
488
-
489
-    public static function tearDownAfterClass()
490
-    {
491
-        if (sizeof(self::$createdConnections)>0) {
492
-
493
-            $teleConn = new TelematicsConnection();
494
-
495
-            foreach (self::$createdConnections as $createdConn) {
496
-                $deleted = $teleConn->deleteTelematicsConnection(
497
-                    self::$api_token,
498
-                    $createdConn->connection_token
499
-                );
500
-            }
501
-        }
502
-    }
404
+		$this->assertNotNull($result);
405
+		$this->assertInstanceOf(
406
+			TelematicsRegisterMemberResponse::class,
407
+			TelematicsRegisterMemberResponse::fromArray($result)
408
+		);
409
+	}
410
+
411
+	public function testGetTelematicsConnections()
412
+	{
413
+		$teleConnection = new TelematicsConnection();
414
+
415
+		$connections = $teleConnection->getTelematicsConnections(self::$api_token);
416
+
417
+		$this->assertNotNull($connections);
418
+		$this->assertTrue(
419
+			TelematicsConnection::fromArray($connections[0])
420
+			instanceof
421
+			TelematicsConnection);
422
+	}
423
+
424
+	public function testGetTelematicsConnection()
425
+	{
426
+		$teleConnection = new TelematicsConnection();
427
+
428
+		$connection = $teleConnection->getTelematicsConnection(
429
+			self::$api_token,
430
+			self::$createdConnections[sizeof(self::$createdConnections)-1]->connection_token
431
+		);
432
+
433
+		$this->assertNotNull($connection);
434
+		$this->assertTrue(
435
+			TelematicsConnection::fromArray($connection)
436
+			instanceof
437
+			TelematicsConnection);
438
+	}
439
+
440
+	public function testCreateTelematicsConnection()
441
+	{
442
+		$vendorParameters = new TelematicsConnectionParameters();
443
+
444
+		$vendorParameters->vendor_id    = self::$tomtom_vendor->id;
445
+		$vendorParameters->vendor       = self::$tomtom_vendor->slug;
446
+		$vendorParameters->account_id   = '12345';
447
+		$vendorParameters->username     = 'John Doe';
448
+		$vendorParameters->password     = 'password';
449
+		$vendorParameters->vehicle_position_refresh_rate    = 60;
450
+		$vendorParameters->name         = 'Test Telematics Connection from php SDK';
451
+		$vendorParameters->validate_remote_credentials      = 0;
452
+
453
+		$teleConnection = new TelematicsConnection();
454
+
455
+	   $result = $teleConnection->createTelematicsConnection(
456
+		   self::$api_token,
457
+		   $vendorParameters->toArray()
458
+	   );
459
+
460
+		$this->assertNotNull($result);
461
+		$this->assertTrue( CreateConnectionResponse::fromArray($result) instanceof CreateConnectionResponse);
462
+
463
+		self::$createdConnections[] = TelematicsConnection::fromArray($result);
464
+	}
465
+
466
+	public function testUpdateTelematicsConnection()
467
+	{
468
+		$teleConParams = new TelematicsConnectionParameters();
469
+
470
+		$teleConParams->vehicle_position_refresh_rate    = 50;
471
+		$teleConParams->name         = 'Test Telematics Connection from php SDK Updated';
472
+		$teleConParams->validate_remote_credentials      = 0;
473
+
474
+		$teleConnection = new TelematicsConnection();
475
+
476
+		$result = $teleConnection->updateTelematicsConnection(
477
+			self::$api_token,
478
+			self::$createdConnections[0]->connection_token,
479
+			$teleConParams->toArray()
480
+		);
481
+
482
+		$this->assertNotNull($result);
483
+		$this->assertTrue(
484
+			TelematicsConnection::fromArray($result)
485
+			instanceof
486
+			TelematicsConnection);
487
+	}
488
+
489
+	public static function tearDownAfterClass()
490
+	{
491
+		if (sizeof(self::$createdConnections)>0) {
492
+
493
+			$teleConn = new TelematicsConnection();
494
+
495
+			foreach (self::$createdConnections as $createdConn) {
496
+				$deleted = $teleConn->deleteTelematicsConnection(
497
+					self::$api_token,
498
+					$createdConn->connection_token
499
+				);
500
+			}
501
+		}
502
+	}
503 503
 
504 504
 }
505 505
\ No newline at end of file
Please login to merge, or discard this patch.
UnitTestFiles/Test/MemberConfigurationTest.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -10,187 +10,187 @@
 block discarded – undo
10 10
 
11 11
 class MemberConfigurationTest extends \PHPUnit\Framework\TestCase
12 12
 {
13
-    public static $createdConfigurationKeys;
14
-
15
-    public static function setUpBeforeClass()
16
-    {
17
-        Route4Me::setApiKey(Constants::API_KEY);
13
+	public static $createdConfigurationKeys;
14
+
15
+	public static function setUpBeforeClass()
16
+	{
17
+		Route4Me::setApiKey(Constants::API_KEY);
18 18
 
19
-        $memberConfiguration = new MemberConfiguration();
19
+		$memberConfiguration = new MemberConfiguration();
20 20
 
21
-        $query = [
22
-            'config_key' => 'Test My weight'
23
-        ];
24
-
25
-        $removed = $memberConfiguration->RemoveConfigurationData($query, $errorText);
21
+		$query = [
22
+			'config_key' => 'Test My weight'
23
+		];
24
+
25
+		$removed = $memberConfiguration->RemoveConfigurationData($query, $errorText);
26 26
 
27
-        $memberConfiguration->config_key = 'Test My height';
28
-        $memberConfiguration->config_value = '180';
29
-
30
-        $result = $memberConfiguration->CreateNewConfigurationData($memberConfiguration->toArray(), $errorText);
27
+		$memberConfiguration->config_key = 'Test My height';
28
+		$memberConfiguration->config_value = '180';
29
+
30
+		$result = $memberConfiguration->CreateNewConfigurationData($memberConfiguration->toArray(), $errorText);
31 31
 
32
-        if(isset($result['affected']) && $result['affected']==1) {
33
-            self::$createdConfigurationKeys[] = 'Test My height';
34
-        } else {
35
-            echo "$errorText <br>";
36
-        }
37
-    }
32
+		if(isset($result['affected']) && $result['affected']==1) {
33
+			self::$createdConfigurationKeys[] = 'Test My height';
34
+		} else {
35
+			echo "$errorText <br>";
36
+		}
37
+	}
38 38
 
39
-    public function testConfigurationMemberFromArray()
40
-    {
41
-        $memberConfiguration = MemberConfiguration::fromArray([
42
-            'member_id'     =>  444444,
43
-            'config_key'    =>  'test_key',
44
-            'config_value'  =>  'test_value'
45
-        ]);
39
+	public function testConfigurationMemberFromArray()
40
+	{
41
+		$memberConfiguration = MemberConfiguration::fromArray([
42
+			'member_id'     =>  444444,
43
+			'config_key'    =>  'test_key',
44
+			'config_value'  =>  'test_value'
45
+		]);
46 46
 
47
-        $this->assertEquals($memberConfiguration->member_id, 444444 ,"member_id != 444444");
48
-        $this->assertEquals($memberConfiguration->config_key, 'test_key' ,"config_key != 'test_key'");
49
-        $this->assertEquals($memberConfiguration->config_value, 'test_value' ,"config_value != 'test_value'");
50
-    }
47
+		$this->assertEquals($memberConfiguration->member_id, 444444 ,"member_id != 444444");
48
+		$this->assertEquals($memberConfiguration->config_key, 'test_key' ,"config_key != 'test_key'");
49
+		$this->assertEquals($memberConfiguration->config_value, 'test_value' ,"config_value != 'test_value'");
50
+	}
51 51
 
52
-    public function testToArray()
53
-    {
54
-        $memberConfiguration = MemberConfiguration::fromArray([
55
-            'member_id'     =>  444444,
56
-            'config_key'    =>  'test_key',
57
-            'config_value'  =>  'test_value'
58
-        ]);
52
+	public function testToArray()
53
+	{
54
+		$memberConfiguration = MemberConfiguration::fromArray([
55
+			'member_id'     =>  444444,
56
+			'config_key'    =>  'test_key',
57
+			'config_value'  =>  'test_value'
58
+		]);
59 59
 
60
-        $this->assertEquals($memberConfiguration->toArray(), [
61
-            'member_id'     =>  444444,
62
-            'config_key'    =>  'test_key',
63
-            'config_value'  =>  'test_value'
64
-         ]);
65
-    }
60
+		$this->assertEquals($memberConfiguration->toArray(), [
61
+			'member_id'     =>  444444,
62
+			'config_key'    =>  'test_key',
63
+			'config_value'  =>  'test_value'
64
+		 ]);
65
+	}
66 66
 
67
-    public function testBadParameter()
68
-    {
69
-        $this->expectException(BadParam::class);
67
+	public function testBadParameter()
68
+	{
69
+		$this->expectException(BadParam::class);
70 70
 
71
-        $memberConfiguration = MemberConfiguration::fromArray([
72
-            'memberID'   => 44444444,
73
-            'config_kkk' => 'test_key'
74
-        ]);
71
+		$memberConfiguration = MemberConfiguration::fromArray([
72
+			'memberID'   => 44444444,
73
+			'config_kkk' => 'test_key'
74
+		]);
75 75
 
76
-        echo "memberConfiguration: ".$memberConfiguration->memberID." <br>";
77
-    }
76
+		echo "memberConfiguration: ".$memberConfiguration->memberID." <br>";
77
+	}
78 78
 
79
-    public function testGetAllConfigurationData()
80
-    {
81
-        $memberConfiguration = new MemberConfiguration();
79
+	public function testGetAllConfigurationData()
80
+	{
81
+		$memberConfiguration = new MemberConfiguration();
82 82
 
83
-        $result = $memberConfiguration->GetConfigurationData();
84
-
85
-        $this->assertNotNull($result);
86
-        $this->assertTrue(isset($result['result']), "Wrong response for member configuration data.");
87
-        $this->assertEquals($result['result'], "OK", "Cannot retrieve the member configuration data.");
88
-    }
83
+		$result = $memberConfiguration->GetConfigurationData();
84
+
85
+		$this->assertNotNull($result);
86
+		$this->assertTrue(isset($result['result']), "Wrong response for member configuration data.");
87
+		$this->assertEquals($result['result'], "OK", "Cannot retrieve the member configuration data.");
88
+	}
89 89
 
90
-    public function testGetSpecificConfigurationKeyData()
91
-    {
92
-        $memberConfiguration = new MemberConfiguration();
93
-
94
-        $allData = $memberConfiguration->GetConfigurationData();
95
-
96
-        $this->assertNotNull($allData);
97
-        $this->assertTrue(isset($allData['data']), "Wrong response for member configuration data.");
98
-        $this->assertTrue(sizeof($allData['data'])>0, "Retrieved member data size <1");
99
-
100
-        $query = [
101
-            'config_key' => $allData['data'][0]['config_key']
102
-        ];
103
-
104
-        $result = $memberConfiguration->GetConfigurationData($query);
105
-
106
-        $this->assertNotNull($result);
107
-        $this->assertTrue(isset($result['data']), "Wrong response for member configuration data.");
108
-        $this->assertTrue(sizeof($result['data'])==1, "Retrieved member data size != 1");
109
-        $this->assertEquals($result['data'][0]['config_key'], $allData['data'][0]['config_key']);
110
-    }
111
-
112
-    public function testCreateConfigurationData()
113
-    {
114
-        $memberConfiguration = new MemberConfiguration();
115
-
116
-        $memberConfiguration->config_key = 'Test My weight';
117
-        $memberConfiguration->config_value = '100';
118
-
119
-        $result = $memberConfiguration->CreateNewConfigurationData($memberConfiguration->toArray(), $errorText);
120
-
121
-        $this->assertNotNull($result);
122
-        $this->assertTrue(isset($result['result']), "Wrong response for member configuration data.");
123
-        $this->assertTrue(isset($result['affected']), "Wrong response for member configuration data.");
124
-        $this->assertEquals(1, $result['affected'], "Cannot create new member configuration data <br> $errorText");
125
-
126
-        if($result['affected']==1) {
127
-            self::$createdConfigurationKeys[] = 'Test My weight';
128
-        }
129
-    }
130
-
131
-    public function testUpdateConfigurationData()
132
-    {
133
-        $memberConfiguration = new MemberConfiguration();
134
-
135
-        $memberConfiguration->config_key = 'Test My height';
136
-        $memberConfiguration->config_value = '120';
137
-
138
-        $result = $memberConfiguration->UpdateConfigurationData($memberConfiguration->toArray(), $errorText);
139
-
140
-        $this->assertNotNull($result);
141
-        $this->assertTrue(isset($result['result']), "Wrong response for member configuration data.");
142
-        $this->assertTrue(isset($result['affected']), "Wrong response for member configuration data.");
143
-        $this->assertEquals(1, $result['affected'], "Cannot update member configuration data <br> $errorText");
144
-
145
-        $query = [
146
-            'config_key' => 'Test My height'
147
-        ];
148
-
149
-        $updatedResult = $memberConfiguration->GetConfigurationData($query);
150
-
151
-        $this->assertNotNull($updatedResult);
152
-        $this->assertTrue(isset($updatedResult['data']), "Wrong response for member configuration data.");
153
-        $this->assertTrue(sizeof($updatedResult['data'])==1, "Retrieved member data size != 1");
154
-        $this->assertEquals('120', $updatedResult['data'][0]['config_value'], "The config value is not updated");
155
-    }
156
-
157
-    public function testRemoveConfigurationData()
158
-    {
159
-        $memberConfiguration = new MemberConfiguration();
160
-
161
-        $query = [
162
-            'config_key' => 'Test My height'
163
-        ];
90
+	public function testGetSpecificConfigurationKeyData()
91
+	{
92
+		$memberConfiguration = new MemberConfiguration();
93
+
94
+		$allData = $memberConfiguration->GetConfigurationData();
95
+
96
+		$this->assertNotNull($allData);
97
+		$this->assertTrue(isset($allData['data']), "Wrong response for member configuration data.");
98
+		$this->assertTrue(sizeof($allData['data'])>0, "Retrieved member data size <1");
99
+
100
+		$query = [
101
+			'config_key' => $allData['data'][0]['config_key']
102
+		];
103
+
104
+		$result = $memberConfiguration->GetConfigurationData($query);
105
+
106
+		$this->assertNotNull($result);
107
+		$this->assertTrue(isset($result['data']), "Wrong response for member configuration data.");
108
+		$this->assertTrue(sizeof($result['data'])==1, "Retrieved member data size != 1");
109
+		$this->assertEquals($result['data'][0]['config_key'], $allData['data'][0]['config_key']);
110
+	}
111
+
112
+	public function testCreateConfigurationData()
113
+	{
114
+		$memberConfiguration = new MemberConfiguration();
115
+
116
+		$memberConfiguration->config_key = 'Test My weight';
117
+		$memberConfiguration->config_value = '100';
118
+
119
+		$result = $memberConfiguration->CreateNewConfigurationData($memberConfiguration->toArray(), $errorText);
120
+
121
+		$this->assertNotNull($result);
122
+		$this->assertTrue(isset($result['result']), "Wrong response for member configuration data.");
123
+		$this->assertTrue(isset($result['affected']), "Wrong response for member configuration data.");
124
+		$this->assertEquals(1, $result['affected'], "Cannot create new member configuration data <br> $errorText");
125
+
126
+		if($result['affected']==1) {
127
+			self::$createdConfigurationKeys[] = 'Test My weight';
128
+		}
129
+	}
130
+
131
+	public function testUpdateConfigurationData()
132
+	{
133
+		$memberConfiguration = new MemberConfiguration();
134
+
135
+		$memberConfiguration->config_key = 'Test My height';
136
+		$memberConfiguration->config_value = '120';
137
+
138
+		$result = $memberConfiguration->UpdateConfigurationData($memberConfiguration->toArray(), $errorText);
139
+
140
+		$this->assertNotNull($result);
141
+		$this->assertTrue(isset($result['result']), "Wrong response for member configuration data.");
142
+		$this->assertTrue(isset($result['affected']), "Wrong response for member configuration data.");
143
+		$this->assertEquals(1, $result['affected'], "Cannot update member configuration data <br> $errorText");
144
+
145
+		$query = [
146
+			'config_key' => 'Test My height'
147
+		];
148
+
149
+		$updatedResult = $memberConfiguration->GetConfigurationData($query);
150
+
151
+		$this->assertNotNull($updatedResult);
152
+		$this->assertTrue(isset($updatedResult['data']), "Wrong response for member configuration data.");
153
+		$this->assertTrue(sizeof($updatedResult['data'])==1, "Retrieved member data size != 1");
154
+		$this->assertEquals('120', $updatedResult['data'][0]['config_value'], "The config value is not updated");
155
+	}
156
+
157
+	public function testRemoveConfigurationData()
158
+	{
159
+		$memberConfiguration = new MemberConfiguration();
160
+
161
+		$query = [
162
+			'config_key' => 'Test My height'
163
+		];
164 164
 
165
-        $removed = $memberConfiguration->RemoveConfigurationData($query, $errorText);
165
+		$removed = $memberConfiguration->RemoveConfigurationData($query, $errorText);
166 166
 
167
-        echo (isset($removed['affected']) && $removed['affected']==1)
168
-            ? "The config data with key 'Test My height' removed"
169
-            : "The config data with key 'Test My height' cannot remove - ".$errorText;
167
+		echo (isset($removed['affected']) && $removed['affected']==1)
168
+			? "The config data with key 'Test My height' removed"
169
+			: "The config data with key 'Test My height' cannot remove - ".$errorText;
170 170
 
171
-        $this->assertNotNull($removed);
172
-        $this->assertTrue(isset($removed['result']), "Wrong response for member configuration data.");
173
-        $this->assertTrue(isset($removed['affected']), "Wrong response for member configuration data.");
174
-        $this->assertEquals(1, $removed['affected'], "Cannot create new member configuration data");
171
+		$this->assertNotNull($removed);
172
+		$this->assertTrue(isset($removed['result']), "Wrong response for member configuration data.");
173
+		$this->assertTrue(isset($removed['affected']), "Wrong response for member configuration data.");
174
+		$this->assertEquals(1, $removed['affected'], "Cannot create new member configuration data");
175 175
 
176
-        if($removed['affected']==1) {
177
-            $key = array_search('Test My height', self::$createdConfigurationKeys);
178
-            array_splice(self::$createdConfigurationKeys, $key, 1);
179
-        }
180
-    }
176
+		if($removed['affected']==1) {
177
+			$key = array_search('Test My height', self::$createdConfigurationKeys);
178
+			array_splice(self::$createdConfigurationKeys, $key, 1);
179
+		}
180
+	}
181 181
 
182
-    public static function tearDownAfterClass()
183
-    {
184
-        $memberConfiguration = new MemberConfiguration();
182
+	public static function tearDownAfterClass()
183
+	{
184
+		$memberConfiguration = new MemberConfiguration();
185 185
 
186
-        if (sizeof(self::$createdConfigurationKeys)>0) {
187
-            foreach (self::$createdConfigurationKeys as $configKey) {
188
-                $removed = $memberConfiguration->RemoveConfigurationData(['config_key' => $configKey], $errorText);
186
+		if (sizeof(self::$createdConfigurationKeys)>0) {
187
+			foreach (self::$createdConfigurationKeys as $configKey) {
188
+				$removed = $memberConfiguration->RemoveConfigurationData(['config_key' => $configKey], $errorText);
189 189
 
190
-                echo (isset($removed['affected']) && $removed['affected']==1)
191
-                            ? "The config data with key '$configKey' removed"
192
-                            : "The config data with key '$configKey' cannot remove - ".$errorText;
193
-            }
194
-        }
195
-    }
190
+				echo (isset($removed['affected']) && $removed['affected']==1)
191
+							? "The config data with key '$configKey' removed"
192
+							: "The config data with key '$configKey' cannot remove - ".$errorText;
193
+			}
194
+		}
195
+	}
196 196
 }
Please login to merge, or discard this patch.
UnitTestFiles/Test/CustomNoteTypeResponseUnitTests.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 class CustomNoteTypeResponseUnitTests extends \PHPUnit\Framework\TestCase
8 8
 {
9
-    public function testFromArray()
10
-    {
11
-        $customNoteTypeResponse = CustomNoteTypeResponse::fromArray([
12
-            'note_custom_type_id'       => 10,
13
-            'note_custom_type'          => 'Dropoff Location',
14
-            'root_owner_member_id'      => 1,
15
-            'note_custom_type_values'   => [
16
-                'Front door',
17
-                'Backdoor',
18
-                'Roof'
19
-            ]
20
-        ]);
9
+	public function testFromArray()
10
+	{
11
+		$customNoteTypeResponse = CustomNoteTypeResponse::fromArray([
12
+			'note_custom_type_id'       => 10,
13
+			'note_custom_type'          => 'Dropoff Location',
14
+			'root_owner_member_id'      => 1,
15
+			'note_custom_type_values'   => [
16
+				'Front door',
17
+				'Backdoor',
18
+				'Roof'
19
+			]
20
+		]);
21 21
 
22
-        $this->assertEquals(10, $customNoteTypeResponse->note_custom_type_id);
23
-        $this->assertEquals('Dropoff Location', $customNoteTypeResponse->note_custom_type);
24
-        $this->assertEquals(1, $customNoteTypeResponse->root_owner_member_id);
25
-        $this->assertEquals([
26
-                'Front door',
27
-                'Backdoor',
28
-                'Roof'
29
-            ],
30
-            $customNoteTypeResponse->note_custom_type_values);
31
-    }
22
+		$this->assertEquals(10, $customNoteTypeResponse->note_custom_type_id);
23
+		$this->assertEquals('Dropoff Location', $customNoteTypeResponse->note_custom_type);
24
+		$this->assertEquals(1, $customNoteTypeResponse->root_owner_member_id);
25
+		$this->assertEquals([
26
+				'Front door',
27
+				'Backdoor',
28
+				'Roof'
29
+			],
30
+			$customNoteTypeResponse->note_custom_type_values);
31
+	}
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
UnitTestFiles/Test/OrderTests.php 1 patch
Indentation   +542 added lines, -542 removed lines patch added patch discarded remove patch
@@ -20,546 +20,546 @@
 block discarded – undo
20 20
 
21 21
 class OrderTests extends \PHPUnit\Framework\TestCase
22 22
 {
23
-    public static $createdOrders = [];
24
-    public static $createdProblems = [];
25
-
26
-    public static function setUpBeforeClass()
27
-    {
28
-        Route4Me::setApiKey(Constants::API_KEY);
29
-
30
-        //region -- Create Test Optimization --
31
-
32
-        // Huge list of addresses
33
-        $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);
34
-        $json = array_slice($json, 0, 10);
35
-
36
-        $addresses = [];
37
-        foreach ($json as $address) {
38
-            $addresses[] = Address::fromArray($address);
39
-        }
40
-
41
-        $parameters = RouteParameters::fromArray([
42
-            'algorithm_type'    => Algorithmtype::TSP,
43
-            'route_name'        => 'Single Driver Multiple TW 10 Stops '.date('Y-m-d H:i'),
44
-            'route_date'        => time() + 24 * 60 * 60,
45
-            'route_time'        => 5 * 3600 + 30 * 60,
46
-            'distance_unit'     => DistanceUnit::MILES,
47
-            'device_type'       => DeviceType::WEB,
48
-            'optimize'          => OptimizationType::DISTANCE,
49
-            'metric'            => Metric::GEODESIC,
50
-        ]);
51
-
52
-        $optimizationParams = new OptimizationProblemParams();
53
-        $optimizationParams->setAddresses($addresses);
54
-        $optimizationParams->setParameters($parameters);
55
-
56
-        $problem = OptimizationProblem::optimize($optimizationParams);
57
-
58
-        self::$createdProblems[] = $problem;
59
-
60
-        //endregion
61
-
62
-        //region -- Create Test Order --
63
-
64
-        $orderParameters = Order::fromArray([
65
-            'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
66
-            'cached_lat'                => 48.335991,
67
-            'cached_lng'                => 31.18287,
68
-            'address_alias'             => 'Auto test address',
69
-            'address_city'              => 'Philadelphia',
70
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
71
-            'EXT_FIELD_first_name'      => 'Igor',
72
-            'EXT_FIELD_last_name'       => 'Progman',
73
-            'EXT_FIELD_email'           => '[email protected]',
74
-            'EXT_FIELD_phone'           => '380380380380',
75
-            'EXT_FIELD_custom_data'     => [
76
-                0 => [
77
-                    'order_id'  => '10',
78
-                    'name'      => 'Bill Soul',
79
-                ],
80
-            ],
81
-        ]);
82
-
83
-        $order = new Order();
84
-
85
-        $response = $order->addOrder($orderParameters);
86
-
87
-        self::assertNotNull($response);
88
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
89
-
90
-        self::$createdOrders[] = $response;
91
-
92
-        //endregion
93
-    }
94
-
95
-    public function testFromArray()
96
-    {
97
-        $orderParameters = Order::fromArray([
98
-            'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
99
-            'cached_lat'                => 48.335991,
100
-            'cached_lng'                => 31.18287,
101
-            'address_alias'             => 'Auto test address',
102
-            'address_city'              => 'Philadelphia',
103
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
104
-            'EXT_FIELD_first_name'      => 'Igor',
105
-            'EXT_FIELD_last_name'       => 'Progman',
106
-            'EXT_FIELD_email'           => '[email protected]',
107
-            'EXT_FIELD_phone'           => '380380380380',
108
-            'EXT_FIELD_custom_data'     => [
109
-                0 => [
110
-                    'order_id'  => '10',
111
-                    'name'      => 'Bill Soul',
112
-                ],
113
-            ],
114
-        ]);
115
-
116
-        $this->assertEquals('1358 E Luzerne St, Philadelphia, PA 19124, US', $orderParameters->address_1);
117
-        $this->assertEquals(48.335991, $orderParameters->cached_lat);
118
-        $this->assertEquals(31.18287, $orderParameters->cached_lng);
119
-        $this->assertEquals('Auto test address', $orderParameters->address_alias);
120
-        $this->assertEquals('Philadelphia', $orderParameters->address_city);
121
-        $this->assertEquals(date('Y-m-d'), $orderParameters->day_scheduled_for_YYMMDD);
122
-        $this->assertEquals('Igor', $orderParameters->EXT_FIELD_first_name);
123
-        $this->assertEquals('Progman', $orderParameters->EXT_FIELD_last_name);
124
-        $this->assertEquals('[email protected]', $orderParameters->EXT_FIELD_email);
125
-        $this->assertEquals('380380380380', $orderParameters->EXT_FIELD_phone);
126
-        $this->assertEquals([
127
-            0 => [
128
-                'order_id'  => '10',
129
-                'name'      => 'Bill Soul',
130
-            ],
131
-        ], $orderParameters->EXT_FIELD_custom_data);
132
-    }
133
-
134
-    public function testToArray()
135
-    {
136
-        $orderParameters = Order::fromArray([
137
-            'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
138
-            'cached_lat'                => 48.335991,
139
-            'cached_lng'                => 31.18287,
140
-            'address_alias'             => 'Auto test address',
141
-            'address_city'              => 'Philadelphia',
142
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
143
-            'EXT_FIELD_first_name'      => 'Igor',
144
-            'EXT_FIELD_last_name'       => 'Progman',
145
-            'EXT_FIELD_email'           => '[email protected]',
146
-            'EXT_FIELD_phone'           => '380380380380',
147
-            'EXT_FIELD_custom_data'     => [
148
-                0 => [
149
-                    'order_id'  => '10',
150
-                    'name'      => 'Bill Soul',
151
-                ],
152
-            ],
153
-        ]);
154
-
155
-        $this->assertEquals($orderParameters->toArray(),
156
-            [
157
-                'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
158
-                'cached_lat'                => 48.335991,
159
-                'cached_lng'                => 31.18287,
160
-                'address_alias'             => 'Auto test address',
161
-                'address_city'              => 'Philadelphia',
162
-                'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
163
-                'EXT_FIELD_first_name'      => 'Igor',
164
-                'EXT_FIELD_last_name'       => 'Progman',
165
-                'EXT_FIELD_email'           => '[email protected]',
166
-                'EXT_FIELD_phone'           => '380380380380',
167
-                'EXT_FIELD_custom_data'     => [
168
-                    0 => [
169
-                        'order_id'  => '10',
170
-                        'name'      => 'Bill Soul',
171
-                    ],
172
-                ],
173
-            ]
174
-        );
175
-    }
176
-
177
-    public function testGetOrders()
178
-    {
179
-        $order = new Order();
180
-
181
-        $orderParameters = Order::fromArray([
182
-            'offset'    => 0,
183
-            'limit'     => 5,
184
-        ]);
185
-
186
-        $response = $order->getOrders($orderParameters);
187
-
188
-        $this->assertNotNull($response);
189
-        $this->assertTrue(is_array($response));
190
-        $this->assertTrue(isset($response['total']));
191
-        $this->assertTrue(isset($response['results']));
192
-        $this->assertInstanceOf(
193
-            Order::class,
194
-            Order::fromArray($response['results'][0])
195
-        );
196
-    }
197
-
198
-    public function testCreateNewOrder()
199
-    {
200
-        $orderParameters = Order::fromArray([
201
-            'address_1'                 => '106 Liberty St, New York, NY 10006, USA',
202
-            'address_alias'             => 'BK Restaurant #: 2446',
203
-            'cached_lat'                => 40.709637,
204
-            'cached_lng'                => -74.011912,
205
-            'curbside_lat'              => 40.709637,
206
-            'curbside_lng'              => -74.011912,
207
-            'address_city'              => 'New York',
208
-            'EXT_FIELD_first_name'      => 'Lui',
209
-            'EXT_FIELD_last_name'       => 'Carol',
210
-            'EXT_FIELD_email'           => '[email protected]',
211
-            'EXT_FIELD_phone'           => '897946541',
212
-            'local_time_window_end'     => 39000,
213
-            'local_time_window_end_2'   => 46200,
214
-            'local_time_window_start'   => 37800,
215
-            'local_time_window_start_2' => 45000,
216
-            'local_timezone_string'     => 'America/New_York',
217
-            'order_icon'                => 'emoji/emoji-bank',
218
-        ]);
219
-
220
-        $order = new Order();
221
-
222
-        $response = $order->addOrder($orderParameters);
223
-
224
-        self::assertNotNull($response);
225
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
226
-
227
-        self::$createdOrders[] = $response;
228
-    }
229
-
230
-    public function testAddOrdersToOptimization()
231
-    {
232
-        $body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_optimization_data.json'), true);
233
-
234
-        $optimizationProblemId = self::$createdProblems[0]->optimization_problem_id;
235
-
236
-        $orderParameters = [
237
-            'optimization_problem_id'   => $optimizationProblemId,
238
-            'redirect'                  => 0,
239
-            'device_type'               => 'web',
240
-            'addresses'                 => $body['addresses'],
241
-        ];
242
-
243
-        $order = new Order();
244
-
245
-        $response = $order->addOrder2Optimization($orderParameters);
246
-
247
-        self::assertNotNull($response);
248
-        self::assertInstanceOf(OptimizationProblem::class, OptimizationProblem::fromArray($response));
249
-    }
250
-
251
-    public function testAddOrdersToRoute()
252
-    {
253
-        $body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_route_data.json'), true);
254
-
255
-        $routeId = self::$createdProblems[0]->routes[0]->route_id;
256
-
257
-        $orderParameters = Order::fromArray([
258
-            'route_id'  => $routeId,
259
-            'redirect'  => 0,
260
-            'addresses' => $body['addresses'],
261
-        ]);
262
-
263
-        $order = new Order();
264
-
265
-        $response = $order->addOrder2Route($orderParameters);
266
-
267
-        self::assertNotNull($response);
268
-        self::assertInstanceOf(Route::class, Route::fromArray($response));
269
-    }
270
-
271
-    public function testAddScheduledOrder()
272
-    {
273
-        $orderParameters = Order::fromArray([
274
-            'address_1'                 => '318 S 39th St, Louisville, KY 40212, USA',
275
-            'cached_lat'                => 38.259326,
276
-            'cached_lng'                => -85.814979,
277
-            'curbside_lat'              => 38.259326,
278
-            'curbside_lng'              => -85.814979,
279
-            'address_alias'             => '318 S 39th St 40212',
280
-            'address_city'              => 'Louisville',
281
-            'EXT_FIELD_first_name'      => 'Lui',
282
-            'EXT_FIELD_last_name'       => 'Carol',
283
-            'EXT_FIELD_email'           => '[email protected]',
284
-            'EXT_FIELD_phone'           => '897946541',
285
-            'EXT_FIELD_custom_data'     => ['order_type' => 'scheduled order'],
286
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
287
-            'local_time_window_end'     => 39000,
288
-            'local_time_window_end_2'   => 46200,
289
-            'local_time_window_start'   => 37800,
290
-            'local_time_window_start_2' => 45000,
291
-            'local_timezone_string'     => 'America/New_York',
292
-            'order_icon'                => 'emoji/emoji-bank',
293
-        ]);
294
-
295
-        $order = new Order();
296
-
297
-        $response = $order->addOrder($orderParameters);
298
-
299
-        self::assertNotNull($response);
300
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
301
-
302
-        self::$createdOrders[] = $response;
303
-    }
304
-
305
-    public function testCreateOrderWithCustomField()
306
-    {
307
-        $orderParameters = Order::fromArray([
308
-            'address_1'                => '1358 E Luzerne St, Philadelphia, PA 19124, US',
309
-            'cached_lat'               => 48.335991,
310
-            'cached_lng'               => 31.18287,
311
-            'day_scheduled_for_YYMMDD' => '2019-10-11',
312
-            'address_alias'            => 'Auto test address',
313
-            'custom_user_fields' => [
314
-                OrderCustomField::fromArray([
315
-                    'order_custom_field_id'    => 93,
316
-                    'order_custom_field_value' => 'false'
317
-                ])
318
-            ]
319
-        ]);
320
-
321
-        $order = new Order();
322
-
323
-        $response = $order->addOrder($orderParameters);
324
-
325
-        self::assertNotNull($response);
326
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
327
-        $this->assertEquals(93,$response['custom_user_fields'][0]['order_custom_field_id']);
328
-        $this->assertEquals('false',$response['custom_user_fields'][0]['order_custom_field_value']);
329
-
330
-        self::$createdOrders[] = $response;
331
-    }
332
-
333
-    public function testGetOrderByID()
334
-    {
335
-        $order = new Order();
336
-
337
-        $orderID = self::$createdOrders[0]['order_id'];
338
-
339
-        // Get an order
340
-        $orderParameters = Order::fromArray([
341
-            'order_id' => $orderID,
342
-        ]);
343
-
344
-        $response = $order->getOrder($orderParameters);
345
-
346
-        self::assertNotNull($response);
347
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
348
-    }
349
-
350
-    public function testGetOrderByInsertedDate()
351
-    {
352
-        $orderParameters = Order::fromArray([
353
-            'day_added_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
354
-            'offset'            => 0,
355
-            'limit'             => 5,
356
-        ]);
357
-
358
-        $order = new Order();
359
-
360
-        $response = $order->getOrder($orderParameters);
361
-
362
-        $this->assertNotNull($response);
363
-        $this->assertTrue(is_array($response));
364
-        $this->assertTrue(isset($response['total']));
365
-        $this->assertTrue(isset($response['results']));
366
-        $this->assertInstanceOf(
367
-            Order::class,
368
-            Order::fromArray($response['results'][0])
369
-        );
370
-    }
371
-
372
-    public function testGetOrderByScheduledDate()
373
-    {
374
-        $orderParameters = Order::fromArray([
375
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
376
-            'offset'                    => 0,
377
-            'limit'                     => 5,
378
-        ]);
379
-
380
-        $order = new Order();
381
-
382
-        $response = $order->getOrder($orderParameters);
383
-
384
-        $this->assertNotNull($response);
385
-        $this->assertTrue(is_array($response));
386
-        $this->assertTrue(isset($response['total']));
387
-        $this->assertTrue(isset($response['results']));
388
-        $this->assertInstanceOf(
389
-            Order::class,
390
-            Order::fromArray($response['results'][0])
391
-        );
392
-    }
393
-
394
-    public function testGetOrdersByCustomFields()
395
-    {
396
-        $orderParameters = Order::fromArray([
397
-            'fields'    => 'order_id,member_id',
398
-            'offset'    => 0,
399
-            'limit'     => 5,
400
-        ]);
401
-
402
-        $order = new Order();
403
-
404
-        $response = $order->getOrder($orderParameters);
405
-
406
-        $response = $order->getOrder($orderParameters);
407
-
408
-        $this->assertNotNull($response);
409
-        $this->assertTrue(is_array($response));
410
-        $this->assertTrue(isset($response['total']));
411
-        $this->assertTrue(isset($response['results']));
412
-        $this->assertTrue(isset($response['fields']));
413
-        $this->assertInstanceOf(
414
-            Order::class,
415
-            Order::fromArray($response['results'][0])
416
-        );
417
-    }
418
-
419
-    public function testGetOrdersByScheduleFilter()
420
-    {
421
-        $orderParameters = Order::fromArray([
422
-            'limit'  => 5,
423
-            'filter' => [
424
-                'display'               => 'all',
425
-                'scheduled_for_YYMMDD'  => [
426
-                    date('Y-m-d', strtotime('-1 days')),
427
-                    date('Y-m-d', strtotime('1 days'))
428
-                ]
429
-            ]
430
-        ]);
431
-
432
-        $order = new Order();
433
-
434
-        $response = $order->getOrder($orderParameters);
435
-
436
-        $this->assertNotNull($response);
437
-        $this->assertTrue(is_array($response));
438
-        $this->assertTrue(isset($response['total']));
439
-        $this->assertTrue(isset($response['results']));
440
-        $this->assertInstanceOf(
441
-            Order::class,
442
-            Order::fromArray($response['results'][0])
443
-        );
444
-    }
445
-
446
-    public function testGetOrdersBySpecifiedText()
447
-    {
448
-        $orderParameters = Order::fromArray([
449
-            'query'     => 'Auto test',
450
-            'offset'    => 0,
451
-            'limit'     => 5,
452
-        ]);
453
-
454
-        $order = new Order();
455
-
456
-        $response = $order->getOrder($orderParameters);
457
-
458
-        $this->assertNotNull($response);
459
-        $this->assertTrue(is_array($response));
460
-        $this->assertTrue(isset($response['total']));
461
-        $this->assertTrue(isset($response['results']));
462
-        $this->assertInstanceOf(
463
-            Order::class,
464
-            Order::fromArray($response['results'][0])
465
-        );
466
-    }
467
-
468
-    public function testUpdateOrder()
469
-    {
470
-        $order = new Order();
471
-
472
-        // Update the order
473
-        self::$createdOrders[0]['address_2'] = 'Lviv';
474
-        self::$createdOrders[0]['EXT_FIELD_phone'] = '032268593';
475
-        self::$createdOrders[0]['EXT_FIELD_custom_data'] = [
476
-            0 => [
477
-                'customer_no' => '11',
478
-            ],
479
-        ];
480
-
481
-        $response = $order->updateOrder(self::$createdOrders[0]);
482
-
483
-        $this->assertNotNull($response);
484
-        $this->assertInstanceOf(Order::class, Order::fromArray($response));
485
-        $this->assertEquals('Lviv', $response['address_2']);
486
-        $this->assertEquals('032268593', $response['EXT_FIELD_phone']);
487
-        $this->assertEquals(
488
-            [
489
-                0 => [ 'customer_no' => '11' ],
490
-            ],
491
-            $response['EXT_FIELD_custom_data']
492
-        );
493
-    }
494
-
495
-    public function testUpdateOrderWithCustomFiel()
496
-    {
497
-        $orderParameters = Order::fromArray([
498
-            'order_id'              => self::$createdOrders[0]['order_id'],
499
-            'custom_user_fields'    => [
500
-                OrderCustomField::fromArray([
501
-                    'order_custom_field_id'    => 93,
502
-                    'order_custom_field_value' => 'true'
503
-                ])
504
-            ]
505
-        ]);
506
-
507
-        $order = new Order();
508
-
509
-        $response = $order->updateOrder($orderParameters);
510
-
511
-        $this->assertNotNull($response);
512
-        $this->assertInstanceOf(Order::class, Order::fromArray($response));
513
-        $this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
514
-        $this->assertEquals('true', $response['custom_user_fields'][0]['order_custom_field_value']);
515
-    }
516
-
517
-    public static function tearDownAfterClass()
518
-    {
519
-        if (sizeof(self::$createdOrders)) {
520
-            $orderIDs = [];
521
-
522
-            foreach (self::$createdOrders as $ord) {
523
-                $orderIDs[] = $ord['order_id'];
524
-            }
525
-
526
-            $orderParameters = Order::fromArray([
527
-                'order_ids' => $orderIDs
528
-            ]);
529
-
530
-            $order = new Order();
531
-
532
-            $response = $order->removeOrder($orderParameters);
533
-
534
-            if (!is_null($response) &&
535
-                isset($response['status']) &&
536
-                $response['status']) {
537
-                echo "The test orders removed <br>";
538
-            }
539
-        }
540
-
541
-        if (sizeof(self::$createdProblems)>0) {
542
-            $optimizationProblemIDs = [];
543
-
544
-            foreach (self::$createdProblems as $problem) {
545
-                $optimizationProblemId = $problem->optimization_problem_id;
546
-
547
-                $optimizationProblemIDs[] = $optimizationProblemId;
548
-            }
549
-
550
-            $params = [
551
-                'optimization_problem_ids' => $optimizationProblemIDs,
552
-                'redirect'                 => 0,
553
-            ];
554
-
555
-            $problem = new OptimizationProblem();
556
-            $result = $problem->removeOptimization($params);
557
-
558
-            if ($result!=null && $result['status']==true) {
559
-                echo "The test optimizations were removed <br>";
560
-            } else {
561
-                echo "Cannot remove the test optimizations <br>";
562
-            }
563
-        }
564
-    }
23
+	public static $createdOrders = [];
24
+	public static $createdProblems = [];
25
+
26
+	public static function setUpBeforeClass()
27
+	{
28
+		Route4Me::setApiKey(Constants::API_KEY);
29
+
30
+		//region -- Create Test Optimization --
31
+
32
+		// Huge list of addresses
33
+		$json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);
34
+		$json = array_slice($json, 0, 10);
35
+
36
+		$addresses = [];
37
+		foreach ($json as $address) {
38
+			$addresses[] = Address::fromArray($address);
39
+		}
40
+
41
+		$parameters = RouteParameters::fromArray([
42
+			'algorithm_type'    => Algorithmtype::TSP,
43
+			'route_name'        => 'Single Driver Multiple TW 10 Stops '.date('Y-m-d H:i'),
44
+			'route_date'        => time() + 24 * 60 * 60,
45
+			'route_time'        => 5 * 3600 + 30 * 60,
46
+			'distance_unit'     => DistanceUnit::MILES,
47
+			'device_type'       => DeviceType::WEB,
48
+			'optimize'          => OptimizationType::DISTANCE,
49
+			'metric'            => Metric::GEODESIC,
50
+		]);
51
+
52
+		$optimizationParams = new OptimizationProblemParams();
53
+		$optimizationParams->setAddresses($addresses);
54
+		$optimizationParams->setParameters($parameters);
55
+
56
+		$problem = OptimizationProblem::optimize($optimizationParams);
57
+
58
+		self::$createdProblems[] = $problem;
59
+
60
+		//endregion
61
+
62
+		//region -- Create Test Order --
63
+
64
+		$orderParameters = Order::fromArray([
65
+			'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
66
+			'cached_lat'                => 48.335991,
67
+			'cached_lng'                => 31.18287,
68
+			'address_alias'             => 'Auto test address',
69
+			'address_city'              => 'Philadelphia',
70
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
71
+			'EXT_FIELD_first_name'      => 'Igor',
72
+			'EXT_FIELD_last_name'       => 'Progman',
73
+			'EXT_FIELD_email'           => '[email protected]',
74
+			'EXT_FIELD_phone'           => '380380380380',
75
+			'EXT_FIELD_custom_data'     => [
76
+				0 => [
77
+					'order_id'  => '10',
78
+					'name'      => 'Bill Soul',
79
+				],
80
+			],
81
+		]);
82
+
83
+		$order = new Order();
84
+
85
+		$response = $order->addOrder($orderParameters);
86
+
87
+		self::assertNotNull($response);
88
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
89
+
90
+		self::$createdOrders[] = $response;
91
+
92
+		//endregion
93
+	}
94
+
95
+	public function testFromArray()
96
+	{
97
+		$orderParameters = Order::fromArray([
98
+			'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
99
+			'cached_lat'                => 48.335991,
100
+			'cached_lng'                => 31.18287,
101
+			'address_alias'             => 'Auto test address',
102
+			'address_city'              => 'Philadelphia',
103
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
104
+			'EXT_FIELD_first_name'      => 'Igor',
105
+			'EXT_FIELD_last_name'       => 'Progman',
106
+			'EXT_FIELD_email'           => '[email protected]',
107
+			'EXT_FIELD_phone'           => '380380380380',
108
+			'EXT_FIELD_custom_data'     => [
109
+				0 => [
110
+					'order_id'  => '10',
111
+					'name'      => 'Bill Soul',
112
+				],
113
+			],
114
+		]);
115
+
116
+		$this->assertEquals('1358 E Luzerne St, Philadelphia, PA 19124, US', $orderParameters->address_1);
117
+		$this->assertEquals(48.335991, $orderParameters->cached_lat);
118
+		$this->assertEquals(31.18287, $orderParameters->cached_lng);
119
+		$this->assertEquals('Auto test address', $orderParameters->address_alias);
120
+		$this->assertEquals('Philadelphia', $orderParameters->address_city);
121
+		$this->assertEquals(date('Y-m-d'), $orderParameters->day_scheduled_for_YYMMDD);
122
+		$this->assertEquals('Igor', $orderParameters->EXT_FIELD_first_name);
123
+		$this->assertEquals('Progman', $orderParameters->EXT_FIELD_last_name);
124
+		$this->assertEquals('[email protected]', $orderParameters->EXT_FIELD_email);
125
+		$this->assertEquals('380380380380', $orderParameters->EXT_FIELD_phone);
126
+		$this->assertEquals([
127
+			0 => [
128
+				'order_id'  => '10',
129
+				'name'      => 'Bill Soul',
130
+			],
131
+		], $orderParameters->EXT_FIELD_custom_data);
132
+	}
133
+
134
+	public function testToArray()
135
+	{
136
+		$orderParameters = Order::fromArray([
137
+			'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
138
+			'cached_lat'                => 48.335991,
139
+			'cached_lng'                => 31.18287,
140
+			'address_alias'             => 'Auto test address',
141
+			'address_city'              => 'Philadelphia',
142
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
143
+			'EXT_FIELD_first_name'      => 'Igor',
144
+			'EXT_FIELD_last_name'       => 'Progman',
145
+			'EXT_FIELD_email'           => '[email protected]',
146
+			'EXT_FIELD_phone'           => '380380380380',
147
+			'EXT_FIELD_custom_data'     => [
148
+				0 => [
149
+					'order_id'  => '10',
150
+					'name'      => 'Bill Soul',
151
+				],
152
+			],
153
+		]);
154
+
155
+		$this->assertEquals($orderParameters->toArray(),
156
+			[
157
+				'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
158
+				'cached_lat'                => 48.335991,
159
+				'cached_lng'                => 31.18287,
160
+				'address_alias'             => 'Auto test address',
161
+				'address_city'              => 'Philadelphia',
162
+				'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
163
+				'EXT_FIELD_first_name'      => 'Igor',
164
+				'EXT_FIELD_last_name'       => 'Progman',
165
+				'EXT_FIELD_email'           => '[email protected]',
166
+				'EXT_FIELD_phone'           => '380380380380',
167
+				'EXT_FIELD_custom_data'     => [
168
+					0 => [
169
+						'order_id'  => '10',
170
+						'name'      => 'Bill Soul',
171
+					],
172
+				],
173
+			]
174
+		);
175
+	}
176
+
177
+	public function testGetOrders()
178
+	{
179
+		$order = new Order();
180
+
181
+		$orderParameters = Order::fromArray([
182
+			'offset'    => 0,
183
+			'limit'     => 5,
184
+		]);
185
+
186
+		$response = $order->getOrders($orderParameters);
187
+
188
+		$this->assertNotNull($response);
189
+		$this->assertTrue(is_array($response));
190
+		$this->assertTrue(isset($response['total']));
191
+		$this->assertTrue(isset($response['results']));
192
+		$this->assertInstanceOf(
193
+			Order::class,
194
+			Order::fromArray($response['results'][0])
195
+		);
196
+	}
197
+
198
+	public function testCreateNewOrder()
199
+	{
200
+		$orderParameters = Order::fromArray([
201
+			'address_1'                 => '106 Liberty St, New York, NY 10006, USA',
202
+			'address_alias'             => 'BK Restaurant #: 2446',
203
+			'cached_lat'                => 40.709637,
204
+			'cached_lng'                => -74.011912,
205
+			'curbside_lat'              => 40.709637,
206
+			'curbside_lng'              => -74.011912,
207
+			'address_city'              => 'New York',
208
+			'EXT_FIELD_first_name'      => 'Lui',
209
+			'EXT_FIELD_last_name'       => 'Carol',
210
+			'EXT_FIELD_email'           => '[email protected]',
211
+			'EXT_FIELD_phone'           => '897946541',
212
+			'local_time_window_end'     => 39000,
213
+			'local_time_window_end_2'   => 46200,
214
+			'local_time_window_start'   => 37800,
215
+			'local_time_window_start_2' => 45000,
216
+			'local_timezone_string'     => 'America/New_York',
217
+			'order_icon'                => 'emoji/emoji-bank',
218
+		]);
219
+
220
+		$order = new Order();
221
+
222
+		$response = $order->addOrder($orderParameters);
223
+
224
+		self::assertNotNull($response);
225
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
226
+
227
+		self::$createdOrders[] = $response;
228
+	}
229
+
230
+	public function testAddOrdersToOptimization()
231
+	{
232
+		$body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_optimization_data.json'), true);
233
+
234
+		$optimizationProblemId = self::$createdProblems[0]->optimization_problem_id;
235
+
236
+		$orderParameters = [
237
+			'optimization_problem_id'   => $optimizationProblemId,
238
+			'redirect'                  => 0,
239
+			'device_type'               => 'web',
240
+			'addresses'                 => $body['addresses'],
241
+		];
242
+
243
+		$order = new Order();
244
+
245
+		$response = $order->addOrder2Optimization($orderParameters);
246
+
247
+		self::assertNotNull($response);
248
+		self::assertInstanceOf(OptimizationProblem::class, OptimizationProblem::fromArray($response));
249
+	}
250
+
251
+	public function testAddOrdersToRoute()
252
+	{
253
+		$body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_route_data.json'), true);
254
+
255
+		$routeId = self::$createdProblems[0]->routes[0]->route_id;
256
+
257
+		$orderParameters = Order::fromArray([
258
+			'route_id'  => $routeId,
259
+			'redirect'  => 0,
260
+			'addresses' => $body['addresses'],
261
+		]);
262
+
263
+		$order = new Order();
264
+
265
+		$response = $order->addOrder2Route($orderParameters);
266
+
267
+		self::assertNotNull($response);
268
+		self::assertInstanceOf(Route::class, Route::fromArray($response));
269
+	}
270
+
271
+	public function testAddScheduledOrder()
272
+	{
273
+		$orderParameters = Order::fromArray([
274
+			'address_1'                 => '318 S 39th St, Louisville, KY 40212, USA',
275
+			'cached_lat'                => 38.259326,
276
+			'cached_lng'                => -85.814979,
277
+			'curbside_lat'              => 38.259326,
278
+			'curbside_lng'              => -85.814979,
279
+			'address_alias'             => '318 S 39th St 40212',
280
+			'address_city'              => 'Louisville',
281
+			'EXT_FIELD_first_name'      => 'Lui',
282
+			'EXT_FIELD_last_name'       => 'Carol',
283
+			'EXT_FIELD_email'           => '[email protected]',
284
+			'EXT_FIELD_phone'           => '897946541',
285
+			'EXT_FIELD_custom_data'     => ['order_type' => 'scheduled order'],
286
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
287
+			'local_time_window_end'     => 39000,
288
+			'local_time_window_end_2'   => 46200,
289
+			'local_time_window_start'   => 37800,
290
+			'local_time_window_start_2' => 45000,
291
+			'local_timezone_string'     => 'America/New_York',
292
+			'order_icon'                => 'emoji/emoji-bank',
293
+		]);
294
+
295
+		$order = new Order();
296
+
297
+		$response = $order->addOrder($orderParameters);
298
+
299
+		self::assertNotNull($response);
300
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
301
+
302
+		self::$createdOrders[] = $response;
303
+	}
304
+
305
+	public function testCreateOrderWithCustomField()
306
+	{
307
+		$orderParameters = Order::fromArray([
308
+			'address_1'                => '1358 E Luzerne St, Philadelphia, PA 19124, US',
309
+			'cached_lat'               => 48.335991,
310
+			'cached_lng'               => 31.18287,
311
+			'day_scheduled_for_YYMMDD' => '2019-10-11',
312
+			'address_alias'            => 'Auto test address',
313
+			'custom_user_fields' => [
314
+				OrderCustomField::fromArray([
315
+					'order_custom_field_id'    => 93,
316
+					'order_custom_field_value' => 'false'
317
+				])
318
+			]
319
+		]);
320
+
321
+		$order = new Order();
322
+
323
+		$response = $order->addOrder($orderParameters);
324
+
325
+		self::assertNotNull($response);
326
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
327
+		$this->assertEquals(93,$response['custom_user_fields'][0]['order_custom_field_id']);
328
+		$this->assertEquals('false',$response['custom_user_fields'][0]['order_custom_field_value']);
329
+
330
+		self::$createdOrders[] = $response;
331
+	}
332
+
333
+	public function testGetOrderByID()
334
+	{
335
+		$order = new Order();
336
+
337
+		$orderID = self::$createdOrders[0]['order_id'];
338
+
339
+		// Get an order
340
+		$orderParameters = Order::fromArray([
341
+			'order_id' => $orderID,
342
+		]);
343
+
344
+		$response = $order->getOrder($orderParameters);
345
+
346
+		self::assertNotNull($response);
347
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
348
+	}
349
+
350
+	public function testGetOrderByInsertedDate()
351
+	{
352
+		$orderParameters = Order::fromArray([
353
+			'day_added_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
354
+			'offset'            => 0,
355
+			'limit'             => 5,
356
+		]);
357
+
358
+		$order = new Order();
359
+
360
+		$response = $order->getOrder($orderParameters);
361
+
362
+		$this->assertNotNull($response);
363
+		$this->assertTrue(is_array($response));
364
+		$this->assertTrue(isset($response['total']));
365
+		$this->assertTrue(isset($response['results']));
366
+		$this->assertInstanceOf(
367
+			Order::class,
368
+			Order::fromArray($response['results'][0])
369
+		);
370
+	}
371
+
372
+	public function testGetOrderByScheduledDate()
373
+	{
374
+		$orderParameters = Order::fromArray([
375
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
376
+			'offset'                    => 0,
377
+			'limit'                     => 5,
378
+		]);
379
+
380
+		$order = new Order();
381
+
382
+		$response = $order->getOrder($orderParameters);
383
+
384
+		$this->assertNotNull($response);
385
+		$this->assertTrue(is_array($response));
386
+		$this->assertTrue(isset($response['total']));
387
+		$this->assertTrue(isset($response['results']));
388
+		$this->assertInstanceOf(
389
+			Order::class,
390
+			Order::fromArray($response['results'][0])
391
+		);
392
+	}
393
+
394
+	public function testGetOrdersByCustomFields()
395
+	{
396
+		$orderParameters = Order::fromArray([
397
+			'fields'    => 'order_id,member_id',
398
+			'offset'    => 0,
399
+			'limit'     => 5,
400
+		]);
401
+
402
+		$order = new Order();
403
+
404
+		$response = $order->getOrder($orderParameters);
405
+
406
+		$response = $order->getOrder($orderParameters);
407
+
408
+		$this->assertNotNull($response);
409
+		$this->assertTrue(is_array($response));
410
+		$this->assertTrue(isset($response['total']));
411
+		$this->assertTrue(isset($response['results']));
412
+		$this->assertTrue(isset($response['fields']));
413
+		$this->assertInstanceOf(
414
+			Order::class,
415
+			Order::fromArray($response['results'][0])
416
+		);
417
+	}
418
+
419
+	public function testGetOrdersByScheduleFilter()
420
+	{
421
+		$orderParameters = Order::fromArray([
422
+			'limit'  => 5,
423
+			'filter' => [
424
+				'display'               => 'all',
425
+				'scheduled_for_YYMMDD'  => [
426
+					date('Y-m-d', strtotime('-1 days')),
427
+					date('Y-m-d', strtotime('1 days'))
428
+				]
429
+			]
430
+		]);
431
+
432
+		$order = new Order();
433
+
434
+		$response = $order->getOrder($orderParameters);
435
+
436
+		$this->assertNotNull($response);
437
+		$this->assertTrue(is_array($response));
438
+		$this->assertTrue(isset($response['total']));
439
+		$this->assertTrue(isset($response['results']));
440
+		$this->assertInstanceOf(
441
+			Order::class,
442
+			Order::fromArray($response['results'][0])
443
+		);
444
+	}
445
+
446
+	public function testGetOrdersBySpecifiedText()
447
+	{
448
+		$orderParameters = Order::fromArray([
449
+			'query'     => 'Auto test',
450
+			'offset'    => 0,
451
+			'limit'     => 5,
452
+		]);
453
+
454
+		$order = new Order();
455
+
456
+		$response = $order->getOrder($orderParameters);
457
+
458
+		$this->assertNotNull($response);
459
+		$this->assertTrue(is_array($response));
460
+		$this->assertTrue(isset($response['total']));
461
+		$this->assertTrue(isset($response['results']));
462
+		$this->assertInstanceOf(
463
+			Order::class,
464
+			Order::fromArray($response['results'][0])
465
+		);
466
+	}
467
+
468
+	public function testUpdateOrder()
469
+	{
470
+		$order = new Order();
471
+
472
+		// Update the order
473
+		self::$createdOrders[0]['address_2'] = 'Lviv';
474
+		self::$createdOrders[0]['EXT_FIELD_phone'] = '032268593';
475
+		self::$createdOrders[0]['EXT_FIELD_custom_data'] = [
476
+			0 => [
477
+				'customer_no' => '11',
478
+			],
479
+		];
480
+
481
+		$response = $order->updateOrder(self::$createdOrders[0]);
482
+
483
+		$this->assertNotNull($response);
484
+		$this->assertInstanceOf(Order::class, Order::fromArray($response));
485
+		$this->assertEquals('Lviv', $response['address_2']);
486
+		$this->assertEquals('032268593', $response['EXT_FIELD_phone']);
487
+		$this->assertEquals(
488
+			[
489
+				0 => [ 'customer_no' => '11' ],
490
+			],
491
+			$response['EXT_FIELD_custom_data']
492
+		);
493
+	}
494
+
495
+	public function testUpdateOrderWithCustomFiel()
496
+	{
497
+		$orderParameters = Order::fromArray([
498
+			'order_id'              => self::$createdOrders[0]['order_id'],
499
+			'custom_user_fields'    => [
500
+				OrderCustomField::fromArray([
501
+					'order_custom_field_id'    => 93,
502
+					'order_custom_field_value' => 'true'
503
+				])
504
+			]
505
+		]);
506
+
507
+		$order = new Order();
508
+
509
+		$response = $order->updateOrder($orderParameters);
510
+
511
+		$this->assertNotNull($response);
512
+		$this->assertInstanceOf(Order::class, Order::fromArray($response));
513
+		$this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
514
+		$this->assertEquals('true', $response['custom_user_fields'][0]['order_custom_field_value']);
515
+	}
516
+
517
+	public static function tearDownAfterClass()
518
+	{
519
+		if (sizeof(self::$createdOrders)) {
520
+			$orderIDs = [];
521
+
522
+			foreach (self::$createdOrders as $ord) {
523
+				$orderIDs[] = $ord['order_id'];
524
+			}
525
+
526
+			$orderParameters = Order::fromArray([
527
+				'order_ids' => $orderIDs
528
+			]);
529
+
530
+			$order = new Order();
531
+
532
+			$response = $order->removeOrder($orderParameters);
533
+
534
+			if (!is_null($response) &&
535
+				isset($response['status']) &&
536
+				$response['status']) {
537
+				echo "The test orders removed <br>";
538
+			}
539
+		}
540
+
541
+		if (sizeof(self::$createdProblems)>0) {
542
+			$optimizationProblemIDs = [];
543
+
544
+			foreach (self::$createdProblems as $problem) {
545
+				$optimizationProblemId = $problem->optimization_problem_id;
546
+
547
+				$optimizationProblemIDs[] = $optimizationProblemId;
548
+			}
549
+
550
+			$params = [
551
+				'optimization_problem_ids' => $optimizationProblemIDs,
552
+				'redirect'                 => 0,
553
+			];
554
+
555
+			$problem = new OptimizationProblem();
556
+			$result = $problem->removeOptimization($params);
557
+
558
+			if ($result!=null && $result['status']==true) {
559
+				echo "The test optimizations were removed <br>";
560
+			} else {
561
+				echo "Cannot remove the test optimizations <br>";
562
+			}
563
+		}
564
+	}
565 565
 }
Please login to merge, or discard this patch.