2 declare(strict_types = 1);
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
43 'REFERENCES `anotherTable`(`aColumn`)' => [
44 'REFERENCES `anotherTable`(`aColumn`)',
46 [[
'aColumn', 0,
null]],
51 'REFERENCES `anotherTable`(`aColumn`, anotherColumn)' => [
52 'REFERENCES `anotherTable`(`aColumn`, anotherColumn)',
54 [[
'aColumn', 0,
null], [
'anotherColumn', 0,
null]],
59 'REFERENCES `anotherTable`(`aColumn`(199),`anotherColumn`)' => [
60 'REFERENCES `anotherTable`(`aColumn`(199),`anotherColumn`)',
62 [[
'aColumn', 199,
null], [
'anotherColumn', 0,
null]],
67 'REFERENCES `anotherTable`(`aColumn`(199) ASC, anotherColumn DESC)' => [
68 'REFERENCES `anotherTable`(`aColumn`(199) ASC, anotherColumn DESC)',
70 [[
'aColumn', 199,
'ASC'], [
'anotherColumn', 0,
'DESC']],
75 'REFERENCES anotherTable(aColumn) MATCH FULL' => [
76 'REFERENCES anotherTable(aColumn) MATCH FULL',
78 [[
'aColumn', 0,
null]],
83 'REFERENCES anotherTable(aColumn) MATCH PARTIAL' => [
84 'REFERENCES anotherTable(aColumn) MATCH PARTIAL',
86 [[
'aColumn', 0,
null]],
91 'REFERENCES anotherTable(aColumn) MATCH SIMPLE' => [
92 'REFERENCES anotherTable(aColumn) MATCH SIMPLE',
94 [[
'aColumn', 0,
null]],
99 'REFERENCES anotherTable(aColumn) ON DELETE RESTRICT' => [
100 'REFERENCES anotherTable(aColumn) ON DELETE RESTRICT',
102 [[
'aColumn', 0,
null]],
107 'REFERENCES anotherTable(aColumn) ON DELETE CASCADE' => [
108 'REFERENCES anotherTable(aColumn) ON DELETE CASCADE',
110 [[
'aColumn', 0,
null]],
115 'REFERENCES anotherTable(aColumn) ON DELETE SET NULL' => [
116 'REFERENCES anotherTable(aColumn) ON DELETE SET NULL',
118 [[
'aColumn', 0,
null]],
123 'REFERENCES anotherTable(aColumn) ON DELETE NO ACTION' => [
124 'REFERENCES anotherTable(aColumn) ON DELETE NO ACTION',
126 [[
'aColumn', 0,
null]],
131 'REFERENCES anotherTable(aColumn) ON UPDATE RESTRICT' => [
132 'REFERENCES anotherTable(aColumn) ON UPDATE RESTRICT',
134 [[
'aColumn', 0,
null]],
139 'REFERENCES anotherTable(aColumn) ON UPDATE CASCADE' => [
140 'REFERENCES anotherTable(aColumn) ON UPDATE CASCADE',
142 [[
'aColumn', 0,
null]],
147 'REFERENCES anotherTable(aColumn) ON UPDATE SET NULL' => [
148 'REFERENCES anotherTable(aColumn) ON UPDATE SET NULL',
150 [[
'aColumn', 0,
null]],
155 'REFERENCES anotherTable(aColumn) ON UPDATE NO ACTION' => [
156 'REFERENCES anotherTable(aColumn) ON UPDATE NO ACTION',
158 [[
'aColumn', 0,
null]],
163 'REFERENCES anotherTable(uid, `hash`(199) DESC) MATCH PARTIAL ON DELETE RESTRICT ON UPDATE SET NULL' => [
164 'REFERENCES anotherTable(uid, `hash`(199) DESC) MATCH PARTIAL ON DELETE RESTRICT ON UPDATE SET NULL',
166 [[
'uid', 0,
null], [
'hash', 199,
'DESC']],
185 string $columnAttribute,
188 string $match =
null,
189 string $onDelete =
null,
190 string $onUpdate =
null
192 $statement = sprintf(
'CREATE TABLE `aTable`(`aField` INT(11) %s);', $columnAttribute);
195 $this->assertInstanceOf(ReferenceDefinition::class, $subject);
196 $this->assertSame($table, $subject->tableName->schemaObjectName);
197 $this->assertSame($match, $subject->match);
198 $this->assertSame($onDelete, $subject->onDelete);
199 $this->assertSame($onUpdate, $subject->onUpdate);
201 foreach ($columns as $index => $column) {
202 $this->assertSame($column[0], $subject->columnNames[$index]->columnName->schemaObjectName);
203 $this->assertSame($column[1], $subject->columnNames[$index]->length);
204 $this->assertSame($column[2], $subject->columnNames[$index]->direction);
218 $createTableStatement =
$parser->getAST();
220 return $createTableStatement->createDefinition->items[0]->reference;