|
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\CoreBundle\Templating\Helper; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Sylius\Bundle\CoreBundle\Templating\Helper\ChannelBasedPriceHelper; |
|
16
|
|
|
use Sylius\Bundle\CoreBundle\Templating\Helper\ChannelBasedPriceHelperInterface; |
|
17
|
|
|
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
19
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
20
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
|
21
|
|
|
use Sylius\Component\Order\Context\CartContextInterface; |
|
22
|
|
|
use Symfony\Component\Templating\Helper\Helper; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Mateusz Zalewski <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
final class ChannelBasedPriceHelperSpec extends ObjectBehavior |
|
28
|
|
|
{ |
|
29
|
|
|
function let( |
|
30
|
|
|
CartContextInterface $cartContext, |
|
31
|
|
|
ProductVariantPriceCalculatorInterface $productVariantPriceCalculator |
|
|
|
|
|
|
32
|
|
|
) { |
|
33
|
|
|
$this->beConstructedWith($cartContext, $productVariantPriceCalculator); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_is_initializable() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->shouldHaveType(ChannelBasedPriceHelper::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_is_helper() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->shouldHaveType(Helper::class); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function it_implements_channel_based_price_helper_interface() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->shouldImplement(ChannelBasedPriceHelperInterface::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
function it_returns_variant_price_for_current_channel( |
|
52
|
|
|
CartContextInterface $cartContext, |
|
53
|
|
|
ChannelInterface $currentChannel, |
|
54
|
|
|
OrderInterface $currentCart, |
|
55
|
|
|
ProductVariantInterface $productVariant, |
|
56
|
|
|
ProductVariantPriceCalculatorInterface $productVariantPriceCalculator |
|
|
|
|
|
|
57
|
|
|
) { |
|
58
|
|
|
$cartContext->getCart()->willReturn($currentCart); |
|
59
|
|
|
$currentCart->getChannel()->willReturn($currentChannel); |
|
60
|
|
|
|
|
61
|
|
|
$productVariantPriceCalculator->calculate($productVariant, ['channel' => $currentChannel])->willReturn(1000); |
|
62
|
|
|
|
|
63
|
|
|
$this->getPriceForCurrentChannel($productVariant)->shouldReturn(1000); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
function it_has_name() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->getName()->shouldReturn('sylius_channel_variant_price'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.