Completed
Push — 3.x ( 852f7d...18583f )
by Oskar
07:39 queued 03:32
created

FormBuilderIteratorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A tearDown() 0 6 1
A testGetChildren() 0 6 1
A testHasChildren() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Util;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\AdminBundle\Util\FormBuilderIterator;
18
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
19
use Symfony\Component\Form\FormBuilder;
20
use Symfony\Component\Form\FormFactoryInterface;
21
22
/**
23
 * @author Mike Meier <[email protected]>
24
 */
25
class FormBuilderIteratorTest extends TestCase
26
{
27
    /**
28
     * @var EventDispatcherInterface
29
     */
30
    private $dispatcher;
31
32
    /**
33
     * @var FormFactoryInterface
34
     */
35
    private $factory;
36
37
    /**
38
     * @var FormBuilder
39
     */
40
    private $builder;
41
42
    protected function setUp()
43
    {
44
        $this->dispatcher = $this->getMockForAbstractClass(EventDispatcherInterface::class);
45
        $this->factory = $this->getMockForAbstractClass(FormFactoryInterface::class);
46
        $this->builder = new TestFormBuilder('name', null, $this->dispatcher, $this->factory);
47
        $this->factory->expects($this->any())->method('createNamedBuilder')->willReturn($this->builder);
48
    }
49
50
    protected function tearDown()
51
    {
52
        $this->dispatcher = null;
53
        $this->factory = null;
54
        $this->builder = null;
55
    }
56
57
    public function testGetChildren()
58
    {
59
        $this->builder->add('name', 'text');
60
        $iterator = new FormBuilderIterator($this->builder);
61
        $this->assertInstanceOf(\get_class($iterator), $iterator->getChildren());
62
    }
63
64
    public function testHasChildren()
65
    {
66
        $this->builder->add('name', 'text');
67
        $iterator = new FormBuilderIterator($this->builder);
68
        $this->assertTrue($iterator->hasChildren());
69
    }
70
}
71
72
class TestFormBuilder extends FormBuilder
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
73
{
74
}
75