Ejemplo n.º 1
0
<?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');
            });
        });
    });
});
Ejemplo n.º 2
0
<?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);
            });