[TASK] Mock SignalSlot\Dispatcher Singletons in unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Database / Schema / SqlReaderTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Core\Tests\Unit\Database\Schema;
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
19 use TYPO3\CMS\Core\Database\Schema\SqlReader;
20 use TYPO3\CMS\Core\Package\PackageManager;
21 use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 /**
25 * Test case
26 */
27 class SqlReaderTest extends UnitTestCase
28 {
29 /**
30 * @var bool Reset singletons created by subject
31 */
32 protected $resetSingletonInstances = true;
33
34 /**
35 * @test
36 */
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
50 /**
51 * @test
52 */
53 public function getStatementArrayFiltersStatements()
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
66 /**
67 * @test
68 */
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
82 /**
83 * @test
84 */
85 public function getInsertStatementArrayResultWithNewline()
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
100 /**
101 * @test
102 */
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 }