/** * Generates fake relations based on the current blueprint * * @param array $overrides * @return array */ public function fakeRelations($overrides = array()) { $relationships = array(); foreach ($this->blueprint->getRelations() as $relation) { $relatedObject = FakeFactory::make($relation->getRelatedClassName(), array_get($overrides, $relation->getName(), array())); $relationships[$relation->getName()] = $relation->isToManyRelation() ? array($relatedObject) : $relatedObject; } return $relationships; }
public function testFakeRelationsIsToManyWrapsClassFakesInArray() { $faker = $this->getFaker(); $blueprint = Mockery::mock('Skovachev\\Fakefactory\\Model\\Blueprint\\Blueprint'); $relation = Mockery::mock('Skovachev\\Fakefactory\\Model\\Blueprint\\Relation'); $relations = array($relation); $relationName = 'relName'; $relatedClassName = 'foobar'; $overrides = array(); $overrides[$relationName] = 'baz'; FakeFactory::shouldReceive('make')->with($relatedClassName, $overrides[$relationName])->once()->andReturn('classFake'); $relation->shouldReceive('getRelatedClassName')->andReturn($relatedClassName); $relation->shouldReceive('getName')->andReturn($relationName); $relation->shouldReceive('isToManyRelation')->andReturn(true); $blueprint->shouldReceive('getAttributes')->andReturn(array()); $blueprint->shouldReceive('getRelations')->andReturn($relations); $faker->setClassBlueprint($blueprint); $relations = $faker->fakeRelations($overrides); $this->assertEquals($relations, array('relName' => array('classFake'))); }