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