<?php use Ayaml\Ayaml; describe('\\Ayaml\\Ayaml', function () { context('file', function () { context('normal case', function () { beforeEach(function () { Ayaml::registerBasePath(__DIR__ . '/../SampleYaml'); }); it('should return Container class', function () { expect(Ayaml::file('user.yml'))->to->instanceof('\\Ayaml\\Container'); }); it('should return Container class with adding file extension', function () { expect(Ayaml::file('user'))->to->instanceof('\\Ayaml\\Container'); }); it('should return Container class with detecting .yaml extension', function () { expect(Ayaml::file('a.yaml'))->to->instanceof('\\Ayaml\\Container'); }); }); context('abnormal case', function () { it('should throw when base path is not registered', function () { expect(function () { $reflection = new \ReflectionProperty('\\Ayaml\\Ayaml', 'basePaths'); $reflection->setAccessible(true); $reflection->setValue([]); Ayaml::file('user'); })->to->throw('\\Ayaml\\AyamlBasePathNotFoundException'); }); }); }); });
<?php use Ayaml\Ayaml; use Ayaml\ContainerCollection; describe('\\Ayaml\\ContainerCollection', function () { beforeEach(function () { Ayaml::registerBasePath(__DIR__ . '/../SampleYaml'); $container = Ayaml::file('user')->schema('valid_user'); $this->containerCollection = new ContainerCollection($container); }); context('range', function () { context('abnormal case', function () { it('should throw with invalid type', function () { expect(function () { $this->containerCollection->range('foo', 'string', 'string'); })->to->throw('\\Ayaml\\AyamlSeqInvalidTypeException'); }); }); }); context('between', function () { context('abnormal case', function () { it('should throw with invalid type', function () { expect(function () { $this->containerCollection->between('foo', 'invalid string', 'invalid string'); })->to->throw('\\Ayaml\\AyamlSeqInvalidTypeException'); }); }); }); });
<?php use Ayaml\Ayaml; use Ayaml\Fixture\YamlData; use Symfony\Component\Yaml\Yaml as SymfonyYaml; describe('\\Ayaml\\Fixture\\YamlData', function () { context('load', function () { beforeEach(function () { Ayaml::registerBasePath(__DIR__ . '/../../SampleYaml'); Ayaml::registerBasePath(__DIR__ . '/../../SampleYaml/AnotherPath'); }); it('should load multiple paths', function () { expect(Ayaml::file('another_path'))->to->be->instanceof('\\Ayaml\\Container'); }); afterEach(function () { $reflection = new \ReflectionProperty('\\Ayaml\\Ayaml', 'basePaths'); $reflection->setAccessible(true); $reflection->setValue([]); }); }); context('getSchema', function () { context('normal case', function () { 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); });