Skip to content
Permalink
Browse files

Fix empty neon file generation

  • Loading branch information
mabar authored and f3l1x committed Dec 10, 2019
1 parent 831ee0d commit 8a8e5bc31c19285107bf6ee7d260b671f68d7542
@@ -12,7 +12,7 @@ class NeonDecoder implements IDecoder
*/
public function decode(string $value): array
{
return Neon::decode($value);
return Neon::decode($value) ?? [];
}

}
@@ -12,7 +12,7 @@ class NeonEncoder implements IEncoder
*/
public function encode(array $value): ?string
{
return '# ' . IEncoder::GENERATED_MESSAGE . "\n" . Neon::encode($value, Neon::BLOCK);
return '# ' . IEncoder::GENERATED_MESSAGE . "\n" . ($value !== [] ? Neon::encode($value, Neon::BLOCK) : '');
}

}
@@ -77,6 +77,24 @@ class TaskProcessTest extends TestCase
self::assertFiles(__DIR__ . '/../fixtures/files/interactive.json', $generatedFile);
}

public function testEmptyFile(): void
{
/** @var IOInterface $io */
$io = Mockery::mock(IOInterface::class);

$io->shouldReceive('write')
->times(1);

$processor = new TaskProcess($io);

$generatedFile = TEMP_DIR . '/empty.neon';
$processor->process(new FileConfig([
'dist-file' => __DIR__ . '/../fixtures/files/empty.neon',
'file' => $generatedFile,
]));
self::assertFiles(__DIR__ . '/../fixtures/files/empty.neon', $generatedFile);
}

private static function assertFiles(string $expected, string $actual): void
{
Assert::same(file_get_contents($expected), file_get_contents($actual));
@@ -0,0 +1 @@
# This file is auto-generated by composer

0 comments on commit 8a8e5bc

Please sign in to comment.
You can’t perform that action at this time.