Example #1
0
 /**
  * Create a fake model instance and save it in the database
  * 
  * @param string $class 
  * @return object
  */
 public function create($class)
 {
     $blueprint = $this->makeBlueprint($class);
     // make and save model
     $model = $this->makeFromBlueprint($blueprint);
     // movel to model
     $model = $this->model->saveModel($model, $blueprint);
     return $model;
 }
 public function testGetAttributesForClass()
 {
     $databaseManager = Mockery::mock('Skovachev\\Fakefactory\\Model\\DatabaseManager');
     $databaseManager->shouldReceive('registerTypeMapping')->once()->with('enum', 'string');
     $databaseManager->shouldReceive('listTableColumnsAsArray')->once()->with('table')->andReturn(array('foo' => 'bar'));
     $model = Mockery::mock();
     $model->shouldReceive('getTable')->andReturn('table');
     $reflector = Mockery::mock('Skovachev\\Fakefactory\\Model\\Reflector');
     $reflector->shouldReceive('instantiate')->with('foo')->andReturn($model);
     $manager = new ModelManager($databaseManager, $reflector);
     $manager->clearCachedFieldData();
     $attributes = $manager->getAttributesForClass('foo');
     $this->assertCount(1, $attributes);
     $this->assertInstanceOf('Skovachev\\Fakefactory\\Model\\Blueprint\\Attribute', $attributes[0]);
     $this->assertEquals($attributes[0]->getName(), 'foo');
     $this->assertEquals($attributes[0]->getType(), 'bar');
 }