|
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
|
|
|
namespace spec\Sylius\Bundle\CurrencyBundle\Templating\Helper; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Sylius\Bundle\CurrencyBundle\Templating\Helper\CurrencyHelper; |
|
16
|
|
|
use Sylius\Bundle\MoneyBundle\Templating\Helper\MoneyHelperInterface; |
|
17
|
|
|
use Sylius\Component\Currency\Context\CurrencyContextInterface; |
|
18
|
|
|
use Sylius\Component\Currency\Converter\CurrencyConverterInterface; |
|
19
|
|
|
use Symfony\Component\Templating\Helper\Helper; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @mixin CurrencyHelper |
|
23
|
|
|
* |
|
24
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class CurrencyHelperSpec extends ObjectBehavior |
|
27
|
|
|
{ |
|
28
|
|
|
function let( |
|
29
|
|
|
CurrencyContextInterface $currencyContext, |
|
30
|
|
|
CurrencyConverterInterface $converter, |
|
31
|
|
|
MoneyHelperInterface $moneyHelper |
|
32
|
|
|
) { |
|
33
|
|
|
$this->beConstructedWith($currencyContext, $converter, $moneyHelper); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_is_initializable() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->shouldHaveType('Sylius\Bundle\CurrencyBundle\Templating\Helper\CurrencyHelper'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_is_a_Twig_extension() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->shouldHaveType(Helper::class); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function it_allows_to_convert_prices_in_different_currencies( |
|
47
|
|
|
$currencyContext, |
|
48
|
|
|
$converter |
|
49
|
|
|
) { |
|
50
|
|
|
$currencyContext->getCurrency()->willReturn('PLN'); |
|
51
|
|
|
|
|
52
|
|
|
$converter->convertFromBase(15, 'USD')->shouldBeCalled()->willReturn(19); |
|
53
|
|
|
$converter->convertFromBase(2500, 'USD')->shouldBeCalled()->willReturn(1913); |
|
54
|
|
|
$converter->convertFromBase(312, 'PLN')->shouldBeCalled()->willReturn(407); |
|
55
|
|
|
$converter->convertFromBase(500, 'PLN')->shouldBeCalled()->willReturn(653); |
|
56
|
|
|
|
|
57
|
|
|
$this->convertAmount(15, 'USD')->shouldReturn(19); |
|
58
|
|
|
$this->convertAmount(2500, 'USD')->shouldReturn(1913); |
|
59
|
|
|
$this->convertAmount(312, 'PLN')->shouldReturn(407); |
|
60
|
|
|
$this->convertAmount(500)->shouldReturn(653); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
function it_provides_current_currency(CurrencyContextInterface $currencyContext) |
|
64
|
|
|
{ |
|
65
|
|
|
$currencyContext->getCurrency()->willReturn('PLN'); |
|
66
|
|
|
|
|
67
|
|
|
$this->getCurrentCurrencySymbol()->shouldReturn('PLN'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|