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(): void |
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->assertIsString($stringValue); |
38
|
|
|
$object = $this->object; |
39
|
|
|
$object->setChoices(['delboy1978uk' => 123456789]); |
40
|
|
|
$object->setValue('delboy1978uk'); |
|
|
|
|
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'); |
|
|
|
|
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() |
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() |
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() |
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
|
|
|
|
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: