Completed
Push — master ( fcb59d...326ddf )
by Ruud
299:19 queued 288:03
created

ChoiceFormSubmissionFieldTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 24.14 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 21
loc 87
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testGetDefaultAdminType() 0 4 1
A testToString() 0 14 1
A testIsNull() 0 9 1
A testSetGetValue() 0 7 1
A testSetGetExpanded() 7 7 1
A testSetGetMultiple() 7 7 1
A testSetGetChoices() 7 7 1
A testSetGetRequired() 0 8 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\FormSubmissionFieldTypes;
4
5
use Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\ChoiceFormSubmissionField;
6
use Kunstmaan\FormBundle\Form\ChoiceFormSubmissionType;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * Tests for ChoiceFormSubmissionField
11
 */
12
class ChoiceFormSubmissionFieldTest extends TestCase
13
{
14
    /**
15
     * @var ChoiceFormSubmissionField
16
     */
17
    protected $object;
18
19
    /**
20
     * Sets up the fixture, for example, opens a network connection.
21
     * This method is called before a test is executed.
22
     */
23
    protected function setUp()
24
    {
25
        $this->object = new ChoiceFormSubmissionField();
26
    }
27
28
    public function testGetDefaultAdminType()
29
    {
30
        $this->assertEquals(ChoiceFormSubmissionType::class, $this->object->getDefaultAdminType());
31
    }
32
33
    public function testToString()
34
    {
35
        $stringValue = $this->object->__toString();
36
        $this->assertNotNull($stringValue);
37
        $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...
38
        $object = $this->object;
39
        $object->setChoices(['delboy1978uk' => 123456789]);
40
        $object->setValue('delboy1978uk');
0 ignored issues
show
Documentation introduced by
'delboy1978uk' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
        $string = $object->__toString();
42
        $this->assertEquals('123456789', $string);
43
        $object->setValue(['delboy1978uk', 'numkil', 'sandergo90', 'dezinc']);
44
        $string = $object->__toString();
45
        $this->assertEquals('123456789, numkil, sandergo90, dezinc', $string);
46
    }
47
48
    public function testIsNull()
49
    {
50
        $object = $this->object;
51
        $this->assertTrue($object->isNull());
52
        $object->setValue(array('test' => 'test'));
53
        $this->assertFalse($object->isNull());
54
        $object->setValue('blah');
0 ignored issues
show
Documentation introduced by
'blah' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
        $this->assertFalse($object->isNull());
56
    }
57
58
    public function testSetGetValue()
59
    {
60
        $object = $this->object;
61
        $value = array('test' => 'test');
62
        $object->setValue($value);
63
        $this->assertEquals($value, $object->getValue());
64
    }
65
66 View Code Duplication
    public function testSetGetExpanded()
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...
67
    {
68
        $object = $this->object;
69
        $this->assertFalse($object->getExpanded());
70
        $object->setExpanded(true);
71
        $this->assertTrue($object->getExpanded());
72
    }
73
74 View Code Duplication
    public function testSetGetMultiple()
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...
75
    {
76
        $object = $this->object;
77
        $this->assertFalse($object->getMultiple());
78
        $object->setMultiple(true);
79
        $this->assertTrue($object->getMultiple());
80
    }
81
82 View Code Duplication
    public function testSetGetChoices()
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...
83
    {
84
        $object = $this->object;
85
        $choices = array('test1' => 'test1', 'test2' => 'test2');
86
        $object->setChoices($choices);
87
        $this->assertEquals($choices, $object->getChoices());
88
    }
89
90
    public function testSetGetRequired()
91
    {
92
        $object = $this->object;
93
        $object->setRequired(true);
94
        $this->assertTrue($object->getRequired());
95
        $object->setRequired(false);
96
        $this->assertFalse($object->getRequired());
97
    }
98
}
99