Skip to content

Commit e22341b

Browse files
committed
Merge pull request #9 from JobBrander/location_parser
Adding location parser and tests
2 parents b119f10 + 58be171 commit e22341b

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
@@ -359,6 +359,17 @@ private function parseAsXml($string)
359359
return [];
360360
}
361361

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

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)