‪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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 final class ‪TableOptionsTest extends UnitTestCase
32 {
38  public static function ‪canParseTableOptionsDataProvider(): array
39  {
40  return [
41  'ENGINE engine_name' => [
42  'ENGINE MyISAM',
43  ['engine' => 'MyISAM'],
44  ],
45  'ENGINE = engine_name' => [
46  'ENGINE = InnoDB',
47  ['engine' => 'InnoDB'],
48  ],
49  'AUTO_INCREMENT' => [
50  'AUTO_INCREMENT = 17',
51  ['auto_increment' => 17],
52  ],
53  'AVG_ROW_LENGTH' => [
54  'AVG_ROW_LENGTH=21',
55  ['average_row_length' => 21],
56  ],
57  'DEFAULT CHARACTER SET' => [
58  'DEFAULT CHARACTER SET latin1',
59  ['character_set' => 'latin1'],
60  ],
61  'CHECKSUM' => [
62  'CHECKSUM =0',
63  ['checksum' => 0],
64  ],
65  'COLLATE' => [
66  'COLLATE = utf8mb4_general_ci',
67  ['collation' => 'utf8mb4_general_ci'],
68  ],
69  'COMMENT' => [
70  "COMMENT = 'aComment'",
71  ['comment' => 'aComment'],
72  ],
73  'COMPRESSION' => [
74  'COMPRESSION = ZLIB',
75  ['compression' => 'ZLIB'],
76  ],
77  'CONNECTION' => [
78  'CONNECTION = connect_string',
79  ['connection' => 'connect_string'],
80  ],
81  'DATA DIRECTORY' => [
82  'DATA DIRECTORY = \'/var/lib/mysql/\'',
83  ['data_directory' => '/var/lib/mysql/'],
84  ],
85  'DELAY_KEY_WRITE' => [
86  'DELAY_KEY_WRITE 0',
87  ['delay_key_write' => 0],
88  ],
89  'ENCRYPTION' => [
90  'ENCRYPTION = Y',
91  ['encryption' => 'Y'],
92  ],
93  'INDEX DIRECTORY' => [
94  'INDEX DIRECTORY = \'/data/mysql/\'',
95  ['index_directory' => '/data/mysql/'],
96  ],
97  'INSERT_METHOD' => [
98  'INSERT_METHOD FIRST',
99  ['insert_method' => 'FIRST'],
100  ],
101  'KEY_BLOCK_SIZE' => [
102  'KEY_BLOCK_SIZE 16',
103  ['key_block_size' => 16],
104  ],
105  'MAX_ROWS' => [
106  'MAX_ROWS = 1000',
107  ['max_rows' => 1000],
108  ],
109  'MIN_ROWS' => [
110  'MIN_ROWS 10',
111  ['min_rows' => 10],
112  ],
113  'PACK_KEYS' => [
114  'PACK_KEYS DEFAULT',
115  ['pack_keys' => 'DEFAULT'],
116  ],
117  'PASSWORD' => [
118  "PASSWORD = 'aPassword'",
119  ['password' => 'aPassword'],
120  ],
121  'ROW_FORMAT' => [
122  'ROW_FORMAT = DYNAMIC',
123  ['row_format' => 'DYNAMIC'],
124  ],
125  'STATS_AUTO_RECALC' => [
126  'STATS_AUTO_RECALC 1',
127  ['stats_auto_recalc' => '1'],
128  ],
129  'STATS_PERSISTENT' => [
130  'STATS_PERSISTENT 0',
131  ['stats_persistent' => '0'],
132  ],
133  'STATS_SAMPLE_PAGES' => [
134  'STATS_SAMPLE_PAGES DEFAULT',
135  ['stats_sample_pages' => 'DEFAULT'],
136  ],
137  'TABLESPACE' => [
138  'TABLESPACE `anotherTableSpace`',
139  ['tablespace' => 'anotherTableSpace'],
140  ],
141  ];
142  }
143 
144  #[DataProvider('canParseTableOptionsDataProvider')]
145  #[Test]
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:38
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateTableStatement
Definition: CreateTableStatement.php:26
‪$parser
‪$parser
Definition: annotationChecker.php:103
‪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:32
‪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