/** @test **/ public function it_fetches_the_attribute_of_the_entity() { $this->createPostsTable(); $entity = Entity::byName('posts'); $attribute = $entity->attribute('title'); $this->assertEquals('title', $attribute->name); }
/** * Create a new model through eloquent model for mocking. * * @param string $table * @param array $values * @return void */ public function insertOn(string $table, array $attributes = []) { $entity = Entity::where('name', $table)->first(); if (!$entity) { $entity = Entity::create(['name' => $table]); } $object = $entity->objects()->save(new Object()); foreach ($attributes as $field => $value) { $attribute = $entity->attributes()->where(['name' => $field])->first(); if (!$attribute) { $attribute = $entity->attributes()->save(new Attribute(['name' => $field])); } $object->values()->save(new Value(['content' => $value, 'attribute_id' => $attribute->id])); } }
/** * Build the schema. * * @return \Illuminate\Database\Eloquent\Collection */ public function build() { return $this->entity->attributes()->saveMany($this->attributes); }
/** * Open a connection to the entity. * * @param string $table * @return Entity */ private function openConnection(string $table) { return Entity::byName($table); }
/** * Create or find the given entity. */ private function createEntity(string $name) { return Entity::firstOrCreate(['name' => $name]); }