Completed
Push — master ( 4e6953...230277 )
by Kamil
26:55
created

AddUserFormSubscriberSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 49
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A it_is_event_subscriber_instance() 0 4 1
A it_adds_user_form_type_and_create_user_check() 0 10 1
A it_removes_user_form_type_by_default() 0 13 1
A it_does_not_remove_user_form_type_if_users_data_is_submitted() 0 11 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\UserBundle\Form\EventSubscriber;
13
14
use PhpSpec\ObjectBehavior;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\Form\Form;
17
use Symfony\Component\Form\FormEvent;
18
19
/**
20
 * @author Łukasz Chruściel <[email protected]>
21
 */
22
class AddUserFormSubscriberSpec extends ObjectBehavior
23
{
24
    function it_is_initializable()
25
    {
26
        $this->shouldHaveType('Sylius\Bundle\UserBundle\Form\EventSubscriber\AddUserFormSubscriber');
27
    }
28
29
    function it_is_event_subscriber_instance()
30
    {
31
        $this->shouldImplement(EventSubscriberInterface::class);
32
    }
33
34
    function it_adds_user_form_type_and_create_user_check(
35
        FormEvent $event,
36
        Form $form
37
    ) {
38
        $event->getForm()->willReturn($form);
39
40
        $form->add('user', 'sylius_user')->shouldBeCalled();
41
42
        $this->preSetData($event);
43
    }
44
45
    function it_removes_user_form_type_by_default(
46
        FormEvent $event,
47
        Form $form
48
    ) {
49
        $event->getData()->willReturn([], ['user' => ['plainPassword' => '']]);
50
        $event->getForm()->willReturn($form);
51
52
        $event->setData([])->shouldBeCalledTimes(1);
53
        $form->remove('user')->shouldBeCalledTimes(2);
54
55
        $this->preSubmit($event);
56
        $this->preSubmit($event);
57
    }
58
59
    function it_does_not_remove_user_form_type_if_users_data_is_submitted(
60
        FormEvent $event,
61
        Form $form
62
    ) {
63
        $event->getData()->willReturn(['user' => ['plainPassword' => 'test']]);
64
65
        $event->getForm()->shouldNotBeCalled();
66
        $form->remove('user')->shouldNotBeCalled();
67
68
        $this->preSubmit($event);
69
    }
70
}
71