Failed Conditions
Push — issue#767 ( 4d8d6b...78ead8 )
by Guilherme
04:57
created

ClientMetadataFormTest::testOnSubmit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\Tests\Form;
12
13
use LoginCidadao\OpenIDBundle\Entity\ClientMetadata;
14
use LoginCidadao\OpenIDBundle\Form\ClientMetadataForm;
15
use LoginCidadao\OpenIDBundle\Manager\ClientManager;
16
use Symfony\Component\Form\FormBuilderInterface;
17
use Symfony\Component\Form\FormEvent;
18
use Symfony\Component\Form\FormEvents;
19
use Symfony\Component\Form\FormInterface;
20
use Symfony\Component\OptionsResolver\OptionsResolver;
21
22
class ClientMetadataFormTest extends \PHPUnit_Framework_TestCase
23
{
24
25
    public function testGetName()
26
    {
27
        $form = new ClientMetadataForm($this->getClientManager());
28
        $this->assertSame('', $form->getName());
29
    }
30
31
    public function testConfigureOptions()
32
    {
33
        /** @var OptionsResolver|\PHPUnit_Framework_MockObject_MockObject $resolver */
34
        $resolver = $this->getMockBuilder('Symfony\Component\OptionsResolver\OptionsResolver')->getMock();
35
        $resolver->expects($this->once())
36
            ->method('setDefaults')->with([
37
                'data_class' => 'LoginCidadao\OpenIDBundle\Entity\ClientMetadata',
38
                'csrf_protection' => false,
39
            ]);
40
41
        $form = new ClientMetadataForm($this->getClientManager());
42
        $form->configureOptions($resolver);
43
    }
44
45
    public function testBuildForm()
46
    {
47
        /** @var FormBuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builder */
48
        $builder = $this->getMock('Symfony\Component\Form\FormBuilderInterface');
49
        $builder->expects($this->exactly(33))->method('add')->willReturn($builder);
50
51
        $form = new ClientMetadataForm($this->getClientManager());
52
53
        $builder->expects($this->once())
54
            ->method('addEventListener')->with(FormEvents::SUBMIT, [$form, 'onSubmit'])
55
            ->willReturn($builder);
56
        $form->buildForm($builder, []);
57
    }
58
59
    public function testOnSubmit()
60
    {
61
        $metadata = new ClientMetadata();
62
63
        $clientManager = $this->getClientManager();
64
        $clientManager->expects($this->once())
65
            ->method('populateNewMetadata')->with($metadata);
66
67
        /** @var FormInterface $formInterface */
68
        $formInterface = $this->getMock('Symfony\Component\Form\FormInterface');
69
        $event = new FormEvent($formInterface, $metadata);
70
71
        $form = new ClientMetadataForm($clientManager);
72
        $form->onSubmit($event);
73
    }
74
75
    /**
76
     * @return ClientManager|\PHPUnit_Framework_MockObject_MockObject
77
     */
78
    private function getClientManager()
79
    {
80
        return $this->getMockBuilder('LoginCidadao\OpenIDBundle\Manager\ClientManager')
81
            ->disableOriginalConstructor()->getMock();
82
    }
83
}
84