These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\FormBundle\Tests\Entity\PageParts; |
||
4 | |||
5 | use ArrayObject; |
||
6 | use Kunstmaan\FormBundle\Entity\PageParts\CheckboxPagePart; |
||
7 | use Kunstmaan\FormBundle\Form\CheckboxPagePartAdminType; |
||
8 | use PHPUnit\Framework\TestCase; |
||
9 | use Symfony\Component\Form\FormBuilderInterface; |
||
10 | |||
11 | /** |
||
12 | * Tests for ChoicePagePart |
||
13 | */ |
||
14 | class CheckboxPagePartTest extends TestCase |
||
15 | { |
||
16 | /** |
||
17 | * @var CheckboxPagePart |
||
18 | */ |
||
19 | protected $object; |
||
20 | |||
21 | /** |
||
22 | * Sets up the fixture, for example, opens a network connection. |
||
23 | * This method is called before a test is executed. |
||
24 | */ |
||
25 | protected function setUp() |
||
26 | { |
||
27 | $this->object = new CheckboxPagePart(); |
||
28 | } |
||
29 | |||
30 | public function testGetDefaultView() |
||
31 | { |
||
32 | $stringValue = $this->object->getDefaultView(); |
||
33 | $this->assertNotNull($stringValue); |
||
34 | $this->assertInternalType('string', $stringValue); |
||
35 | } |
||
36 | |||
37 | View Code Duplication | public function testAdaptForm() |
|
0 ignored issues
–
show
|
|||
38 | { |
||
39 | $object = $this->object; |
||
40 | $object->setRequired(true); |
||
41 | |||
42 | $formBuilder = $this->getMockBuilder('Symfony\Component\Form\FormBuilder') |
||
43 | ->disableOriginalConstructor() |
||
44 | ->getMock(); |
||
45 | |||
46 | $formBuilder->expects($this->any()) |
||
47 | ->method('getData') |
||
48 | ->willReturn([]); |
||
49 | |||
50 | $fields = new ArrayObject(); |
||
51 | |||
52 | $this->assertEquals(count($fields), 0); |
||
53 | $object->setErrorMessageRequired('omg sort it out'); |
||
54 | /* @var FormBuilderInterface $formBuilder */ |
||
55 | $object->adaptForm($formBuilder, $fields, 0); |
||
56 | $this->assertTrue(count($fields) > 0); |
||
57 | } |
||
58 | |||
59 | public function testGetDefaultAdminType() |
||
60 | { |
||
61 | $adminType = $this->object->getDefaultAdminType(); |
||
62 | $this->assertNotNull($adminType); |
||
63 | $this->assertEquals(CheckboxPagePartAdminType::class, $adminType); |
||
64 | } |
||
65 | |||
66 | public function testErrorMessage() |
||
67 | { |
||
68 | $object = $this->object; |
||
69 | $msg = 'fill in the form properly'; |
||
70 | $object->setErrorMessageRequired($msg); |
||
71 | $this->assertEquals($msg, $object->getErrorMessageRequired()); |
||
72 | } |
||
73 | } |
||
74 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.