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 committed Nov 29, 2024
1 parent 1065fbe commit a8ef2a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 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
42 changes: 30 additions & 12 deletions tests/Generator/SqlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ public function testGenerate(): void
"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,
);

$code = $migrationSqlGenerator->generate($this->sql, true, 80);
$code = $migrationSqlGenerator->generate($this->sql, true, false,80);

self::assertSame($expectedCode, $code);
}
Expand All @@ -65,13 +71,19 @@ 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,
);

$code = $this->migrationSqlGenerator->generate($this->sql, true, 80, false);
$code = $this->migrationSqlGenerator->generate($this->sql, true, false, 80, false);

self::assertSame($expectedCode, $code);
}
Expand All @@ -82,13 +94,19 @@ 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,
);

$code = $this->migrationSqlGenerator->generate($this->sql, true, 80);
$code = $this->migrationSqlGenerator->generate($this->sql, true, false,80);

self::assertSame($expectedCode, $code);
}
Expand Down

0 comments on commit a8ef2a8

Please sign in to comment.