TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
CreateTableFragmentTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 
4 namespace TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser;
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 
23 
28 {
37  public function canParseCreateTableFragmentDataProvider(): array
38  {
39  return [
40  'CREATE TABLE' => [
41  'CREATE TABLE aTable (aField INT);',
42  'aTable',
43  false
44  ],
45  'CREATE TEMPORARY TABLE' => [
46  'CREATE TEMPORARY TABLE aTable (aField INT);',
47  'aTable',
48  true
49  ],
50  'CREATE TABLE IF NOT EXISTS' => [
51  'CREATE TABLE IF NOT EXISTS aTable (aField INT);',
52  'aTable',
53  false
54  ],
55  'CREATE TEMPORARY TABLE IF NOT EXISTS' => [
56  'CREATE TEMPORARY TABLE IF NOT EXISTS aTable (aField INT);',
57  'aTable',
58  true
59  ],
60  'CREATE TABLE (quoted table name)' => [
61  'CREATE TABLE `aTable` (aField INT);',
62  'aTable',
63  false
64  ],
65  'CREATE TEMPORARY TABLE (quoted table name)' => [
66  'CREATE TEMPORARY TABLE `aTable` (aField INT);',
67  'aTable',
68  true
69  ],
70  'CREATE TABLE IF NOT EXISTS (quoted table name)' => [
71  'CREATE TABLE IF NOT EXISTS `aTable` (aField INT);',
72  'aTable',
73  false
74  ],
75  'CREATE TEMPORARY TABLE IF NOT EXISTS (quoted table name)' => [
76  'CREATE TEMPORARY TABLE IF NOT EXISTS `aTable` (aField INT);',
77  'aTable',
78  true
79  ],
80  ];
81  }
82 
90  public function canParseCreateTableFragment(string $statement, string $tableName, bool $isTemporary)
91  {
92  $subject = $this->createSubject($statement);
93  $this->assertInstanceOf(CreateTableStatement::class, $subject);
94  $this->assertSame($tableName, $subject->tableName->schemaObjectName);
95  $this->assertSame($isTemporary, $subject->isTemporary);
96  }
97 
104  protected function createSubject(string $statement): AbstractCreateStatement
105  {
106  $parser = new Parser($statement);
107  return $parser->getAST();
108  }
109 }
canParseCreateTableFragment(string $statement, string $tableName, bool $isTemporary)