Completed
Push — master ( 081637...206e0a )
by Eric
06:26
created

IconButtonExtensionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Bundle\UiBundle\Tests\Form\Extension;
13
14
use Lug\Bundle\UiBundle\Form\Extension\IconButtonExtension;
15
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
16
use Symfony\Component\Form\FormFactoryInterface;
17
use Symfony\Component\Form\Forms;
18
19
/**
20
 * @author GeLo <[email protected]>
21
 */
22
class IconButtonExtensionTest extends \PHPUnit_Framework_TestCase
23
{
24
    /**
25
     * @var FormFactoryInterface
26
     */
27
    private $factory;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function setUp()
33
    {
34
        $this->factory = Forms::createFormFactoryBuilder()
35
            ->addTypeExtension(new IconButtonExtension())
36
            ->getFormFactory();
37
    }
38
39
    public function testDefault()
40
    {
41
        $form = $this->factory->create(ButtonType::class);
42
        $view = $form->createView();
43
44
        $this->assertArrayHasKey('icon', $view->vars);
45
        $this->assertNull($view->vars['icon']);
46
    }
47
48
    public function testIcon()
49
    {
50
        $form = $this->factory->create(ButtonType::class, null, ['icon' => $icon = 'my.icon']);
51
        $view = $form->createView();
52
53
        $this->assertArrayHasKey('icon', $view->vars);
54
        $this->assertSame($icon, $view->vars['icon']);
55
    }
56
}
57