Skip to content

Commit 58be171

Browse files
committed
Adding location parser and tests
1 parent afa3394 commit 58be171

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Providers/AbstractProvider.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,17 @@ private function parseAsXml($string)
357357
return [];
358358
}
359359

360+
/**
361+
* Parse location string into components.
362+
*
363+
* @param string $location
364+
* @return array
365+
**/
366+
public static function parseLocation($location, $separator = ', ')
367+
{
368+
return explode($separator, $location);
369+
}
370+
360371
/**
361372
* Sets http client
362373
*

test/src/ProviderTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,31 @@ public function testItCanNotGetJobsInvalidFormat()
355355
$this->assertCount($provider['jobs_count'], $results);
356356
}
357357

358+
public function testItCanParseLocationWithoutSeparator()
359+
{
360+
$seg1 = uniqid();
361+
$seg2 = uniqid();
362+
$string = $seg1.', '.$seg2;
363+
364+
$results = $this->client->parseLocation($string);
365+
366+
$this->assertEquals($seg1, $results[0]);
367+
$this->assertEquals($seg2, $results[1]);
368+
}
369+
370+
public function testItCanParseLocationWithSeparator()
371+
{
372+
$seg1 = uniqid();
373+
$seg2 = uniqid();
374+
$seperator = uniqid();
375+
$string = $seg1.$seperator.$seg2;
376+
377+
$results = $this->client->parseLocation($string, $seperator);
378+
379+
$this->assertEquals($seg1, $results[0]);
380+
$this->assertEquals($seg2, $results[1]);
381+
}
382+
358383
private function getProviderAttributes($attributes = [])
359384
{
360385
$defaults = [

0 commit comments

Comments
 (0)