[BUGFIX] Set correct unit test namespaces
[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\Utility\GeneralUtility;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 /**
24 * Tests for SqlReader
25 */
26 class SqlReaderTest extends UnitTestCase
27 {
28 /**
29 * @var SqlReader
30 */
31 protected $subject;
32
33 /**
34 * Set up the test subject
35 */
36 protected function setUp()
37 {
38 parent::setUp();
39 $this->subject = GeneralUtility::makeInstance(SqlReader::class);
40 }
41
42 /**
43 * @test
44 */
45 public function getStatementArraySplitsStatements()
46 {
47 $result = $this->subject->getStatementArray(
48 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
49 LF .
50 'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
51 );
52 $this->assertCount(2, $result);
53 $this->assertStringStartsWith('CREATE TABLE', $result[0]);
54 $this->assertStringStartsWith('INSERT INTO', $result[1]);
55 }
56
57 /**
58 * @test
59 */
60 public function getStatementArrayFiltersStatements()
61 {
62 $result = $this->subject->getStatementArray(
63 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
64 LF .
65 'INSERT INTO aTestTable(`aTestField`) VALUES(1);',
66 '^CREATE TABLE'
67 );
68 $this->assertCount(1, $result);
69 $this->assertStringStartsWith('CREATE TABLE', array_pop($result));
70 }
71
72 /**
73 * @test
74 */
75 public function getInsertStatementArrayResult()
76 {
77 $result = $this->subject->getInsertStatementArray(
78 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
79 LF .
80 'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
81 );
82
83 $this->assertCount(1, $result);
84 $this->assertStringStartsWith('INSERT', array_pop($result));
85 }
86
87 /**
88 * @test
89 */
90 public function getInsertStatementArrayResultWithNewline()
91 {
92 $result = $this->subject->getInsertStatementArray(
93 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
94 LF .
95 'INSERT INTO aTestTable(`aTestField`) ' .
96 LF .
97 'VALUES(1);'
98 );
99
100 $this->assertCount(1, $result);
101 $this->assertSame('INSERT INTO aTestTable(`aTestField`) VALUES(1);', array_pop($result));
102 }
103
104 /**
105 * @test
106 */
107 public function getCreateTableStatementArrayResult()
108 {
109 $result = $this->subject->getCreateTableStatementArray(
110 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' .
111 LF .
112 'INSERT INTO aTestTable(`aTestField`) VALUES(1);'
113 );
114 $this->assertCount(1, $result);
115 $this->assertStringStartsWith('CREATE TABLE', array_pop($result));
116 }
117 }