diff --git a/test/Unit/Format/SnifferTest.php b/test/Unit/Format/SnifferTest.php index 2162e7a9..e7c7e678 100644 --- a/test/Unit/Format/SnifferTest.php +++ b/test/Unit/Format/SnifferTest.php @@ -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) { @@ -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 = <<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 = <<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 *