Ejemplo n.º 1
0
 /** @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);
 }
Ejemplo n.º 2
0
 /**
  * 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]));
     }
 }
Ejemplo n.º 3
0
 /**
  * Build the schema.
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function build()
 {
     return $this->entity->attributes()->saveMany($this->attributes);
 }
Ejemplo n.º 4
0
 /**
  * Open a connection to the entity.
  *
  * @param  string  $table
  * @return Entity
  */
 private function openConnection(string $table)
 {
     return Entity::byName($table);
 }
Ejemplo n.º 5
0
 /**
  * Create or find the given entity.
  */
 private function createEntity(string $name)
 {
     return Entity::firstOrCreate(['name' => $name]);
 }