Completed
Push — master ( ecae9c...8b2ccb )
by Kamil
21:33 queued 01:01
created

CurrencyHelperSpec::it_provides_current_currency()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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