/** * @param string $name * @return $this * @throws AyamlSchemaNotFoundException */ public function schema($name) { $this->resultData = $this->yamlData->getSchema($name); return $this; }
beforeEach(function () { $data = SymfonyYaml::parse(file_get_contents(__DIR__ . '/../../SampleYaml/user.yml', SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE)); $this->yamlData = new YamlData($data); }); it('should get schema correctly', function () { $validUser = $this->yamlData->getSchema('valid_user'); $expected = ['id' => 1, 'name' => 'Taro', 'created' => '2014-01-01 00:00:00']; expect($validUser)->to->equal($expected); }); it('should get nested data', function () { $nested = $this->yamlData->getSchema('nested.1.2.3.4.data'); $expected = ['id' => 2, 'name' => 'Jiro', 'created' => '2014-01-01 00:00:00']; expect($nested)->to->equal($expected); }); }); context('abnormal case', function () { it('should throw when file not found', function () { expect(function () { YamlData::load(['invalid path'], 'invalid file'); })->to->throw('\\Ayaml\\Fixture\\AyamlFixtureFileNotFoundException'); }); it('should throw when schema not found', function () { expect(function () { $data = SymfonyYaml::parse(file_get_contents(__DIR__ . '/../../SampleYaml/user.yml', SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE)); $yamlData = new YamlData($data); $yamlData->getSchema('no existing schema'); })->to->throw('\\Ayaml\\Fixture\\AyamlSchemaNotFoundException'); }); }); }); });