‪TYPO3CMS  9.5
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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪CreateTableFragmentTest extends UnitTestCase
28 {
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 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\CreateTableFragmentTest
Definition: CreateTableFragmentTest.php:28
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateTableStatement
Definition: CreateTableStatement.php:23
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\CreateTableFragmentTest\canParseCreateTableFragmentDataProvider
‪array canParseCreateTableFragmentDataProvider()
Definition: CreateTableFragmentTest.php:37
‪$parser
‪$parser
Definition: annotationChecker.php:100
‪TYPO3\CMS\Core\Database\Schema\Parser\Parser
Definition: Parser.php:28
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\AbstractCreateStatement
Definition: AbstractCreateStatement.php:24
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\CreateTableFragmentTest\createSubject
‪AbstractCreateStatement CreateTableStatement createSubject(string $statement)
Definition: CreateTableFragmentTest.php:104
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser
Definition: AbstractDataTypeBaseTestCase.php:4
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\CreateTableFragmentTest\canParseCreateTableFragment
‪canParseCreateTableFragment(string $statement, string $tableName, bool $isTemporary)
Definition: CreateTableFragmentTest.php:90