mirror of
https://github.com/composer/composer
synced 2025-05-10 17:12:51 +00:00
parent
16d1b11c26
commit
1c9fbeb978
4 changed files with 58 additions and 8 deletions
|
@ -364,6 +364,29 @@ class JsonFileTest extends TestCase
|
|||
$this->assertEquals($data, $doubleData);
|
||||
}
|
||||
|
||||
public function testPreserveIndentationAfterRead(): void
|
||||
{
|
||||
copy(__DIR__.'/Fixtures/tabs.json', __DIR__.'/Fixtures/tabs2.json');
|
||||
$jsonFile = new JsonFile(__DIR__.'/Fixtures/tabs2.json');
|
||||
$data = $jsonFile->read();
|
||||
$jsonFile->write(['foo' => 'baz']);
|
||||
|
||||
self::assertSame("{\n\t\"foo\": \"baz\"\n}\n", file_get_contents(__DIR__.'/Fixtures/tabs2.json'));
|
||||
|
||||
unlink(__DIR__.'/Fixtures/tabs2.json');
|
||||
}
|
||||
|
||||
public function testOverwritesIndentationByDefault(): void
|
||||
{
|
||||
copy(__DIR__.'/Fixtures/tabs.json', __DIR__.'/Fixtures/tabs2.json');
|
||||
$jsonFile = new JsonFile(__DIR__.'/Fixtures/tabs2.json');
|
||||
$jsonFile->write(['foo' => 'baz']);
|
||||
|
||||
self::assertSame("{\n \"foo\": \"baz\"\n}\n", file_get_contents(__DIR__.'/Fixtures/tabs2.json'));
|
||||
|
||||
unlink(__DIR__.'/Fixtures/tabs2.json');
|
||||
}
|
||||
|
||||
private function expectParseException(string $text, string $json): void
|
||||
{
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue