1 | <?php |
||
37 | class TableConfigurationTest extends UnitTestCase |
||
38 | { |
||
39 | use Language, AccessibleTraitForTest; |
||
40 | |||
41 | /** |
||
42 | * @var TableConfiguration $subject |
||
43 | */ |
||
44 | protected $subject; |
||
45 | |||
46 | /** |
||
47 | * TABLE |
||
48 | */ |
||
49 | const TABLE = 'pages'; |
||
50 | |||
51 | /** |
||
52 | * @return void |
||
53 | */ |
||
54 | public function setUp() |
||
55 | { |
||
56 | $GLOBALS['LANG'] = new \TYPO3\CMS\Lang\LanguageService(); |
||
57 | $GLOBALS['LANG']->init('de'); |
||
58 | |||
59 | $GLOBALS['TCA'] = [ |
||
60 | 'pages' => [ |
||
61 | 'ctrl' => [ |
||
62 | 'title' => 'LLL:EXT:lang/locallang_tca.xlf:pages' |
||
63 | ], |
||
64 | 'columns' => [ |
||
65 | 'title' => [ |
||
66 | 'config' => [ |
||
67 | 'type' => 'array', |
||
68 | 'size' => '50', |
||
69 | 'max' => '255', |
||
70 | 'eval' => 'trim,required', |
||
71 | ], |
||
72 | ], |
||
73 | 'doctype' => [ |
||
74 | 'exclude' => 1, |
||
75 | 'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.type', |
||
76 | 'config' => [ |
||
77 | 'type' => 'select', |
||
78 | 'renderType' => 'selectSingle', |
||
79 | 'default' => '1' |
||
80 | ], |
||
81 | ], |
||
82 | ], |
||
83 | ], |
||
84 | 'fe_users' => [], |
||
85 | ]; |
||
86 | |||
87 | $this->subject = new TableConfiguration('pages'); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @test |
||
92 | */ |
||
93 | public function createTableConfigurationThrowsExceptionWhenTableNameNotExist() |
||
94 | { |
||
95 | $this->expectException(\InvalidArgumentException::class); |
||
96 | new TableConfiguration('LoremIpsum'); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @test |
||
101 | */ |
||
102 | public function createTableConfigurationThrowsExceptionWhenArgumentIsNoString() |
||
103 | { |
||
104 | $this->expectException(\InvalidArgumentException::class); |
||
105 | $this->subject->getColumnConfiguration(123); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @test |
||
110 | */ |
||
111 | public function tableConfigurationContainsArray() |
||
112 | { |
||
113 | $tableConfiguration = $this->accessProtectedProperty($this->subject, 'tableConfiguration'); |
||
114 | $this->assertTrue(is_array($tableConfiguration)); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @test |
||
119 | */ |
||
120 | public function tablePropertyContainsString() |
||
121 | { |
||
122 | $table = $this->accessProtectedProperty($this->subject, 'name'); |
||
123 | $this->assertSame(self::TABLE, $table); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @test |
||
128 | */ |
||
129 | public function getNameReturnsTableName() |
||
130 | { |
||
131 | $this->assertSame(self::TABLE, $this->subject->getName()); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @test |
||
136 | */ |
||
137 | public function getTitleReturnsTitleOfTable() |
||
138 | { |
||
139 | $this->assertSame('Page', $this->subject->getTitle()); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * @test |
||
144 | */ |
||
145 | public function getColumnsReturnsArray() |
||
146 | { |
||
147 | $this->assertSame(['title', 'doctype'], $this->subject->getColumns()); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @test |
||
152 | */ |
||
153 | public function getColumnConfigurationThrowsExceptionWhenTableNotExist() |
||
154 | { |
||
155 | $column = 'FooBar'; |
||
156 | $this->expectException( |
||
157 | 'InvalidArgumentException', |
||
158 | 'Column ' . $column . ' does not exist for table ' . self::TABLE |
||
|
|||
159 | ); |
||
160 | $this->assertSame($this->getExpectedException(), $this->subject->getColumnConfiguration($column)); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @test |
||
165 | */ |
||
166 | public function getColumnConfigurationReturnsArray() |
||
178 | |||
179 | /** |
||
180 | * @test |
||
181 | */ |
||
182 | public function getAllTablesReturnsArray() |
||
183 | { |
||
184 | $this->assertSame(['pages' => 'pages', 'fe_users' => 'fe_users'], $this->subject->getAllTables()); |
||
185 | } |
||
186 | } |
||
187 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.