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