‪TYPO3CMS  9.5
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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪TableOptionsTest extends UnitTestCase
28 {
36  public 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 
148  public function ‪canParseTableOptions(
149  string $tableOptionsSQL,
150  array $expectedTableOptions
151  ) {
152  $statement = sprintf('CREATE TABLE `aTable`(`aField` INT(11)) %s;', $tableOptionsSQL);
153  $subject = $this->‪createSubject($statement);
154 
155  $this->assertInstanceOf(CreateTableStatement::class, $subject);
156  $this->assertSame($expectedTableOptions, $subject->tableOptions);
157  }
158 
165  protected function ‪createSubject(string $statement): ‪AbstractCreateStatement
166  {
167  ‪$parser = new ‪Parser($statement);
168  return ‪$parser->getAST();
169  }
170 }
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateTableStatement
Definition: CreateTableStatement.php:23
‪$parser
‪$parser
Definition: annotationChecker.php:100
‪TYPO3\CMS\Core\Database\Schema\Parser\Parser
Definition: Parser.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableOptionsTest\createSubject
‪AbstractCreateStatement CreateTableStatement createSubject(string $statement)
Definition: TableOptionsTest.php:165
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\AbstractCreateStatement
Definition: AbstractCreateStatement.php:24
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableOptionsTest
Definition: TableOptionsTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser
Definition: AbstractDataTypeBaseTestCase.php:4
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableOptionsTest\canParseTableOptions
‪canParseTableOptions(string $tableOptionsSQL, array $expectedTableOptions)
Definition: TableOptionsTest.php:148
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\TableOptionsTest\canParseTableOptionsDataProvider
‪array canParseTableOptionsDataProvider()
Definition: TableOptionsTest.php:36