‪TYPO3CMS  10.4
TableOptionsTest.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 ‪TableOptionsTest extends UnitTestCase
29 {
37  public function ‪canParseTableOptionsDataProvider(): array
38  {
39  return [
40  'ENGINE engine_name' => [
41  'ENGINE MyISAM',
42  ['engine' => 'MyISAM'],
43  ],
44  'ENGINE = engine_name' => [
45  'ENGINE = InnoDB',
46  ['engine' => 'InnoDB'],
47  ],
48  'AUTO_INCREMENT' => [
49  'AUTO_INCREMENT = 17',
50  ['auto_increment' => 17],
51  ],
52  'AVG_ROW_LENGTH' => [
53  'AVG_ROW_LENGTH=21',
54  ['average_row_length' => 21],
55  ],
56  'DEFAULT CHARACTER SET' => [
57  'DEFAULT CHARACTER SET latin1',
58  ['character_set' => 'latin1'],
59  ],
60  'CHECKSUM' => [
61  'CHECKSUM =0',
62  ['checksum' => 0],
63  ],
64  'COLLATE' => [
65  'COLLATE = utf8mb4_general_ci',
66  ['collation' => 'utf8mb4_general_ci'],
67  ],
68  'COMMENT' => [
69  "COMMENT = 'aComment'",
70  ['comment' => 'aComment'],
71  ],
72  'COMPRESSION' => [
73  'COMPRESSION = ZLIB',
74  ['compression' => 'ZLIB'],
75  ],
76  'CONNECTION' => [
77  'CONNECTION = connect_string',
78  ['connection' => 'connect_string'],
79  ],
80  'DATA DIRECTORY' => [
81  'DATA DIRECTORY = \'/var/lib/mysql/\'',
82  ['data_directory' => '/var/lib/mysql/'],
83  ],
84  'DELAY_KEY_WRITE' => [
85  'DELAY_KEY_WRITE 0',
86  ['delay_key_write' => 0],
87  ],
88  'ENCRYPTION' => [
89  'ENCRYPTION = Y',
90  ['encryption' => 'Y'],
91  ],
92  'INDEX DIRECTORY' => [
93  'INDEX DIRECTORY = \'/data/mysql/\'',
94  ['index_directory' => '/data/mysql/'],
95  ],
96  'INSERT_METHOD' => [
97  'INSERT_METHOD FIRST',
98  ['insert_method' => 'FIRST'],
99  ],
100  'KEY_BLOCK_SIZE' => [
101  'KEY_BLOCK_SIZE 16',
102  ['key_block_size' => 16],
103  ],
104  'MAX_ROWS' => [
105  'MAX_ROWS = 1000',
106  ['max_rows' => 1000],
107  ],
108  'MIN_ROWS' => [
109  'MIN_ROWS 10',
110  ['min_rows' => 10],
111  ],
112  'PACK_KEYS' => [
113  'PACK_KEYS DEFAULT',
114  ['pack_keys' => 'DEFAULT'],
115  ],
116  'PASSWORD' => [
117  "PASSWORD = 'aPassword'",
118  ['password' => 'aPassword'],
119  ],
120  'ROW_FORMAT' => [
121  'ROW_FORMAT = DYNAMIC',
122  ['row_format' => 'DYNAMIC'],
123  ],
124  'STATS_AUTO_RECALC' => [
125  'STATS_AUTO_RECALC 1',
126  ['stats_auto_recalc' => '1'],
127  ],
128  'STATS_PERSISTENT' => [
129  'STATS_PERSISTENT 0',
130  ['stats_persistent' => '0'],
131  ],
132  'STATS_SAMPLE_PAGES' => [
133  'STATS_SAMPLE_PAGES DEFAULT',
134  ['stats_sample_pages' => 'DEFAULT'],
135  ],
136  'TABLESPACE' => [
137  'TABLESPACE `anotherTableSpace`',
138  ['tablespace' => 'anotherTableSpace'],
139  ]
140  ];
141  }
142 
149  public function ‪canParseTableOptions(
150  string $tableOptionsSQL,
151  array $expectedTableOptions
152  ) {
153  $statement = sprintf('CREATE TABLE `aTable`(`aField` INT(11)) %s;', $tableOptionsSQL);
154  $subject = $this->‪createSubject($statement);
155 
156  self::assertInstanceOf(CreateTableStatement::class, $subject);
157  self::assertSame($expectedTableOptions, $subject->tableOptions);
158  }
159 
166  protected function ‪createSubject(string $statement): ‪AbstractCreateStatement
167  {
168  ‪$parser = new ‪Parser($statement);
169  return ‪$parser->getAST();
170  }
171 }
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateTableStatement
Definition: CreateTableStatement.php:24
‪$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\TableOptionsTest\createSubject
‪AbstractCreateStatement CreateTableStatement createSubject(string $statement)
Definition: TableOptionsTest.php:166
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\AbstractCreateStatement
Definition: AbstractCreateStatement.php:25
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableOptionsTest
Definition: TableOptionsTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser
Definition: AbstractDataTypeBaseTestCase.php:18
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableOptionsTest\canParseTableOptions
‪canParseTableOptions(string $tableOptionsSQL, array $expectedTableOptions)
Definition: TableOptionsTest.php:149
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableOptionsTest\canParseTableOptionsDataProvider
‪array canParseTableOptionsDataProvider()
Definition: TableOptionsTest.php:37