<?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; 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'); }); }); }); });
$expected = [['id' => 10, 'name' => 'Taro', 'created' => '2014-01-01 00:00:00'], ['id' => 9, 'name' => 'Taro', 'created' => '2014-01-01 00:00:00'], ['id' => 8, 'name' => 'Taro', 'created' => '2014-01-01 00:00:00']]; expect($actual)->to->equal($expected); }); it('should be enable you to specify logic', function () { $actual = Ayaml::seq($this->container)->range('id', 10, 13)->by(function ($id) { return $id + 2; })->dump(); $expected = [['id' => 10, 'name' => 'Taro', 'created' => '2014-01-01 00:00:00'], ['id' => 12, 'name' => 'Taro', 'created' => '2014-01-01 00:00:00']]; expect($actual)->to->equal($expected); }); }); context('date sequence', function () { it('increment', function () { $actual = Ayaml::seq($this->container)->between('created', '2014-01', '2014-03')->byMonth()->dump(); $expected = [['id' => 1, 'name' => 'Taro', 'created' => '2014-01-01 00:00:00'], ['id' => 1, 'name' => 'Taro', 'created' => '2014-02-01 00:00:00'], ['id' => 1, 'name' => 'Taro', 'created' => '2014-03-01 00:00:00']]; expect($actual)->to->equal($expected); }); it('decrement', function () { $actual = Ayaml::seq($this->container)->between('created', '2014-01', '2013-11')->byMonth()->dump(); $expected = [['id' => 1, 'name' => 'Taro', 'created' => '2014-01-01 00:00:00'], ['id' => 1, 'name' => 'Taro', 'created' => '2013-12-01 00:00:00'], ['id' => 1, 'name' => 'Taro', 'created' => '2013-11-01 00:00:00']]; expect($actual)->to->equal($expected); }); }); context('complex', function () { it('changes num and date', function () { $actual = Ayaml::seq($this->container)->range('id', 10, 12)->byOne()->between('created', '2014-01', '2014-03')->byMonth()->dump(); $expected = [['id' => 10, 'name' => 'Taro', 'created' => '2014-01-01 00:00:00'], ['id' => 11, 'name' => 'Taro', 'created' => '2014-02-01 00:00:00'], ['id' => 12, 'name' => 'Taro', 'created' => '2014-03-01 00:00:00']]; expect($actual)->to->equal($expected); }); }); });
<?php use Ayaml\Ayaml; describe('\\Ayaml\\Sequence\\Calculator\\Datetime\\Decrementer', function () { beforeEach(function () { Ayaml::registerBasePath(__DIR__ . '/../../../../SampleYaml'); $container = Ayaml::file('user')->schema('valid_user'); $this->subject = Ayaml::seq($container); }); context('normal case', function () { it('should be specified duration by Day', function () { $days = $this->subject->between('created', '2014-01-03 00:00:00', '2014-01-01 00:00:00')->byDay()->getAll(); expect($days)->to->an('array')->to->length(3); }); it('should be specified duration by Week', function () { $weeks = $this->subject->between('created', '2014-01-21 00:00:00', '2014-01-01 00:00:00')->byWeek()->getAll(); expect($weeks)->to->an('array')->to->length(3); }); it('should be specified duration by Month', function () { $months = $this->subject->between('created', '2014-03-01 00:00:00', '2014-01-01 00:00:00')->byMonth()->getAll(); expect($months)->to->an('array')->to->length(3); }); it('should be specified duration by Year', function () { $years = $this->subject->between('created', '2016-01-01 00:00:00', '2014-01-01 00:00:00')->byYear()->getAll(); expect($years)->to->an('array')->to->length(3); }); it('should be specified date format', function () { $days = $this->subject->between('created', '2014-01-01 00:00:00', '2014-01-03 00:00:00')->byDay('Y-m-d')->dump(); $expected = [['id' => 1, 'name' => 'Taro', 'created' => '2014-01-01'], ['id' => 1, 'name' => 'Taro', 'created' => '2014-01-02'], ['id' => 1, 'name' => 'Taro', 'created' => '2014-01-03']]; expect($days)->to->equal($expected); });
<?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); });