TYPO3 CMS  TYPO3_8-7
CreateTableFragmentTest.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 CreateTableFragmentTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
36  public function canParseCreateTableFragmentDataProvider(): array
37  {
38  return [
39  'CREATE TABLE' => [
40  'CREATE TABLE aTable (aField INT);',
41  'aTable',
42  false
43  ],
44  'CREATE TEMPORARY TABLE' => [
45  'CREATE TEMPORARY TABLE aTable (aField INT);',
46  'aTable',
47  true
48  ],
49  'CREATE TABLE IF NOT EXISTS' => [
50  'CREATE TABLE IF NOT EXISTS aTable (aField INT);',
51  'aTable',
52  false
53  ],
54  'CREATE TEMPORARY TABLE IF NOT EXISTS' => [
55  'CREATE TEMPORARY TABLE IF NOT EXISTS aTable (aField INT);',
56  'aTable',
57  true
58  ],
59  'CREATE TABLE (quoted table name)' => [
60  'CREATE TABLE `aTable` (aField INT);',
61  'aTable',
62  false
63  ],
64  'CREATE TEMPORARY TABLE (quoted table name)' => [
65  'CREATE TEMPORARY TABLE `aTable` (aField INT);',
66  'aTable',
67  true
68  ],
69  'CREATE TABLE IF NOT EXISTS (quoted table name)' => [
70  'CREATE TABLE IF NOT EXISTS `aTable` (aField INT);',
71  'aTable',
72  false
73  ],
74  'CREATE TEMPORARY TABLE IF NOT EXISTS (quoted table name)' => [
75  'CREATE TEMPORARY TABLE IF NOT EXISTS `aTable` (aField INT);',
76  'aTable',
77  true
78  ],
79  ];
80  }
81 
89  public function canParseCreateTableFragment(string $statement, string $tableName, bool $isTemporary)
90  {
91  $subject = $this->createSubject($statement);
92  $this->assertInstanceOf(CreateTableStatement::class, $subject);
93  $this->assertSame($tableName, $subject->tableName->schemaObjectName);
94  $this->assertSame($isTemporary, $subject->isTemporary);
95  }
96 
103  protected function createSubject(string $statement): AbstractCreateStatement
104  {
105  $parser = new Parser($statement);
106  return $parser->getAST();
107  }
108 }
canParseCreateTableFragment(string $statement, string $tableName, bool $isTemporary)