Пример #1
0
<?php

use Bravesheep\Dogmatist\Exception\BuilderException;
use Bravesheep\Dogmatist\Exception\NoSuchIndexException;
use Bravesheep\Dogmatist\Exception\SampleException;
use Bravesheep\Dogmatist\Factory;
describe("Dogmatist", function () {
    beforeEach(function () {
        $this->dogmatist = Factory::create();
    });
    it("should be able to create builders", function () {
        $builder = $this->dogmatist->create('object');
        expect($builder)->toBeAnInstanceOf('Bravesheep\\Dogmatist\\Builder');
    });
    it("should retrieve the link manager", function () {
        expect($this->dogmatist->getLinkManager())->toBeAnInstanceOf('Bravesheep\\Dogmatist\\LinkManager');
    });
    it("should retrieve the sampler", function () {
        expect($this->dogmatist->getSampler())->toBeAnInstanceOf('Bravesheep\\Dogmatist\\Sampler');
    });
    it("should retrieve the guesser", function () {
        expect($this->dogmatist->getGuesser())->toBeAnInstanceOf('Bravesheep\\Dogmatist\\Guesser\\GuesserInterface');
    });
    it("should retrieve the faker instance", function () {
        expect($this->dogmatist->getFaker())->toBeAnInstanceOf('Faker\\Generator');
    });
    describe("working with saved builders", function () {
        beforeEach(function () {
            $this->builder = $this->dogmatist->create('object')->fake('example', 'name')->save('example', 1);
        });
        it("should create a sample from a saved builder", function () {
Пример #2
0
<?php

use Bravesheep\Dogmatist\Exception\InvalidArgumentException;
use Bravesheep\Dogmatist\Factory;
describe("Factory", function () {
    it("creates an instance of Dogmatist", function () {
        expect(Factory::create())->toBeAnInstanceOf('Bravesheep\\Dogmatist\\Dogmatist');
    });
    it("should fail for invalid values of faker", function () {
        $task = function () {
            Factory::create(22);
        };
        expect($task)->toThrow(new InvalidArgumentException());
    });
});
<?php

use Bravesheep\Dogmatist\Factory;
use Bravesheep\Dogmatist\Field;
use Bravesheep\Dogmatist\Guesser\AnnotationGuesser;
describe("AnnotationGuesser", function () {
    beforeEach(function () {
        $this->filler = new AnnotationGuesser();
        $this->dogmatist = Factory::create(\Faker\Factory::DEFAULT_LOCALE, $this->filler);
    });
    it("should be inserted in dogmatist", function () {
        expect($this->dogmatist->getGuesser())->toBe($this->filler);
    });
    it("should create the properties for the constructor", function () {
        $builder = $this->dogmatist->create('Bravesheep\\Spec\\Annotated\\WithConstructorTest');
        expect($builder->getClass())->toBe('Bravesheep\\Spec\\Annotated\\WithConstructorTest');
        expect($builder->hasConstructor())->toBe(true);
        $constructor = $builder->constructor();
        expect($constructor->getFields())->toHaveLength(2);
        expect($constructor->isPositional())->toBe(true);
        expect($constructor->get(0)->getType())->toBe(Field::TYPE_LINK);
        expect($constructor->get(1)->getType())->toBe(Field::TYPE_FAKE);
        expect($constructor->get(0)->getLinkTarget())->toBe('another');
        expect($constructor->get(1)->getFakedType())->toBe('randomNumber');
    });
    it("should set up a relation", function () {
        $builder = $this->dogmatist->create('Bravesheep\\Spec\\Annotated\\RelationFieldTest');
        expect($builder->get('relation')->getType())->toBe(Field::TYPE_RELATION);
        expect($builder->get('relation')->getRelated()->hasConstructor())->toBe(false);
    });
    it("should set up a relation with a constructor", function () {
Пример #4
0
<?php

use Bravesheep\Dogmatist\Builder;
use Bravesheep\Dogmatist\Exception\BuilderException;
use Bravesheep\Dogmatist\Factory;
use Bravesheep\Dogmatist\Field;
use Bravesheep\Dogmatist\Guesser\NoneGuesser;
describe("Builder", function () {
    beforeEach(function () {
        $this->dogmatist = Factory::create(\Faker\Factory::DEFAULT_LOCALE, new NoneGuesser());
        $this->builder = new Builder('object', $this->dogmatist);
    });
    it("should have a field defined", function () {
        $this->builder->fake('example', 'number');
        expect($this->builder->has('example'))->toBe(true);
    });
    it("should create a faked field", function () {
        $this->builder->fake('example', 'number');
        $field = $this->builder->get('example');
        expect($field->getType())->toBe(Field::TYPE_FAKE);
        expect($field->isType(Field::TYPE_FAKE))->toBe(true);
        expect($field->getName())->toBe('example');
        expect($field->getFakedOptions())->toBe([]);
        expect($field->getFakedType())->toBe('number');
    });
    it("should update a field to none", function () {
        $this->builder->fake('example', 'number');
        $this->builder->none('example');
        $field = $this->builder->get('example');
        expect($field->getType())->toBe(Field::TYPE_NONE);
        expect($field->isType(Field::TYPE_NONE))->toBe(true);