ColumnTest::testGetGetter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Admingenerator\GeneratorBundle\Tests\Generator;
4
5
use Doctrine\Common\Util\Inflector;
6
use Admingenerator\GeneratorBundle\Tests\TestCase;
7
use Admingenerator\GeneratorBundle\Generator\Column;
8
9
class ColumnTest extends TestCase
10
{
11
12
    public function testGetName()
13
    {
14
        $from_to_array = array(
15
            'name' => 'name',
16
            'underscored_name' => 'underscored_name',
17
        );
18
19
        $this->checkColumn($from_to_array, 'getName');
20
    }
21
22
    public function testGetGetter()
23
    {
24
        $from_to_array = array(
25
            'name' => 'name',
26
            'underscored_name' => 'underscoredName',
27
        );
28
29
        $this->checkColumn($from_to_array, 'getGetter');
30
    }
31
32
    public function testGetLabel()
33
    {
34
        $from_to_array = array(
35
            'name' => 'Name',
36
            'underscored_name' => 'Underscored name',
37
        );
38
39
        $this->checkColumn($from_to_array, 'getLabel');
40
    }
41
42
    public function testSetProperty()
43
    {
44
        $options = array(
45
            'label' => 'my label',
46
            'getter' => 'getFoo',
47
            'sort_on' => 'foo',
48
            'sortOn' => 'foo',
49
            'dbType' => 'text',
50
            'formType' => 'choices',
51
            'formOptions' => array('foo' => 'bar'),
52
            'filterType' => 'choice',
53
            'filterOptions' => array('bar' => 'foo'),
54
        );
55
56
        $column = new Column("test", false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, 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...
57
58
        foreach ($options as $option => $value) {
59
            $column->setProperty($option, $value);
60
            $this->assertEquals($value, call_user_func_array(array($column, 'get'.Inflector::classify($option)), array()));
61
        }
62
    }
63
64
    public function testSetAddFormFilterOptionsPhpFunction()
65
    {
66
        $column = new Column("test", false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, 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...
67
68
        $addOptions = array('years' => array('.range' => array('from' => 1900, 'to' => 1915, 'step' => 5)));
69
70
        $column->setAddFormOptions($addOptions);
71
72
        $options = $column->getFormOptions();
73
74
        $testOptions = array(1900, 1905, 1910, 1915);
75
76
        $this->assertEquals($testOptions, $options['years']);
77
78
        $column->setAddFilterOptions($addOptions);
79
80
        $options = $column->getFilterOptions();
81
82
        $this->assertEquals($testOptions, $options['years']);
83
    }
84
85
    public function testCredentials()
86
    {
87
        $column = new Column('test', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, 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...
88
89
        $column->setCredentials(array('credential1', 'credential2'));
0 ignored issues
show
Documentation introduced by
array('credential1', 'credential2') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

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...
90
        $column->setFiltersCredentials(array('credential3', 'credential4'));
0 ignored issues
show
Documentation introduced by
array('credential3', 'credential4') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

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...
91
92
        $this->assertEquals(array('credential1', 'credential2'), $column->getCredentials());
93
        $this->assertEquals(array('credential3', 'credential4'), $column->getFiltersCredentials());
94
95
        $column->setFiltersCredentials(array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

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...
96
97
        $this->assertEquals(array(), $column->getFiltersCredentials());
98
    }
99
100
    public function testFiltersCredentialsFallbackOnCredentialsIfNotCustomized()
101
    {
102
        $column = new Column('test', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, 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...
103
104
        $column->setCredentials(array('credential1', 'credential2'));
0 ignored issues
show
Documentation introduced by
array('credential1', 'credential2') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

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...
105
106
        $this->assertEquals(array('credential1', 'credential2'), $column->getFiltersCredentials());
107
    }
108
109
110
    /**
111
     * @param string $method
112
     */
113
    protected function checkColumn($from_to_array, $method)
114
    {
115
        foreach ($from_to_array as $from => $to) {
116
            $column = new Column($from, false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, 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...
117
            $this->assertEquals($to, $column->$method());
118
        }
119
    }
120
121
}
122