function it_can_create_multiple_entities_at_once(BuildableRepositoryInterface $builderRepository)
 {
     $stub = new AlbumStub();
     $builderRepository->build(Argument::type('string'), Argument::type('array'))->shouldBeCalledTimes(3)->willReturn($stub);
     $builderRepository->save($stub)->shouldBeCalledTimes(3);
     $this->setTimes(3)->create('Album')->shouldReturn([$stub, $stub, $stub]);
 }
Example #2
0
 /**
  * Persist the entity and any relationships.
  *
  * @param string $type
  * @param array  $fields
  * @return mixed
  */
 protected function persist($type, array $fields = [])
 {
     $entity = $this->build($type, $fields);
     // We'll filter through all of the columns, and check
     // to see if there are any defined relationships. If there
     // are, then we'll need to create those records as well
     foreach ($entity->getAttributes() as $column => $value) {
         if ($this->hasRelationshipAttribute($column, $value)) {
             $entity[$column] = $this->fetchRelationshipId($value['type']);
         }
     }
     $this->database->save($entity);
     return $entity;
 }