‪TYPO3CMS  10.4
SqlReaderTest.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 
20 use Psr\EventDispatcher\EventDispatcherInterface;
22 use TYPO3\CMS\Core\Package\PackageManager;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪SqlReaderTest extends UnitTestCase
29 {
33  protected ‪$resetSingletonInstances = true;
34 
38  public function ‪getStatementArraySplitsStatements()
39  {
40  $subject = new ‪SqlReader($this->prophesize(EventDispatcherInterface::class)->reveal(), $this->prophesize(PackageManager::class)->reveal());
41  $result = $subject->getStatementArray(
42  'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
43  LF .
44  'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
45  );
46  self::assertCount(2, $result);
47  self::assertStringStartsWith('CREATE TABLE', $result[0]);
48  self::assertStringStartsWith('INSERT INTO', $result[1]);
49  }
50 
55  {
56  $subject = new ‪SqlReader($this->prophesize(EventDispatcherInterface::class)->reveal(), $this->prophesize(PackageManager::class)->reveal());
57  $result = $subject->getStatementArray(
58  'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
59  LF .
60  'INSERT INTO aTestTable(`aTestField`) VALUES(1);',
61  '^CREATE TABLE'
62  );
63  self::assertCount(1, $result);
64  self::assertStringStartsWith('CREATE TABLE', array_pop($result));
65  }
66 
70  public function ‪getInsertStatementArrayResult()
71  {
72  $subject = new ‪SqlReader($this->prophesize(EventDispatcherInterface::class)->reveal(), $this->prophesize(PackageManager::class)->reveal());
73  $result = $subject->getInsertStatementArray(
74  'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
75  LF .
76  'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
77  );
78 
79  self::assertCount(1, $result);
80  self::assertStringStartsWith('INSERT', array_pop($result));
81  }
82 
87  {
88  $subject = new ‪SqlReader($this->prophesize(EventDispatcherInterface::class)->reveal(), $this->prophesize(PackageManager::class)->reveal());
89  $result = $subject->getInsertStatementArray(
90  'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
91  LF .
92  'INSERT INTO aTestTable(`aTestField`) ' .
93  LF .
94  'VALUES(1);'
95  );
96 
97  self::assertCount(1, $result);
98  self::assertSame('INSERT INTO aTestTable(`aTestField`) VALUES(1);', array_pop($result));
99  }
100 
104  public function ‪getCreateTableStatementArrayResult()
105  {
106  $subject = new ‪SqlReader($this->prophesize(EventDispatcherInterface::class)->reveal(), $this->prophesize(PackageManager::class)->reveal());
107  $result = $subject->getCreateTableStatementArray(
108  'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
109  LF .
110  'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
111  );
112  self::assertCount(1, $result);
113  self::assertStringStartsWith('CREATE TABLE', array_pop($result));
114  }
115 
121  public function ‪getCreateTableStatementArrayResultWithComment(string $comment)
122  {
123  $subject = new ‪SqlReader($this->prophesize(EventDispatcherInterface::class)->reveal(), $this->prophesize(PackageManager::class)->reveal());
124  $result = $subject->getCreateTableStatementArray(
125  $comment . LF . 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
126  LF .
127  'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
128  );
129  self::assertCount(1, $result);
130  self::assertStringStartsWith('CREATE TABLE', array_pop($result));
131  }
132 
133  public function ‪commentProvider(): array
134  {
135  return [
136  'Single line comment starting with "#"' => [
137  '# Comment'
138  ],
139  'Single line comment starting with "--"' => [
140  '-- Comment'
141  ],
142  'Single line c-style comment' => [
143  '/* Same line c-style comment */'
144  ],
145  'Multiline comment variant 1' => [
146  '/*' . LF . 'Some comment text' . LF . 'more text' . LF . '*/'
147  ],
148  'Multiline comment variant 2' => [
149  '/* More' . LF . ' comments */'
150  ]
151  ];
152  }
153 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\SqlReaderTest\getCreateTableStatementArrayResultWithComment
‪getCreateTableStatementArrayResultWithComment(string $comment)
Definition: SqlReaderTest.php:120
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema
Definition: ConnectionMigratorTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\SqlReaderTest\commentProvider
‪commentProvider()
Definition: SqlReaderTest.php:132
‪TYPO3\CMS\Core\Database\Schema\SqlReader
Definition: SqlReader.php:31
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\SqlReaderTest\getStatementArraySplitsStatements
‪getStatementArraySplitsStatements()
Definition: SqlReaderTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\SqlReaderTest\getInsertStatementArrayResult
‪getInsertStatementArrayResult()
Definition: SqlReaderTest.php:69
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\SqlReaderTest
Definition: SqlReaderTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\SqlReaderTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: SqlReaderTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\SqlReaderTest\getCreateTableStatementArrayResult
‪getCreateTableStatementArrayResult()
Definition: SqlReaderTest.php:103
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\SqlReaderTest\getInsertStatementArrayResultWithNewline
‪getInsertStatementArrayResultWithNewline()
Definition: SqlReaderTest.php:85
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\SqlReaderTest\getStatementArrayFiltersStatements
‪getStatementArrayFiltersStatements()
Definition: SqlReaderTest.php:53