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 |
||
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 |