FormManagerSpec   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 0
loc 100
rs 10
c 1
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A it_should_be_able_to_bind_unsafe_requests() 0 10 1
A it_should_not_bind_get_safe_requests() 0 10 1
A it_should_be_able_to_register_creators() 0 4 1
A it_should_be_able_to_register_creators_orderly() 0 4 1
A it_should_be_able_to_return_creators_many_times() 0 5 1
A it_should_try_to_create_form_with_registered_creators() 0 7 1
A its_createObjectForm_should_throw_exception_if_no_creator_fits() 0 8 1
A it_should_return_first_non_null_result_from_creator() 0 8 1
A let() 0 9 1
1
<?php
2
3
namespace spec\Knp\RadBundle\Form;
4
5
use PhpSpec\Exception\Example\PendingException;
6
use PhpSpec\ObjectBehavior;
7
8
class FormManagerSpec extends ObjectBehavior
9
{
10
    /**
11
     * @param Symfony\Component\HttpFoundation\RequestStack $requestStack
12
     * @param Symfony\Component\HttpFoundation\Request $request
13
     * @param Knp\RadBundle\Form\FormCreatorInterface $creator1
14
     * @param Knp\RadBundle\Form\FormCreatorInterface $creator2
15
     * @param Knp\RadBundle\Form\FormCreatorInterface $creator3
16
     */
17
    function let($requestStack, $request, $creator1, $creator2, $creator3)
18
    {
19
        $this->beConstructedWith($requestStack);
20
21
        $requestStack->getCurrentRequest()->willReturn($request);
22
        $this->registerCreator($creator1, 2);
23
        $this->registerCreator($creator2, 3);
24
        $this->registerCreator($creator3, 1);
25
    }
26
27
    function it_should_be_able_to_register_creators()
0 ignored issues
show
Coding Style introduced by
Method name "FormManagerSpec::it_should_be_able_to_register_creators" is not in camel caps format
Loading history...
28
    {
29
        $this->getCreators()->shouldHaveCount(3);
30
    }
31
32
    function it_should_be_able_to_register_creators_orderly($creator1, $creator2, $creator3)
0 ignored issues
show
Coding Style introduced by
Method name "FormManagerSpec::it_should_be_able_to_register_creators_orderly" is not in camel caps format
Loading history...
33
    {
34
        $this->getCreators()->shouldReturn(array($creator2, $creator1, $creator3));
35
    }
36
37
    function it_should_be_able_to_return_creators_many_times($creator1, $creator2, $creator3)
0 ignored issues
show
Coding Style introduced by
Method name "FormManagerSpec::it_should_be_able_to_return_creators_many_times" is not in camel caps format
Loading history...
38
    {
39
        $this->getCreators();
40
        $this->getCreators()->shouldReturn(array($creator2, $creator1, $creator3));
41
    }
42
43
    /**
44
     * @param stdClass $object
45
     */
46
    function it_should_try_to_create_form_with_registered_creators($object, $creator1, $creator2)
0 ignored issues
show
Coding Style introduced by
Method name "FormManagerSpec::it_should_try_to_create_form_with_registered_creators" is not in camel caps format
Loading history...
47
    {
48
        $creator2->create($object, 'edit', array())->willReturn(null)->shouldBeCalled();
49
        $creator1->create($object, 'edit', array())->willReturn(true)->shouldBeCalled();
50
51
        $this->createObjectForm($object, 'edit');
52
    }
53
54
    /**
55
     * @param stdClass $object
56
     */
57
    function its_createObjectForm_should_throw_exception_if_no_creator_fits($object, $creator1, $creator2, $creator3)
0 ignored issues
show
Coding Style introduced by
Method name "FormManagerSpec::its_createObjectForm_should_throw_exception_if_no_creator_fits" is not in camel caps format
Loading history...
58
    {
59
        $creator1->create($object, 'edit', array())->willReturn(null)->shouldBeCalled();
60
        $creator2->create($object, 'edit', array())->willReturn(null)->shouldBeCalled();
61
        $creator3->create($object, 'edit', array())->willReturn(null)->shouldBeCalled();
62
63
        $this->shouldThrow()->duringCreateObjectForm($object, 'edit');
64
    }
65
66
    /**
67
     * @param stdClass $object
68
     */
69
    function it_should_return_first_non_null_result_from_creator($object, $creator1, $creator2, $creator3)
0 ignored issues
show
Coding Style introduced by
Method name "FormManagerSpec::it_should_return_first_non_null_result_from_creator" is not in camel caps format
Loading history...
70
    {
71
        $creator2->create($object, 'edit', array())->willReturn(null)->shouldBeCalled();
72
        $creator1->create($object, 'edit', array())->willReturn(true)->shouldBeCalled();
73
        $creator3->create($object, 'edit', array())->shouldNotBeCalled();
74
75
        $this->createObjectForm($object, 'edit');
76
    }
77
78
    /**
79
     * @param stdClass $object
80
     * @param Symfony\Component\Form\Form $form
81
     */
82
    function it_should_be_able_to_bind_unsafe_requests($object, $request, $form, $creator2)
0 ignored issues
show
Coding Style introduced by
Method name "FormManagerSpec::it_should_be_able_to_bind_unsafe_requests" is not in camel caps format
Loading history...
83
    {
84
        $request->isMethodSafe()->willReturn(false);
85
        $request->getMethod()->willReturn('PUT');
86
        $creator2->create($object, null, array('method' => 'PUT'))->willReturn($form)->shouldBeCalled();
87
        $form->handleRequest($request)->shouldBeCalled();
88
        $form->submit($request)->shouldNotBeCalled();
89
90
        $this->createBoundObjectForm($object);
91
    }
92
93
    /**
94
     * @param stdClass $object
95
     * @param Symfony\Component\Form\Form $form
96
     */
97
    function it_should_not_bind_get_safe_requests($object, $request, $form, $creator2)
0 ignored issues
show
Coding Style introduced by
Method name "FormManagerSpec::it_should_not_bind_get_safe_requests" is not in camel caps format
Loading history...
98
    {
99
        $request->isMethodSafe()->willReturn(true);
100
        $request->getMethod()->willReturn('GET');
101
        $creator2->create($object, null, array())->willReturn($form)->shouldBeCalled();
102
        $form->handleRequest($request)->shouldBeCalled();
103
        $form->submit($request)->shouldNotBeCalled();
104
105
        $this->createBoundObjectForm($object);
106
    }
107
}
108