files = vfsStream::setup(); } /** * @dataProvider file_is_handled_properly_data_provider */ public function test_file_is_handled_properly(string $filename, string $content): void { $file = (vfsStream::newFile($filename))->withContent($content)->at($this->files); $source = new FileSource(new SplFileObject($file->url())); self::assertSame(['foo' => 'bar'], iterator_to_array($source)); self::assertSame($file->url(), $source->sourceName()); } public function file_is_handled_properly_data_provider(): iterable { yield ['test-json.json', '{"foo": "bar"}']; yield ['test-json.JSON', '{"foo": "bar"}']; if (function_exists('yaml_parse')) { yield ['test-yaml.yaml', 'foo: bar']; yield ['test-yaml.YAML', 'foo: bar']; yield ['test-yml.yml', 'foo: bar']; yield ['test-yml.YML', 'foo: bar']; } } public function test_unhandled_extension_throws_exception(): void { $this->expectException(FileExtensionNotHandled::class); $this->expectExceptionCode(1629991744); $this->expectExceptionMessage('The file extension `foo` is not handled.'); $file = (vfsStream::newFile('some-unhandled-extension.foo')) ->withContent('foo') ->at($this->files); new FileSource(new SplFileObject($file->url())); } public function test_unreadable_file_throws_exception(): void { $file = (vfsStream::newFile('some-file.json')) ->withContent('{"foo": "bar"}') ->at($this->files); $fileObject = new SplFileObject($file->url()); $file->chmod(0000); $this->expectException(UnableToReadFile::class); $this->expectExceptionCode(1629993117); $this->expectExceptionMessage("Unable to read the file `{$file->url()}`."); new FileSource($fileObject); } }