$schema = $model::definition(); $schema->column('hello_boy', ['getter' => function ($entity, $data, $name) { return 'Hi Boy!'; }]); $entity = $model::create(); expect($entity->hello_boy)->toBe('Hi Boy!'); }); context("when a model is defined", function () { beforeEach(function () { $this->model = Double::classname(['extends' => $this->model]); }); it("autoboxes setted data", function () { $model = $this->model; $childEntity = Double::classname(['extends' => $this->model]); $childEntity::definition()->locked(false); $schema = new Schema(['model' => $model]); $schema->column('child', ['type' => 'object', 'model' => $childEntity]); $model::definition($schema); $entity = $model::create(); $entity['child'] = ['id' => 1, 'title' => 'child record', 'enabled' => true]; $child = $entity['child']; expect($child)->toBeAnInstanceOf($childEntity); expect($child->parents()->get($entity))->toBe('child'); expect($child->basePath())->toBe('child'); }); }); }); describe("->validates()", function () { beforeEach(function () { $validator = Gallery::validator(); $validator->rule('name', 'not:empty');
}); }); describe("->basePath()", function () { it("returns the root path", function () { $document = new Document(['basePath' => 'items']); expect($document->basePath())->toBe('items'); }); }); describe("->get()", function () { it("gets a value", function () { $document = new Document(); expect($document->set('title', 'Hello'))->toBe($document); expect($document->get('title'))->toBe('Hello'); }); it("gets a virtual value", function () { $schema = new Schema(); $schema->column('a', ['type' => 'string', 'virtual' => true]); $document = new Document(['schema' => $schema]); $document['a'] = 1; expect($document->get('a'))->toBe('1'); }); it("gets all values", function () { $document = new Document(); $document->set(['a' => 1, 'b' => 2, 'c' => 3]); expect($document->get())->toBe(['a' => 1, 'b' => 2, 'c' => 3]); }); }); describe("->set()", function () { it("sets values", function () { $date = new DateTime('2014-10-26 00:25:15'); $document = new Document();
describe("->unbind()", function () { it("unbinds a relation", function () { expect($this->schema->hasRelation('gallery'))->toBe(true); $this->schema->unbind('gallery'); expect($this->schema->hasRelation('gallery'))->toBe(false); }); }); describe("->relations", function () { it("returns all relation names", function () { $relations = $this->schema->relations(); sort($relations); expect($relations)->toBe(['gallery', 'images_tags', 'tags']); }); it("includes embedded relations using `true` as first parameter", function () { $model = Stub::classname(['extends' => Model::class]); $schema = new Schema(['model' => $model]); $schema->set('embedded', ['type' => 'object', 'model' => $model]); expect($schema->relations())->toBe(['embedded']); expect($schema->relations(false))->toBe([]); }); }); describe("->conventions()", function () { it("gets/sets the conventions", function () { $conventions = Stub::create(); $schema = new Schema(); expect($schema->conventions($conventions))->toBe($schema); expect($schema->conventions())->toBe($conventions); }); }); describe("->expand()", function () { it("expands schema paths", function () {
describe("->unbind()", function () { it("unbinds a relation", function () { expect($this->schema->hasRelation('gallery'))->toBe(true); $this->schema->unbind('gallery'); expect($this->schema->hasRelation('gallery'))->toBe(false); }); }); describe("->relations", function () { it("returns all relation names", function () { $relations = $this->schema->relations(); sort($relations); expect($relations)->toBe(['gallery', 'images_tags', 'tags']); }); it("includes embedded relations using `true` as first parameter", function () { $model = Double::classname(['extends' => Model::class]); $schema = new Schema(['model' => $model]); $schema->column('embedded', ['type' => 'object', 'model' => $model]); expect($schema->relations())->toBe([]); expect($schema->relations(true))->toBe(['embedded']); }); }); describe("->conventions()", function () { it("gets/sets the conventions", function () { $conventions = Double::instance(); $schema = new Schema(); expect($schema->conventions($conventions))->toBe($schema); expect($schema->conventions())->toBe($conventions); }); }); describe("->expand()", function () { it("expands schema paths", function () {