-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ARCANEDEV/develop
Adding Currencies Collection
- Loading branch information
Showing
3 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php namespace Arcanedev\GeoIP\Entities; | ||
|
||
use Arcanedev\Support\Collection; | ||
|
||
/** | ||
* Class Currencies | ||
* | ||
* @package Arcanedev\GeoIP\Entities | ||
* @author ARCANEDEV <[email protected]> | ||
*/ | ||
class Currencies extends Collection | ||
{ | ||
/* ------------------------------------------------------------------------------------------------ | ||
| Constructor | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Make the currencies collection. | ||
* | ||
* @param array $items | ||
* | ||
* @return self | ||
*/ | ||
public static function make($items = []) | ||
{ | ||
return new static( | ||
config('geoip.currencies.data', $items) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php namespace Arcanedev\GeoIP\Tests\Entities; | ||
|
||
use Arcanedev\GeoIP\Tests\TestCase; | ||
|
||
/** | ||
* Class CurrenciesTest | ||
* | ||
* @package Arcanedev\GeoIP\Tests\Entities | ||
* @author ARCANEDEV <[email protected]> | ||
*/ | ||
class CurrenciesTest extends TestCase | ||
{ | ||
/* ------------------------------------------------------------------------------------------------ | ||
| Properties | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** @var \Arcanedev\GeoIP\Entities\Currencies */ | ||
protected $currencies; | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Main Functions | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->currencies = \Arcanedev\GeoIP\Entities\Currencies::make(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
unset($this->currencies); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Test Functions | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** @test */ | ||
public function it_can_be_instantiated() | ||
{ | ||
$expectations = [ | ||
\Illuminate\Support\Collection::class, | ||
\Arcanedev\Support\Collection::class, | ||
\Arcanedev\GeoIP\Entities\Currencies::class, | ||
]; | ||
|
||
foreach ($expectations as $expected) { | ||
$this->assertInstanceOf($expected, $this->currencies); | ||
} | ||
|
||
$this->assertFalse($this->currencies->isEmpty()); | ||
$this->assertCount(247, $this->currencies); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_get_continent() | ||
{ | ||
$expectations = [ | ||
'FR' => 'EUR', | ||
'JP' => 'JPY', | ||
'MA' => 'MAD', | ||
]; | ||
|
||
foreach ($expectations as $key => $expected) { | ||
$this->assertSame($expected, $this->currencies->get($key)); | ||
} | ||
|
||
$this->assertNull($this->currencies->get('ZZ')); | ||
$this->assertSame('Unknown', $this->currencies->get('ZZ', 'Unknown')); | ||
} | ||
} |