‪TYPO3CMS  9.5
TableBuilderTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Doctrine\DBAL\Schema\ForeignKeyConstraint;
20 use Doctrine\DBAL\Schema\Index;
21 use Doctrine\DBAL\Schema\Table;
22 use Doctrine\DBAL\Types\IntegerType;
23 use Doctrine\DBAL\Types\SmallIntType;
24 use Doctrine\DBAL\Types\TextType;
27 use TYPO3\CMS\Core\Package\PackageManager;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
34 class ‪TableBuilderTest extends UnitTestCase
35 {
39  protected ‪$resetSingletonInstances = true;
40 
44  protected ‪$table;
45 
49  protected function ‪setUp()
50  {
51  parent::setUp();
52  $sqlFile = file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', 'Fixtures', 'tablebuilder.sql']));
53  $signalSlotDispatcherProphecy = $this->prophesize(Dispatcher::class);
54  $packageManagerProphecy = $this->prophesize(PackageManager::class);
55  $sqlReader = new ‪SqlReader($signalSlotDispatcherProphecy->reveal(), $packageManagerProphecy->reveal());
56  $statements = $sqlReader->getCreateTableStatementArray($sqlFile);
57 
58  ‪$parser = new ‪Parser($statements[0]);
59  $this->table = ‪$parser->parse()[0];
60  }
61 
65  public function ‪hasExpectedTableName()
66  {
67  $this->assertSame('aTestTable', $this->table->getName());
68  }
69 
73  public function ‪hasExpectedTableEngine()
74  {
75  $this->assertTrue($this->table->hasOption('engine'));
76  $this->assertSame('MyISAM', $this->table->getOption('engine'));
77  }
78 
82  public function ‪hasExpectedTableCollation()
83  {
84  $this->assertTrue($this->table->hasOption('charset'));
85  $this->assertSame('latin1', $this->table->getOption('charset'));
86  }
87 
91  public function ‪hasExpectedTableCharacterSet()
92  {
93  $this->assertTrue($this->table->hasOption('collate'));
94  $this->assertSame('latin1_german_cs', $this->table->getOption('collate'));
95  }
96 
100  public function ‪hasExpectedTableRowFormat()
101  {
102  $this->assertTrue($this->table->hasOption('row_format'));
103  $this->assertSame('DYNAMIC', $this->table->getOption('row_format'));
104  }
105 
109  public function ‪hasExpectedTableAutoIncrementValue()
110  {
111  $this->assertTrue($this->table->hasOption('auto_increment'));
112  $this->assertSame('1', $this->table->getOption('auto_increment'));
113  }
114 
118  public function ‪isExpectedUidColumn()
119  {
120  $subject = $this->table->getColumn('uid');
121  $this->assertInstanceOf(IntegerType::class, $subject->getType());
122  $this->assertSame(11, $subject->getLength());
123  $this->assertFalse($subject->getUnsigned());
124  $this->assertTrue($subject->getNotnull());
125  $this->assertNull($subject->getDefault());
126  $this->assertTrue($subject->getAutoincrement());
127  }
128 
132  public function ‪isExpectedPidColumn()
133  {
134  $subject = $this->table->getColumn('pid');
135  $this->assertInstanceOf(IntegerType::class, $subject->getType());
136  $this->assertSame(11, $subject->getLength());
137  $this->assertFalse($subject->getUnsigned());
138  $this->assertTrue($subject->getNotnull());
139  $this->assertFalse($subject->getAutoincrement());
140  $this->assertSame('0', $subject->getDefault());
141  }
142 
146  public function ‪isExpectedTstampColumn()
147  {
148  $subject = $this->table->getColumn('tstamp');
149  $this->assertInstanceOf(IntegerType::class, $subject->getType());
150  $this->assertSame(11, $subject->getLength());
151  $this->assertTrue($subject->getUnsigned());
152  $this->assertTrue($subject->getNotnull());
153  $this->assertFalse($subject->getAutoincrement());
154  $this->assertSame('0', $subject->getDefault());
155  }
156 
160  public function ‪isExpectedSortingColumn()
161  {
162  $subject = $this->table->getColumn('sorting');
163  $this->assertInstanceOf(IntegerType::class, $subject->getType());
164  $this->assertSame(11, $subject->getLength());
165  $this->assertTrue($subject->getUnsigned());
166  $this->assertTrue($subject->getNotnull());
167  $this->assertFalse($subject->getAutoincrement());
168  $this->assertSame(0, $subject->getDefault());
169  }
170 
174  public function ‪isExpectedDeletedColumn()
175  {
176  $subject = $this->table->getColumn('deleted');
177  $this->assertInstanceOf(SmallIntType::class, $subject->getType());
178  $this->assertSame(1, $subject->getLength());
179  $this->assertTrue($subject->getUnsigned());
180  $this->assertTrue($subject->getNotnull());
181  $this->assertFalse($subject->getAutoincrement());
182  $this->assertSame('0', $subject->getDefault());
183  }
184 
188  public function ‪isExpectedTSconfigColumn()
189  {
190  $subject = $this->table->getColumn('TSconfig');
191  $this->assertInstanceOf(TextType::class, $subject->getType());
192  $this->assertSame(65535, $subject->getLength());
193  $this->assertFalse($subject->getNotnull());
194  $this->assertNull($subject->getDefault());
195  }
196 
200  public function ‪isExpectedNoCacheColumn()
201  {
202  $subject = $this->table->getColumn('no_cache');
203  $this->assertInstanceOf(IntegerType::class, $subject->getType());
204  $this->assertSame(10, $subject->getLength());
205  $this->assertTrue($subject->getUnsigned());
206  $this->assertTrue($subject->getNotnull());
207  $this->assertFalse($subject->getAutoincrement());
208  $this->assertSame('0', $subject->getDefault());
209  }
210 
214  public function ‪isExpectedPrimaryKey()
215  {
216  $subject = $this->table->getPrimaryKey();
217  $this->assertInstanceOf(Index::class, $subject);
218  $this->assertTrue($subject->isPrimary());
219  $this->assertSame(['`uid`'], $subject->getColumns());
220  }
221 
225  public function ‪isExpectedParentKey()
226  {
227  $subject = $this->table->getIndex('parent');
228  $this->assertInstanceOf(Index::class, $subject);
229  $this->assertTrue($subject->isUnique());
230  $this->assertSame(['`pid`', '`deleted`', '`sorting`'], $subject->getColumns());
231  }
232 
236  public function ‪isExpectedNoCacheKey()
237  {
238  $subject = $this->table->getIndex('noCache');
239  $this->assertInstanceOf(Index::class, $subject);
240  $this->assertTrue($subject->isSimpleIndex());
241  $this->assertSame(['`no_cache`'], $subject->getColumns());
242  }
243 
247  public function ‪isExpectedForeignKey()
248  {
249  $subject = $this->table->getForeignKey('fk_overlay');
250  $this->assertInstanceOf(ForeignKeyConstraint::class, $subject);
251  $this->assertSame(['`pid`'], $subject->getForeignColumns());
252  $this->assertSame(['`uid`'], $subject->getLocalColumns());
253  $this->assertSame('aTestTable', $subject->getLocalTableName());
254  $this->assertSame('any_foreign_table', $subject->getForeignTableName());
255  }
256 
260  public function ‪hasColumnLengthOnIndex()
261  {
262  $subject = $this->table->getIndex('substring');
263  $this->assertSame(['`TSconfig`(80)'], $subject->getColumns());
264  }
265 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedPrimaryKey
‪isExpectedPrimaryKey()
Definition: TableBuilderTest.php:212
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedNoCacheKey
‪isExpectedNoCacheKey()
Definition: TableBuilderTest.php:234
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedTstampColumn
‪isExpectedTstampColumn()
Definition: TableBuilderTest.php:144
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableName
‪hasExpectedTableName()
Definition: TableBuilderTest.php:63
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableEngine
‪hasExpectedTableEngine()
Definition: TableBuilderTest.php:71
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\setUp
‪setUp()
Definition: TableBuilderTest.php:47
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasColumnLengthOnIndex
‪hasColumnLengthOnIndex()
Definition: TableBuilderTest.php:258
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedDeletedColumn
‪isExpectedDeletedColumn()
Definition: TableBuilderTest.php:172
‪$parser
‪$parser
Definition: annotationChecker.php:100
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedPidColumn
‪isExpectedPidColumn()
Definition: TableBuilderTest.php:130
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableCharacterSet
‪hasExpectedTableCharacterSet()
Definition: TableBuilderTest.php:89
‪TYPO3\CMS\Core\Database\Schema\SqlReader
Definition: SqlReader.php:29
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedParentKey
‪isExpectedParentKey()
Definition: TableBuilderTest.php:223
‪TYPO3\CMS\Core\Database\Schema\Parser\Parser
Definition: Parser.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: TableBuilderTest.php:38
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\$table
‪Table $table
Definition: TableBuilderTest.php:42
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedForeignKey
‪isExpectedForeignKey()
Definition: TableBuilderTest.php:245
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableRowFormat
‪hasExpectedTableRowFormat()
Definition: TableBuilderTest.php:98
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedTSconfigColumn
‪isExpectedTSconfigColumn()
Definition: TableBuilderTest.php:186
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedSortingColumn
‪isExpectedSortingColumn()
Definition: TableBuilderTest.php:158
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedNoCacheColumn
‪isExpectedNoCacheColumn()
Definition: TableBuilderTest.php:198
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableCollation
‪hasExpectedTableCollation()
Definition: TableBuilderTest.php:80
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser
Definition: AbstractDataTypeBaseTestCase.php:4
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\isExpectedUidColumn
‪isExpectedUidColumn()
Definition: TableBuilderTest.php:116
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest\hasExpectedTableAutoIncrementValue
‪hasExpectedTableAutoIncrementValue()
Definition: TableBuilderTest.php:107
‪TYPO3\CMS\Extbase\SignalSlot\Dispatcher
Definition: Dispatcher.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableBuilderTest
Definition: TableBuilderTest.php:35