Skip to content

Commit

Permalink
Enhancement: Assert that sniffer sniffs only pure indents
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Aug 12, 2018
1 parent 26a61ff commit 724a061
Showing 1 changed file with 51 additions and 15 deletions.
66 changes: 51 additions & 15 deletions test/Unit/Format/SnifferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function providerJsonWithoutWhitespace(): \Generator
'object-empty' => '{}',
'object-without-indent' => '{"foo":"bar baz","baz":[9000,123]}',
'string' => '"foo"',
'string-blank' => '" "',
];

foreach ($values as $key => $value) {
Expand All @@ -132,11 +133,13 @@ public function providerJsonWithoutWhitespace(): \Generator
}

/**
* @dataProvider providerIndent
* @dataProvider providerPureIndentAndSniffedIndent
* @dataProvider providerMixedIndentAndSniffedIndent
*
* @param string $indent
* @param string $sniffedIndent
*/
public function testSniffReturnsFormatWithIndentSniffedFromArray(string $indent): void
public function testSniffReturnsFormatWithIndentSniffedFromArray(string $indent, string $sniffedIndent): void
{
$json = <<<JSON
[
Expand All @@ -153,15 +156,17 @@ public function testSniffReturnsFormatWithIndentSniffedFromArray(string $indent)
$format = $sniffer->sniff($json);

$this->assertInstanceOf(FormatInterface::class, $format);
$this->assertSame($indent, $format->indent());
$this->assertSame($sniffedIndent, $format->indent());
}

/**
* @dataProvider providerIndent
* @dataProvider providerPureIndentAndSniffedIndent
* @dataProvider providerMixedIndentAndSniffedIndent
*
* @param string $indent
* @param string $sniffedIndent
*/
public function testSniffReturnsFormatWithIndentSniffedFromObject(string $indent): void
public function testSniffReturnsFormatWithIndentSniffedFromObject(string $indent, string $sniffedIndent): void
{
$json = <<<JSON
{
Expand All @@ -178,29 +183,60 @@ public function testSniffReturnsFormatWithIndentSniffedFromObject(string $indent
$format = $sniffer->sniff($json);

$this->assertInstanceOf(FormatInterface::class, $format);
$this->assertSame($indent, $format->indent());
$this->assertSame($sniffedIndent, $format->indent());
}

public function providerIndent(): \Generator
public function providerPureIndentAndSniffedIndent(): \Generator
{
$characters = [
' ',
"\t",
'space' => ' ',
'tab' => "\t",
];

$counts = [1, 3];
$sizes = [1, 3];

foreach ($characters as $character) {
foreach ($counts as $count) {
$indent = \str_repeat($character, $count);
foreach ($characters as $style => $character) {
foreach ($sizes as $size) {
$key = \sprintf(
'%s-%d',
$style,
$size
);

yield [
$indent,
$pureIndent = \str_repeat(
$character,
$size
);

yield $key => [
$pureIndent,
$pureIndent,
];
}
}
}

public function providerMixedIndentAndSniffedIndent(): \Generator
{
$mixedIndents = [
'space-and-tab' => [
" \t",
' ',
],
'tab-and-space' => [
"\t ",
"\t",
],
];

foreach ($mixedIndents as $key => [$mixedIndent, $sniffedIndent]) {
yield $key => [
$mixedIndent,
$sniffedIndent,
];
}
}

/**
* @dataProvider providerJsonWithoutWhitespace
*
Expand Down

0 comments on commit 724a061

Please sign in to comment.