Пример #1
0
 public function getByClassName($classname, array $config, $id = null)
 {
     $model = new Model(array_merge(['model' => $classname], $config), $this->modelManager->getAbstractionLayer($classname), $this->relationFactory, $this->fieldFactory, $this->generator);
     $model->setSlug($this->slugger->slugify((new ReflectionClass($classname))->getShortName()));
     if (is_null($id)) {
         $model->setInstance($this->modelManager->getModelInstance($classname));
     } else {
         $repository = $this->modelManager->getRepository($classname);
         $model->setInstance($repository->findByOrFail($repository->getModel()->getKeyName(), $id));
     }
     return $model;
 }
Пример #2
0
 public function test_get_form_with_instance()
 {
     $this->generatorMock->shouldReceive('setModelFields', 'setRelatedModelFields')->atLeast()->once();
     $this->generatorMock->shouldReceive('getForm')->atLeast()->once()->andReturn($this->mock('FormManager\\ElementInterface'));
     $this->dbalMock->shouldReceive('getTableColumns')->once()->andReturn(['id' => $this->columnMock, 'username' => $this->columnMock, 'password' => $this->columnMock, 'image' => $this->columnMock]);
     $this->dbalMock->shouldReceive('getTableForeignKeys')->andReturn([]);
     $this->dbalMock->shouldReceive('getModel')->andReturn($this->dbalMock);
     $this->dbalMock->shouldReceive('getKeyName')->andReturn(LaravelModel::CREATED_AT, LaravelModel::UPDATED_AT);
     $this->relationFactoryMock->shouldReceive('setModel')->andReturn($this->relationFactoryMock);
     $this->relationFactoryMock->shouldReceive('setConfig')->andReturn($this->relationFactoryMock);
     $this->relationFactoryMock->shouldReceive('get')->andReturn($relationMock = $this->mock('\\Anavel\\Crud\\Abstractor\\Eloquent\\Relation\\Relation'));
     $relationMock->shouldReceive('getSecondaryRelations')->andReturn(collect());
     $this->fieldFactoryMock->shouldReceive('setColumn', 'setConfig')->andReturn($this->fieldFactoryMock);
     $this->fieldFactoryMock->shouldReceive('get')->andReturn($this->mock('Anavel\\Crud\\Abstractor\\Eloquent\\Field'));
     $modelMock = $this->mock('Illuminate\\Database\\Eloquent\\Model');
     $modelMock->shouldReceive('getAttribute');
     $this->sut->setInstance($modelMock);
     $form = $this->sut->getForm('crudoado.model.store', 'users');
     $this->assertInstanceOf('FormManager\\ElementInterface', $form);
 }