ColumnBuilderTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Component\Grid\Tests\Model\Builder;
13
14
use Lug\Component\Grid\Model\Builder\ColumnBuilder;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
class ColumnBuilderTest extends \PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * @var ColumnBuilder
23
     */
24
    private $builder;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function setUp()
30
    {
31
        $this->builder = new ColumnBuilder();
32
    }
33
34
    public function testBuild()
35
    {
36
        $column = $this->builder->build(['name' => $name = 'my.name']);
37
38
        $this->assertSame($name, $column->getName());
39
        $this->assertSame($name, $column->getLabel());
40
        $this->assertSame('text', $column->getType());
41
        $this->assertFalse($column->hasOptions());
42
    }
43
44
    public function testBuildWithFullOptions()
45
    {
46
        $column = $this->builder->build([
47
            'name'    => $name = 'my.name',
48
            'label'   => $label = 'my.label',
49
            'type'    => $type = 'my.type',
50
            'options' => $options = ['foo' => 'bar'],
51
        ]);
52
53
        $this->assertSame($name, $column->getName());
54
        $this->assertSame($label, $column->getLabel());
55
        $this->assertSame($type, $column->getType());
56
        $this->assertSame($options, $column->getOptions());
57
    }
58
59
    public function testBuildResource()
60
    {
61
        $column = $this->builder->build([
62
            'name'    => $name = 'my.name',
63
            'type'    => $type = 'resource',
64
            'options' => $options = ['foo' => 'bar'],
65
        ]);
66
67
        $this->assertSame($name, $column->getName());
68
        $this->assertSame($name, $column->getLabel());
69
        $this->assertSame($type, $column->getType());
70
        $this->assertSame(array_merge($options, ['resource' => $name]), $column->getOptions());
71
    }
72
73
    /**
74
     * @expectedException \Lug\Component\Grid\Exception\ConfigNotFoundException
75
     * @expectedExceptionMessage The column config "name" could not be found.
76
     */
77
    public function testBuildWithMissingName()
78
    {
79
        $this->builder->build([]);
80
    }
81
}
82