Completed
Push — master ( cfaf77...b5ed7c )
by Kamil
47:11 queued 29:42
created

ChannelPricingsFormSubscriberSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 6
dl 0
loc 45
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_event_subscriber_interface() 0 4 1
A it_listens_on_pre_set_data_event() 0 4 1
A it_adds_missing_channel_pricings_on_pre_set_data() 0 22 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\CoreBundle\Form\EventSubscriber;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\CoreBundle\Form\EventSubscriber\ChannelPricingsFormSubscriber;
16
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
17
use Sylius\Component\Core\Model\ChannelInterface;
18
use Sylius\Component\Core\Model\ChannelPricingInterface;
19
use Sylius\Component\Core\Model\ProductVariantInterface;
20
use Sylius\Component\Resource\Factory\FactoryInterface;
21
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
22
use Symfony\Component\Form\FormEvent;
23
use Symfony\Component\Form\FormEvents;
24
25
/**
26
 * @author Mateusz Zalewski <[email protected]>
27
 */
28
final class ChannelPricingsFormSubscriberSpec extends ObjectBehavior
29
{
30
    function let(ChannelRepositoryInterface $channelRepository, FactoryInterface $channelPricingFactory)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $channelPricingFactory exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
31
    {
32
        $this->beConstructedWith($channelRepository, $channelPricingFactory);
33
    }
34
35
    function it_is_initializable()
36
    {
37
        $this->shouldHaveType(ChannelPricingsFormSubscriber::class);
38
    }
39
40
    function it_implements_event_subscriber_interface()
41
    {
42
        $this->shouldImplement(EventSubscriberInterface::class);
43
    }
44
45
    function it_listens_on_pre_set_data_event()
46
    {
47
        $this->getSubscribedEvents()->shouldReturn([FormEvents::PRE_SET_DATA => 'preSetData']);
48
    }
49
50
    function it_adds_missing_channel_pricings_on_pre_set_data(
51
        ChannelInterface $firstChannel,
52
        ChannelInterface $secondChannel,
53
        ChannelPricingInterface $channelPricing,
54
        ChannelRepositoryInterface $channelRepository,
55
        FactoryInterface $channelPricingFactory,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $channelPricingFactory exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
56
        FormEvent $formEvent,
57
        ProductVariantInterface $productVariant
58
    ) {
59
        $formEvent->getData()->willReturn($productVariant);
60
61
        $channelRepository->findAll()->willReturn([$firstChannel, $secondChannel]);
62
63
        $productVariant->hasChannelPricingForChannel($firstChannel)->willReturn(true);
64
        $productVariant->hasChannelPricingForChannel($secondChannel)->willReturn(false);
65
66
        $channelPricingFactory->createNew()->willReturn($channelPricing);
67
        $channelPricing->setChannel($secondChannel)->shouldBeCalled();
68
        $productVariant->addChannelPricing($channelPricing)->shouldBeCalled();
69
70
        $this->preSetData($formEvent);
71
    }
72
}
73