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