Skip to content

Commit 4e4f8c4

Browse files
KamilKamil Karkus
authored andcommitted
Resolves #939 replaced single quotes with nowdoc
1 parent 1065fbe commit 4e4f8c4

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

src/Generator/SqlGenerator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public function generate(
6161
}
6262
}
6363

64-
$code[] = sprintf('$this->addSql(%s);', var_export($query, true));
64+
$code[] = sprintf(
65+
"\$this->addSql(<<<'SQL'\n%s\nSQL);",
66+
preg_replace('/^/m', str_repeat(' ', 4), $query)
67+
);
6568
}
6669

6770
if (count($code) !== 0 && $checkDbPlatform && $this->configuration->isDatabasePlatformChecked()) {

tests/Generator/SqlGeneratorTest.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ public function testGenerate(): void
4747
!\$this->connection->getDatabasePlatform() instanceof \\$expectedPlatform,
4848
"Migration can only be executed safely on '\\$expectedPlatform'."
4949
);
50-
51-
\$this->addSql('SELECT 1');
52-
\$this->addSql('SELECT 2');
53-
\$this->addSql('%s');
50+
51+
\$this->addSql(<<<'SQL'
52+
SELECT 1
53+
SQL);
54+
\$this->addSql(<<<'SQL'
55+
SELECT 2
56+
SQL);
57+
\$this->addSql(<<<'SQL'
58+
%s
59+
SQL);
5460
CODE,
5561
);
5662

@@ -65,9 +71,15 @@ public function testGenerationWithoutCheckingDatabasePlatform(): void
6571

6672
$expectedCode = $this->prepareGeneratedCode(
6773
<<<'CODE'
68-
$this->addSql('SELECT 1');
69-
$this->addSql('SELECT 2');
70-
$this->addSql('%s');
74+
$this->addSql(<<<'SQL'
75+
SELECT 1
76+
SQL);
77+
$this->addSql(<<<'SQL'
78+
SELECT 2
79+
SQL);
80+
$this->addSql(<<<'SQL'
81+
%s
82+
SQL);
7183
CODE,
7284
);
7385

@@ -82,9 +94,15 @@ public function testGenerationWithoutCheckingDatabasePlatformWithConfiguration()
8294

8395
$expectedCode = $this->prepareGeneratedCode(
8496
<<<'CODE'
85-
$this->addSql('SELECT 1');
86-
$this->addSql('SELECT 2');
87-
$this->addSql('%s');
97+
$this->addSql(<<<'SQL'
98+
SELECT 1
99+
SQL);
100+
$this->addSql(<<<'SQL'
101+
SELECT 2
102+
SQL);
103+
$this->addSql(<<<'SQL'
104+
%s
105+
SQL);
88106
CODE,
89107
);
90108

@@ -119,7 +137,13 @@ private function prepareGeneratedCode(string $expectedCode): string
119137

120138
return sprintf(
121139
$expectedCode,
122-
(new SqlFormatter(new NullHighlighter()))->format($this->sql[2]),
140+
implode(
141+
PHP_EOL . str_repeat(' ', 4),
142+
explode(
143+
PHP_EOL,
144+
(new SqlFormatter(new NullHighlighter()))->format($this->sql[2]),
145+
),
146+
),
123147
);
124148
}
125149
}

0 commit comments

Comments
 (0)