Skip to content

Commit ac908db

Browse files
committed
New Currency tests
1 parent b170820 commit ac908db

File tree

3 files changed

+132
-5
lines changed

3 files changed

+132
-5
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace PostScripton\Money\Tests;
4+
5+
use PostScripton\Money\Currency;
6+
use PostScripton\Money\Money;
7+
8+
class CurrencyDisplayTest extends TestCase
9+
{
10+
/** @test */
11+
public function DisplayCodeStart()
12+
{
13+
$currency = Currency::code('USD')
14+
->setDisplay(Currency::DISPLAY_CODE);
15+
$usd = Money::make(1234, $currency);
16+
17+
$this->assertEquals('USD 123.4', $usd->toString());
18+
}
19+
20+
/** @test */
21+
public function DisplayCodeStartInEnd()
22+
{
23+
$currency = Currency::code('USD')
24+
->setDisplay(Currency::DISPLAY_CODE)
25+
->setPosition(Currency::POS_END);
26+
$usd = Money::make(1234, $currency);
27+
28+
$this->assertEquals('123.4 USD', $usd->toString());
29+
}
30+
31+
/** @test */
32+
public function DisplayCodeEnd()
33+
{
34+
$currency = Currency::code('RUB')
35+
->setDisplay(Currency::DISPLAY_CODE);
36+
$usd = Money::make(1234, $currency);
37+
38+
$this->assertEquals('123.4 RUB', $usd->toString());
39+
}
40+
41+
/** @test */
42+
public function DisplayCodeEndInStart()
43+
{
44+
$currency = Currency::code('RUB')
45+
->setDisplay(Currency::DISPLAY_CODE)
46+
->setPosition(Currency::POS_START);
47+
$rub = Money::make(1234, $currency);
48+
49+
$this->assertEquals('RUB 123.4', $rub->toString());
50+
}
51+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace PostScripton\Money\Tests;
4+
5+
use PostScripton\Money\Currency;
6+
use PostScripton\Money\Exceptions\CurrencyDoesNotExistException;
7+
8+
class CurrencyListsTest extends TestCase
9+
{
10+
/** @test */
11+
public function PopularList()
12+
{
13+
Currency::setCurrencyList(Currency::LIST_POPULAR);
14+
15+
$this->assertEquals('USD', Currency::code('840')->getCode());
16+
$this->assertEquals('EUR', Currency::code('EUR')->getCode());
17+
$this->assertEquals('RUB', Currency::code('RUB')->getCode());
18+
}
19+
20+
/** @test */
21+
public function AllList()
22+
{
23+
Currency::setCurrencyList(Currency::LIST_ALL);
24+
25+
$this->assertEquals('AFN', Currency::code('AFN')->getCode());
26+
$this->assertEquals('ALL', Currency::code('ALL')->getCode());
27+
$this->assertEquals('AMD', Currency::code('AMD')->getCode());
28+
}
29+
30+
/** @test */
31+
public function CurrencyFromALlInPopularException()
32+
{
33+
$this->expectException(CurrencyDoesNotExistException::class);
34+
35+
Currency::setCurrencyList(Currency::LIST_POPULAR);
36+
$this->assertEquals('AFN', Currency::code('AFN')->getCode());
37+
}
38+
}

tests/Feature/CurrencyTest.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,62 @@
44

55
use PostScripton\Money\Currency;
66
use PostScripton\Money\Exceptions\CurrencyDoesNotExistException;
7+
use PostScripton\Money\Exceptions\NoSuchCurrencySymbolException;
78

89
class CurrencyTest extends TestCase
910
{
10-
/** @test
11-
* @throws CurrencyDoesNotExistException
12-
*/
11+
/** @test */
1312
public function CheckingCurrencyPropsByCodeTest()
1413
{
1514
$cur = Currency::code('RUB');
16-
$this->assertEquals('', $cur->getSymbol());
15+
$this->assertEquals('Russian ruble', $cur->getFullName());
16+
$this->assertEquals('ruble', $cur->getName());
1717
$this->assertEquals('RUB', $cur->getCode());
18+
$this->assertEquals('643', $cur->getNumCode());
19+
$this->assertEquals('', $cur->getSymbol());
1820
$this->assertEquals(Currency::POS_END, $cur->getPosition());
1921
}
2022

2123
/** @test */
22-
public function NoCurrencyByCodeTest()
24+
public function NoCurrencyByISOCodeTest()
2325
{
2426
$this->expectException(CurrencyDoesNotExistException::class);
2527
Currency::code('NO_SUCH_CODE');
2628
}
29+
30+
/** @test */
31+
public function NoCurrencyByNumCodeTest()
32+
{
33+
$this->expectException(CurrencyDoesNotExistException::class);
34+
Currency::code('000');
35+
}
36+
37+
/** @test */
38+
public function CurrencyWithTwoSymbols()
39+
{
40+
Currency::setCurrencyList(Currency::LIST_ALL);
41+
42+
$cve = Currency::code('CVE');
43+
$this->assertEquals('Esc', $cve->getSymbol());
44+
$this->assertEquals('$', $cve->getSymbol(1));
45+
}
46+
47+
/** @test */
48+
public function CurrencyWithTwoSymbolsException()
49+
{
50+
Currency::setCurrencyList(Currency::LIST_ALL);
51+
52+
$cve = Currency::code('CVE');
53+
$this->expectException(NoSuchCurrencySymbolException::class);
54+
$cve->getSymbol(1234);
55+
}
56+
57+
/** @test */
58+
public function CurrencyNoSymbolException()
59+
{
60+
Currency::setCurrencyList(Currency::LIST_POPULAR);
61+
62+
// No exception because it has only 1 symbol
63+
$this->assertEquals('$', Currency::code('USD')->getSymbol(1234));
64+
}
2765
}

0 commit comments

Comments
 (0)