Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generators #43

Merged
merged 1 commit into from
Apr 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 24 additions & 73 deletions tests/SqlFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\SqlFormatter\NullHighlighter;
use Doctrine\SqlFormatter\SqlFormatter;
use Doctrine\SqlFormatter\Tokenizer;
use Generator;
use PHPUnit\Framework\TestCase;
use function assert;
use function defined;
Expand Down Expand Up @@ -123,108 +124,58 @@ public function testUsePre() : void
}

/**
* @return mixed[][]
* @return Generator<mixed[]>
*/
public function formatHighlightData() : array
private function fileDataProvider(string $file) : Generator
{
$contents = file_get_contents(__DIR__ . '/format-highlight.html');
$contents = file_get_contents(__DIR__ . '/' . $file);
assert($contents !== false);
$formatHighlightData = explode("\n\n", $contents);
$sqlData = $this->sqlData();

$return = [];
foreach ($formatHighlightData as $i => $data) {
$return[] = [
$sqlData[$i],
$data,
];
yield [$sqlData[$i], $data];
}

return $return;
}

/**
* @return mixed[][]
* @return Generator<mixed[]>
*/
public function highlightCliData() : array
public function formatHighlightData() : Generator
{
$contents = file_get_contents(__DIR__ . '/clihighlight.html');
assert($contents !== false);
$clidata = explode("\n\n", $contents);
$sqlData = $this->sqlData();

$return = [];
foreach ($clidata as $i => $data) {
$return[] = [
$sqlData[$i],
$data,
];
}

return $return;
return $this->fileDataProvider('format-highlight.html');
}

/**
* @return mixed[][]
* @return Generator<mixed[]>
*/
public function formatData() : array
public function highlightCliData() : Generator
{
$contents = file_get_contents(__DIR__ . '/format.html');
assert($contents !== false);
$formatData = explode("\n\n", $contents);
$sqlData = $this->sqlData();

$return = [];
foreach ($formatData as $i => $data) {
$return[] = [
$sqlData[$i],
$data,
];
}

return $return;
return $this->fileDataProvider('clihighlight.html');
}

/**
* @return mixed[][]
* @return Generator<mixed[]>
*/
public function compressData() : array
public function formatData() : Generator
{
$contents = file_get_contents(__DIR__ . '/compress.html');
assert($contents !== false);
$compressData = explode("\n\n", $contents);
$sqlData = $this->sqlData();

$return = [];
foreach ($compressData as $i => $data) {
$return[] = [
$sqlData[$i],
$data,
];
}

return $return;
return $this->fileDataProvider('format.html');
}

/**
* @return mixed[][]
* @return Generator<mixed[]>
*/
public function highlightData() : array
public function compressData() : Generator
{
$contents = file_get_contents(__DIR__ . '/highlight.html');
assert($contents !== false);
$highlightData = explode("\n\n", $contents);
$sqlData = $this->sqlData();

$return = [];
foreach ($highlightData as $i => $data) {
$return[] = [
$sqlData[$i],
$data,
];
}
return $this->fileDataProvider('compress.html');
}

return $return;
/**
* @return Generator<mixed[]>
*/
public function highlightData() : Generator
{
return $this->fileDataProvider('highlight.html');
}

/**
Expand Down