/** * Persist the entity and any relationships. * * @param string $name * @param array $attributes * @return mixed */ protected function persist($name, array $attributes = []) { $entity = $this->build($name, $attributes); $this->assignRelationships($entity, $attributes); $this->model->save($entity); return $entity; }
function it_can_create_multiple_entities_at_once(IsPersistable $model) { $stub = new AlbumStub(); $model->getAttributes(Argument::any())->willReturn([]); $model->build('Album', Argument::type('array'))->shouldBeCalledTimes(3)->willReturn($stub); $model->save($stub)->shouldBeCalledTimes(3); $collection = $this->setTimes(3)->create('Album'); $collection[0]->shouldEqual($stub); $collection[1]->shouldEqual($stub); $collection[2]->shouldEqual($stub); }