Пример #1
0
 public function test_returns_relations_as_multidimensional_collection()
 {
     $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(['chompy' => $relationMock]));
     $relations = $this->sut->getRelations();
     $this->assertInstanceOf('Illuminate\\Support\\Collection', $relations);
     foreach ($relations as $relation) {
         $this->assertInstanceOf('Illuminate\\Support\\Collection', $relation);
         $this->assertArrayHasKey('relation', $relation);
         $this->assertArrayHasKey('secondaryRelations', $relation);
         $this->assertInstanceOf('Illuminate\\Support\\Collection', $relation->get('secondaryRelations'));
         foreach ($relation->get('secondaryRelations') as $secondaryRelation) {
             $this->assertInstanceOf('Anavel\\Crud\\Contracts\\Abstractor\\Relation', $secondaryRelation);
         }
     }
 }
Пример #2
0
 protected function getNestedRelation(Model $modelAbstractor, $relationName)
 {
     $relations = $modelAbstractor->getRelations();
     if (!$relations->has($relationName)) {
         throw new AbstractorException('Relation ' . $relationName . ' not configured on ' . $modelAbstractor->getModel());
     }
     $relation = $relations->get($relationName);
     if ($relation instanceof Relation) {
         return $relation;
     } else {
         return $relation['relation'];
     }
 }