Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

FileUploadPagePartTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 37.93 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 22
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testAdaptForm() 22 22 1
A testGetDefaultView() 0 6 1
A testGetDefaultAdminType() 0 4 1
A testGetSetRequired() 0 6 1

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
namespace Kunstmaan\FormBundle\Tests\Entity\PageParts;
4
5
use ArrayObject;
6
use Kunstmaan\FormBundle\Entity\PageParts\FileUploadPagePart;
7
use Kunstmaan\FormBundle\Form\FileUploadPagePartAdminType;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\Form\FormBuilderInterface;
10
11
/**
12
 * Tests for FileUploadPagePart
13
 */
14
class FileUploadPagePartTest extends TestCase
15
{
16
    /**
17
     * @var FileUploadPagePart
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 FileUploadPagePart();
28
    }
29
30 View Code Duplication
    public function testAdaptForm()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
31
    {
32
        $object = $this->object;
33
        $object->setRequired(true);
34
35
        $formBuilder = $this->getMockBuilder('Symfony\Component\Form\FormBuilder')
36
            ->disableOriginalConstructor()
37
            ->getMock();
38
39
        $formBuilder->expects($this->any())
40
            ->method('getData')
41
            ->willReturn([]);
42
43
        $fields = new ArrayObject();
44
45
        $object->setErrorMessageRequired('this is required');
46
        $this->assertEquals(count($fields), 0);
47
        /* @var FormBuilderInterface $formBuilder */
48
        $object->adaptForm($formBuilder, $fields, 0);
49
        $this->assertTrue(count($fields) > 0);
50
        $this->assertEquals('this is required', $object->getErrorMessageRequired());
51
    }
52
53
    public function testGetDefaultView()
54
    {
55
        $stringValue = $this->object->getDefaultView();
56
        $this->assertNotNull($stringValue);
57
        $this->assertInternalType('string', $stringValue);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
58
    }
59
60
    public function testGetDefaultAdminType()
61
    {
62
        $this->assertEquals(FileUploadPagePartAdminType::class, $this->object->getDefaultAdminType());
63
    }
64
65
    public function testGetSetRequired()
66
    {
67
        $obj = $this->object;
68
        $obj->setRequired(true);
69
        $this->assertTrue($obj->getRequired());
70
    }
71
}
72