‪TYPO3CMS  10.4
ColumnDefinitionAttributesTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪ColumnDefinitionAttributesTest extends UnitTestCase
29 {
47  {
48  return [
49  'NULL' => [
50  'NULL',
51  true,
52  false,
53  null,
54  false,
55  false,
56  false,
57  false,
58  null,
59  null,
60  null,
61  ],
62  'NOT NULL' => [
63  'NOT NULL',
64  false,
65  false,
66  null,
67  false,
68  false,
69  false,
70  false,
71  null,
72  null,
73  null,
74  ],
75  'DEFAULT' => [
76  "DEFAULT '0'",
77  true,
78  true,
79  '0',
80  false,
81  false,
82  false,
83  false,
84  null,
85  null,
86  null,
87  ],
88  'AUTO_INCREMENT' => [
89  'AUTO_INCREMENT',
90  true,
91  false,
92  null,
93  true,
94  false,
95  false,
96  false,
97  null,
98  null,
99  null,
100  ],
101  'UNIQUE' => [
102  'UNIQUE',
103  true,
104  false,
105  null,
106  false,
107  false,
108  true,
109  false,
110  null,
111  null,
112  null,
113  ],
114  'UNIQUE KEY' => [
115  'UNIQUE KEY',
116  true,
117  false,
118  null,
119  false,
120  false,
121  true,
122  false,
123  null,
124  null,
125  null,
126  ],
127  'PRIMARY' => [
128  'PRIMARY',
129  true,
130  false,
131  null,
132  false,
133  false,
134  false,
135  true,
136  null,
137  null,
138  null,
139  ],
140  'PRIMARY KEY' => [
141  'PRIMARY KEY',
142  true,
143  false,
144  null,
145  false,
146  false,
147  false,
148  true,
149  null,
150  null,
151  null,
152  ],
153  'KEY' => [
154  'KEY',
155  true,
156  false,
157  null,
158  false,
159  true,
160  false,
161  false,
162  null,
163  null,
164  null,
165  ],
166  'COMMENT' => [
167  "COMMENT 'aComment'",
168  true,
169  false,
170  null,
171  false,
172  false,
173  false,
174  false,
175  'aComment',
176  null,
177  null,
178  ],
179  'COLUMN_FORMAT FIXED' => [
180  'COLUMN_FORMAT FIXED',
181  true,
182  false,
183  null,
184  false,
185  false,
186  false,
187  false,
188  null,
189  'fixed',
190  null,
191  ],
192  'COLUMN_FORMAT DYNAMIC' => [
193  'COLUMN_FORMAT DYNAMIC',
194  true,
195  false,
196  null,
197  false,
198  false,
199  false,
200  false,
201  null,
202  'dynamic',
203  null,
204  ],
205  'COLUMN_FORMAT DEFAULT' => [
206  'COLUMN_FORMAT DEFAULT',
207  true,
208  false,
209  null,
210  false,
211  false,
212  false,
213  false,
214  null,
215  null,
216  null,
217  ],
218  'STORAGE DISK' => [
219  'STORAGE DISK',
220  true,
221  false,
222  null,
223  false,
224  false,
225  false,
226  false,
227  null,
228  null,
229  'disk',
230  ],
231  'STORAGE MEMORY' => [
232  'STORAGE MEMORY',
233  true,
234  false,
235  null,
236  false,
237  false,
238  false,
239  false,
240  null,
241  null,
242  'memory',
243  ],
244  'STORAGE DEFAULT' => [
245  'STORAGE DEFAULT',
246  true,
247  false,
248  null,
249  false,
250  false,
251  false,
252  false,
253  null,
254  null,
255  null,
256  ],
257  "NOT NULL DEFAULT '0'" => [
258  "NOT NULL DEFAULT '0'",
259  false,
260  true,
261  '0',
262  false,
263  false,
264  false,
265  false,
266  null,
267  null,
268  null,
269  ],
270  'NOT NULL AUTO_INCREMENT' => [
271  'NOT NULL AUTO_INCREMENT',
272  false,
273  false,
274  null,
275  true,
276  false,
277  false,
278  false,
279  null,
280  null,
281  null,
282  ],
283  'NULL DEFAULT NULL' => [
284  'NULL DEFAULT NULL',
285  true,
286  true,
287  null,
288  false,
289  false,
290  false,
291  false,
292  null,
293  null,
294  null,
295  ],
296  'NOT NULL PRIMARY KEY' => [
297  'NOT NULL PRIMARY KEY',
298  false,
299  false,
300  null,
301  false,
302  false,
303  false,
304  true,
305  null,
306  null,
307  null,
308  ],
309  "NULL DEFAULT 'dummy' UNIQUE" => [
310  "NULL DEFAULT 'dummy' UNIQUE",
311  true,
312  true,
313  'dummy',
314  false,
315  false,
316  true,
317  false,
318  null,
319  null,
320  null,
321  ],
322  "NOT NULL DEFAULT '0' COMMENT 'aComment with blanks' AUTO_INCREMENT PRIMARY KEY COLUMN_FORMAT DYNAMIC" => [
323  "NOT NULL DEFAULT '0' COMMENT 'aComment with blanks' AUTO_INCREMENT PRIMARY KEY COLUMN_FORMAT DYNAMIC",
324  false,
325  true,
326  '0',
327  true,
328  false,
329  false,
330  true,
331  'aComment with blanks',
332  'dynamic',
333  null,
334  ],
335  ];
336  }
337 
354  string $columnAttribute,
355  bool $allowNull,
356  bool $hasDefaultValue,
357  $defaultValue,
358  bool $autoIncrement,
359  bool $createIndex,
360  bool $createUniqueIndex,
361  bool $isPrimaryKey,
362  string $comment = null,
363  string $columnFormat = null,
364  string $storage = null
365  ) {
366  $statement = sprintf('CREATE TABLE `aTable`(`aField` INT(11) %s);', $columnAttribute);
367  $subject = $this->‪createSubject($statement);
368 
369  self::assertInstanceOf(CreateColumnDefinitionItem::class, $subject);
370  self::assertSame($allowNull, $subject->allowNull);
371  self::assertSame($hasDefaultValue, $subject->hasDefaultValue);
372  self::assertSame($defaultValue, $subject->defaultValue);
373  self::assertSame($createIndex, $subject->index);
374  self::assertSame($createUniqueIndex, $subject->unique);
375  self::assertSame($isPrimaryKey, $subject->primary);
376  self::assertSame($autoIncrement, $subject->autoIncrement);
377  self::assertSame($comment, $subject->comment);
378  self::assertSame($columnFormat, $subject->columnFormat);
379  self::assertSame($storage, $subject->storage);
380  }
381 
388  protected function ‪createSubject(string $statement): ‪CreateColumnDefinitionItem
389  {
390  ‪$parser = new ‪Parser($statement);
392  $createTableStatement = ‪$parser->getAST();
393 
394  return $createTableStatement->createDefinition->items[0];
395  }
396 }
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateTableStatement
Definition: CreateTableStatement.php:24
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateColumnDefinitionItem
Definition: CreateColumnDefinitionItem.php:27
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Core\Database\Schema\Parser\Parser
Definition: Parser.php:71
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\ColumnDefinitionAttributesTest
Definition: ColumnDefinitionAttributesTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\ColumnDefinitionAttributesTest\canParseColumnDefinitionAttributesDataProvider
‪array canParseColumnDefinitionAttributesDataProvider()
Definition: ColumnDefinitionAttributesTest.php:46
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser
Definition: AbstractDataTypeBaseTestCase.php:18
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\ColumnDefinitionAttributesTest\createSubject
‪TYPO3 CMS Core Database Schema Parser AST CreateColumnDefinitionItem createSubject(string $statement)
Definition: ColumnDefinitionAttributesTest.php:388
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\ColumnDefinitionAttributesTest\canParseColumnDefinitionAttributes
‪canParseColumnDefinitionAttributes(string $columnAttribute, bool $allowNull, bool $hasDefaultValue, $defaultValue, bool $autoIncrement, bool $createIndex, bool $createUniqueIndex, bool $isPrimaryKey, string $comment=null, string $columnFormat=null, string $storage=null)
Definition: ColumnDefinitionAttributesTest.php:353