Skip to content

Commit

Permalink
Test with indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 31, 2024
1 parent faa8abd commit 54d89d3
Showing 1 changed file with 76 additions and 28 deletions.
104 changes: 76 additions & 28 deletions tests/ExporterTest.php
Expand Up @@ -65,23 +65,23 @@ public static function exportProvider(): array
fclose($resource);

return [
'null' => [null, 'null'],
'boolean true' => [true, 'true'],
'boolean false' => [false, 'false'],
'int 1' => [1, '1'],
'float 1.0' => [1.0, '1.0'],
'float 1.2' => [1.2, '1.2'],
'float 1 / 3' => [1 / 3, '0.3333333333333333'],
'float 1 - 2 / 3' => [1 - 2 / 3, '0.33333333333333337'],
'float 5.5E+123' => [5.5E+123, '5.5E+123'],
'float 5.5E-123' => [5.5E-123, '5.5E-123'],
'float NAN' => [NAN, 'NAN'],
'float INF' => [INF, 'INF'],
'float -INF' => [-INF, '-INF'],
'stream' => [fopen('php://memory', 'r'), 'resource(%d) of type (stream)'],
'stream (closed)' => [$resource, 'resource (closed)'],
'numeric string' => ['1', "'1'"],
'multidimensional array' => [[[1, 2, 3], [3, 4, 5]],
'null' => [null, 'null', 0],
'boolean true' => [true, 'true', 0],
'boolean false' => [false, 'false', 0],
'int 1' => [1, '1', 0],
'float 1.0' => [1.0, '1.0', 0],
'float 1.2' => [1.2, '1.2', 0],
'float 1 / 3' => [1 / 3, '0.3333333333333333', 0],
'float 1 - 2 / 3' => [1 - 2 / 3, '0.33333333333333337', 0],
'float 5.5E+123' => [5.5E+123, '5.5E+123', 0],
'float 5.5E-123' => [5.5E-123, '5.5E-123', 0],
'float NAN' => [NAN, 'NAN', 0],
'float INF' => [INF, 'INF', 0],
'float -INF' => [-INF, '-INF', 0],
'stream' => [fopen('php://memory', 'r'), 'resource(%d) of type (stream)', 0],
'stream (closed)' => [$resource, 'resource (closed)', 0],
'numeric string' => ['1', "'1'", 0],
'multidimensional array (indentation=0)' => [[[1, 2, 3], [3, 4, 5]],
<<<'EOF'
Array &0 [
0 => Array &1 [
Expand All @@ -95,7 +95,42 @@ public static function exportProvider(): array
2 => 5,
],
]
EOF
EOF,
0,
],
'multidimensional array (indentation=1)' => [[[1, 2, 3], [3, 4, 5]],
<<<'EOF'
Array &0 [
0 => Array &1 [
0 => 1,
1 => 2,
2 => 3,
],
1 => Array &2 [
0 => 3,
1 => 4,
2 => 5,
],
]
EOF,
1,
],
'multidimensional array (indentation=2)' => [[[1, 2, 3], [3, 4, 5]],
<<<'EOF'
Array &0 [
0 => Array &1 [
0 => 1,
1 => 2,
2 => 3,
],
1 => Array &2 [
0 => 3,
1 => 4,
2 => 5,
],
]
EOF,
2,
],
// \n\r and \r is converted to \n
'export multiline text' => ["this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext",
Expand All @@ -111,9 +146,10 @@ public static function exportProvider(): array
very\r
long\n\r
text'
EOF
EOF,
0,
],
'empty stdclass' => [new stdClass, 'stdClass Object #%d ()'],
'empty stdclass' => [new stdClass, 'stdClass Object #%d ()', 0],
'non empty stdclass' => [$obj,
<<<'EOF'
stdClass Object #%d (
Expand Down Expand Up @@ -142,9 +178,10 @@ public static function exportProvider(): array
],
'self' => stdClass Object #%d,
)
EOF
EOF,
0,
],
'empty array' => [[], 'Array &%d []'],
'empty array' => [[], 'Array &%d []', 0],
'splObjectStorage' => [$storage,
<<<'EOF'
SplObjectStorage Object #%d (
Expand All @@ -155,7 +192,8 @@ public static function exportProvider(): array
'inf' => null,
],
)
EOF
EOF,
0,
],
'stdClass with numeric properties' => [$obj3,
<<<'EOF'
Expand All @@ -170,23 +208,28 @@ public static function exportProvider(): array
6 => 7,
7 => 8,
)
EOF
EOF,
0,
],
[
chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5),
'Binary String: 0x000102030405',
0,
],
[
implode('', array_map('chr', range(0x0E, 0x1F))),
'Binary String: 0x0e0f101112131415161718191a1b1c1d1e1f',
0,
],
[
chr(0x00) . chr(0x09),
'Binary String: 0x0009',
0,
],
[
'',
"''",
0,
],
'Exception without trace' => [
new Exception('The exception message', 42),
Expand All @@ -199,7 +242,8 @@ public static function exportProvider(): array
'line' => %d,
'previous' => null,
)
EOF
EOF,
0,
],
'Error without trace' => [
new Error('The exception message', 42),
Expand All @@ -212,19 +256,23 @@ public static function exportProvider(): array
'line' => %d,
'previous' => null,
)
EOF
EOF,
0,
],
'enum' => [
ExampleEnum::Value,
'SebastianBergmann\Exporter\ExampleEnum Enum #%d (Value)',
0,
],
'backed enum (string)' => [
ExampleStringBackedEnum::Value,
'SebastianBergmann\Exporter\ExampleStringBackedEnum Enum #%d (Value, \'value\')',
0,
],
'backed enum (integer)' => [
ExampleIntegerBackedEnum::Value,
'SebastianBergmann\Exporter\ExampleIntegerBackedEnum Enum #%d (Value, 0)',
0,
],
];
}
Expand Down Expand Up @@ -286,11 +334,11 @@ public static function shortenedRecursiveExportProvider(): array
}

#[DataProvider('exportProvider')]
public function testExport(mixed $value, string $expected): void
public function testExport(mixed $value, string $expected, int $indentation): void
{
$this->assertStringMatchesFormat(
$expected,
$this->trimNewline((new Exporter)->export($value)),
$this->trimNewline((new Exporter)->export($value, $indentation)),
);
}

Expand Down

0 comments on commit 54d89d3

Please sign in to comment.