‪TYPO3CMS  10.4
CreateTableFragmentTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪CreateTableFragmentTest extends UnitTestCase
29 {
39  {
40  return [
41  'CREATE TABLE' => [
42  'CREATE TABLE aTable (aField INT);',
43  'aTable',
44  false
45  ],
46  'CREATE TEMPORARY TABLE' => [
47  'CREATE TEMPORARY TABLE aTable (aField INT);',
48  'aTable',
49  true
50  ],
51  'CREATE TABLE IF NOT EXISTS' => [
52  'CREATE TABLE IF NOT EXISTS aTable (aField INT);',
53  'aTable',
54  false
55  ],
56  'CREATE TEMPORARY TABLE IF NOT EXISTS' => [
57  'CREATE TEMPORARY TABLE IF NOT EXISTS aTable (aField INT);',
58  'aTable',
59  true
60  ],
61  'CREATE TABLE (quoted table name)' => [
62  'CREATE TABLE `aTable` (aField INT);',
63  'aTable',
64  false
65  ],
66  'CREATE TEMPORARY TABLE (quoted table name)' => [
67  'CREATE TEMPORARY TABLE `aTable` (aField INT);',
68  'aTable',
69  true
70  ],
71  'CREATE TABLE IF NOT EXISTS (quoted table name)' => [
72  'CREATE TABLE IF NOT EXISTS `aTable` (aField INT);',
73  'aTable',
74  false
75  ],
76  'CREATE TEMPORARY TABLE IF NOT EXISTS (quoted table name)' => [
77  'CREATE TEMPORARY TABLE IF NOT EXISTS `aTable` (aField INT);',
78  'aTable',
79  true
80  ],
81  ];
82  }
83 
91  public function ‪canParseCreateTableFragment(string $statement, string $tableName, bool $isTemporary)
92  {
93  $subject = $this->‪createSubject($statement);
94  self::assertInstanceOf(CreateTableStatement::class, $subject);
95  self::assertSame($tableName, $subject->tableName->schemaObjectName);
96  self::assertSame($isTemporary, $subject->isTemporary);
97  }
98 
105  protected function ‪createSubject(string $statement): ‪AbstractCreateStatement
106  {
107  ‪$parser = new ‪Parser($statement);
108  return ‪$parser->getAST();
109  }
110 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\CreateTableFragmentTest
Definition: CreateTableFragmentTest.php:29
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateTableStatement
Definition: CreateTableStatement.php:24
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\CreateTableFragmentTest\canParseCreateTableFragmentDataProvider
‪array canParseCreateTableFragmentDataProvider()
Definition: CreateTableFragmentTest.php:38
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Core\Database\Schema\Parser\Parser
Definition: Parser.php:71
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\AbstractCreateStatement
Definition: AbstractCreateStatement.php:25
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\CreateTableFragmentTest\createSubject
‪AbstractCreateStatement CreateTableStatement createSubject(string $statement)
Definition: CreateTableFragmentTest.php:105
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser
Definition: AbstractDataTypeBaseTestCase.php:18
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\CreateTableFragmentTest\canParseCreateTableFragment
‪canParseCreateTableFragment(string $statement, string $tableName, bool $isTemporary)
Definition: CreateTableFragmentTest.php:91