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\Component\Currency\Model; |
13
|
|
|
|
14
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
15
|
|
|
use Sylius\Component\Currency\Model\ExchangeRate; |
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Component\Currency\Model\ExchangeRateInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Jan Góralski <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class ExchangeRateSpec extends ObjectBehavior |
23
|
|
|
{ |
24
|
|
|
function it_is_initializable() |
25
|
|
|
{ |
26
|
|
|
$this->shouldHaveType(ExchangeRate::class); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
function it_implements_exchange_rate_interface() |
30
|
|
|
{ |
31
|
|
|
$this->shouldImplement(ExchangeRateInterface::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_throws_an_invalid_argument_exception_when_adding_non_float_ratio() |
35
|
|
|
{ |
36
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('setRatio', ['1.01']); |
37
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('setRatio', ['asd']); |
38
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('setRatio', [[]]); |
39
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('setRatio', [null]); |
40
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('setRatio', [false]); |
41
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('setRatio', [new \stdClass()]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_has_a_ratio() |
45
|
|
|
{ |
46
|
|
|
$this->getRatio()->shouldReturn(null); |
47
|
|
|
$this->setRatio(1.02); |
48
|
|
|
$this->getRatio()->shouldReturn(1.02); |
49
|
|
|
$this->setRatio(1e-6); |
50
|
|
|
$this->getRatio()->shouldReturn(1e-6); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function it_has_base_currency(CurrencyInterface $currency) |
54
|
|
|
{ |
55
|
|
|
$this->getSourceCurrency()->shouldReturn(null); |
56
|
|
|
$this->setSourceCurrency($currency); |
57
|
|
|
$this->getSourceCurrency()->shouldReturn($currency); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
function it_has_target_currency(CurrencyInterface $currency) |
61
|
|
|
{ |
62
|
|
|
$this->getTargetCurrency()->shouldReturn(null); |
63
|
|
|
$this->setTargetCurrency($currency); |
64
|
|
|
$this->getTargetCurrency()->shouldReturn($currency); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|