Skip to content

Commit

Permalink
Resolves #939 replaced single quotes with nowdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-karkus authored and Kamil Karkus committed Nov 29, 2024
1 parent 1065fbe commit 4e4f8c4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/Generator/SqlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public function generate(
}
}

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

if (count($code) !== 0 && $checkDbPlatform && $this->configuration->isDatabasePlatformChecked()) {
Expand Down
46 changes: 35 additions & 11 deletions tests/Generator/SqlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ public function testGenerate(): void
!\$this->connection->getDatabasePlatform() instanceof \\$expectedPlatform,
"Migration can only be executed safely on '\\$expectedPlatform'."
);
\$this->addSql('SELECT 1');
\$this->addSql('SELECT 2');
\$this->addSql('%s');
\$this->addSql(<<<'SQL'
SELECT 1
SQL);
\$this->addSql(<<<'SQL'
SELECT 2
SQL);
\$this->addSql(<<<'SQL'
%s
SQL);
CODE,
);

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

$expectedCode = $this->prepareGeneratedCode(
<<<'CODE'
$this->addSql('SELECT 1');
$this->addSql('SELECT 2');
$this->addSql('%s');
$this->addSql(<<<'SQL'
SELECT 1
SQL);
$this->addSql(<<<'SQL'
SELECT 2
SQL);
$this->addSql(<<<'SQL'
%s
SQL);
CODE,
);

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

$expectedCode = $this->prepareGeneratedCode(
<<<'CODE'
$this->addSql('SELECT 1');
$this->addSql('SELECT 2');
$this->addSql('%s');
$this->addSql(<<<'SQL'
SELECT 1
SQL);
$this->addSql(<<<'SQL'
SELECT 2
SQL);
$this->addSql(<<<'SQL'
%s
SQL);
CODE,
);

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

return sprintf(
$expectedCode,
(new SqlFormatter(new NullHighlighter()))->format($this->sql[2]),
implode(
PHP_EOL . str_repeat(' ', 4),
explode(
PHP_EOL,
(new SqlFormatter(new NullHighlighter()))->format($this->sql[2]),
),
),
);
}
}

0 comments on commit 4e4f8c4

Please sign in to comment.