1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\MoneyBundle\Formatter; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatter; |
18
|
|
|
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Łukasz Chruściel <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class MoneyFormatterSpec extends ObjectBehavior |
24
|
|
|
{ |
25
|
|
|
function it_implements_money_formatter_interface(): void |
26
|
|
|
{ |
27
|
|
|
$this->shouldImplement(MoneyFormatterInterface::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function it_formats_positive_money_using_given_currency_and_locale(): void |
31
|
|
|
{ |
32
|
|
|
$this->format(15, 'USD', 'en')->shouldReturn('$0.15'); |
33
|
|
|
$this->format(2500, 'USD', 'en')->shouldReturn('$25.00'); |
34
|
|
|
$this->format(312, 'EUR', 'en')->shouldReturn('€3.12'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function it_formats_positive_money_using_default_locale_if_not_given(): void |
38
|
|
|
{ |
39
|
|
|
$this->format(500, 'USD')->shouldReturn('$5.00'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function it_formats_negative_money_using_given_currency_and_locale(): void |
43
|
|
|
{ |
44
|
|
|
$this->format(-15, 'USD', 'en')->shouldReturn('-$0.15'); |
45
|
|
|
$this->format(-2500, 'USD', 'en')->shouldReturn('-$25.00'); |
46
|
|
|
$this->format(-312, 'EUR', 'en')->shouldReturn('-€3.12'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function it_formats_negative_money_using_default_locale_if_not_given(): void |
50
|
|
|
{ |
51
|
|
|
$this->format(-500, 'USD')->shouldReturn('-$5.00'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function it_formats_zero_money_using_given_currency_and_locale(): void |
55
|
|
|
{ |
56
|
|
|
$this->format(0, 'USD', 'en')->shouldReturn('$0.00'); |
57
|
|
|
$this->format(0, 'EUR', 'en')->shouldReturn('€0.00'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
function it_formats_zero_money_using_default_locale_if_not_given(): void |
61
|
|
|
{ |
62
|
|
|
$this->format(0, 'USD')->shouldReturn('$0.00'); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|