|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Tests\AdminBundle\Field; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use LAG\AdminBundle\Field\Field\ArrayField; |
|
7
|
|
|
use LAG\AdminBundle\Tests\AdminTestBase; |
|
8
|
|
|
use stdClass; |
|
9
|
|
|
|
|
10
|
|
|
class ArrayFieldTest extends AdminTestBase |
|
11
|
|
|
{ |
|
12
|
|
View Code Duplication |
public function testRender() |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
$arrayField = new ArrayField('my-field'); |
|
15
|
|
|
|
|
16
|
|
|
$this->setPrivateProperty($arrayField, 'options', [ |
|
17
|
|
|
'glue' => ', ', |
|
18
|
|
|
]); |
|
19
|
|
|
|
|
20
|
|
|
$content = $arrayField->render([ |
|
21
|
|
|
'panda', |
|
22
|
|
|
'squirrel', |
|
23
|
|
|
'narwhal', |
|
24
|
|
|
]); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertEquals('panda, squirrel, narwhal', $content); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
View Code Duplication |
public function testRenderCollection() |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$arrayField = new ArrayField('my-field'); |
|
32
|
|
|
|
|
33
|
|
|
$this->setPrivateProperty($arrayField, 'options', [ |
|
34
|
|
|
'glue' => ', ', |
|
35
|
|
|
]); |
|
36
|
|
|
|
|
37
|
|
|
$collection = new ArrayCollection([ |
|
38
|
|
|
'panda', |
|
39
|
|
|
'squirrel', |
|
40
|
|
|
'narwhal', |
|
41
|
|
|
]); |
|
42
|
|
|
$content = $arrayField->render($collection); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals('panda, squirrel, narwhal', $content); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testRenderInvalidValue() |
|
48
|
|
|
{ |
|
49
|
|
|
$arrayField = new ArrayField('my-field'); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertExceptionRaised(\Exception::class, function () use ($arrayField) { |
|
52
|
|
|
$arrayField->render('a string'); |
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertExceptionRaised(\Exception::class, function () use ($arrayField) { |
|
56
|
|
|
$arrayField->render(12); |
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertExceptionRaised(\Exception::class, function () use ($arrayField) { |
|
60
|
|
|
$arrayField->render(new stdClass()); |
|
61
|
|
|
}); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
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.