set('database.default', 'testbench'); $app['config']->set('database.connections.testbench', [ 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'abc-api-testing', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'username' => 'abc-api', 'password' => 'sio2nf0d' ]); } protected function _before() { $this->startApplication(); $db = app()->make('db'); $db->beginTransaction(); $this->withFactories(__DIR__.'/factories'); } protected function _after() { $db = app()->make('db'); $db->rollBack(); $this->stopApplication(); } // tests: trying to... public function testMakeModel() { $tune = factory(TuneSetting::class)->create(); $type = 'Title'; $title = 'a title'; $ordering = 1; $model = new TuneSettingAttribute(); $model->tune_id = $tune->id; $model->type = $type; $model->string = $title; $model->ordering = $ordering; $this->assertInstanceOf(TuneSettingAttribute::class, $model); $this->assertEquals($tune->id, $model->tune_id); $this->assertEquals($type, $model->type); $this->assertEquals($title, $model->string); $this->assertEquals($ordering, $model->ordering); } public function testMassAssignable() { $setting = factory(TuneSetting::class)->create(); $type = 'Notes'; $value = 'a little note'; $ordering = 1; $model = TuneSettingAttribute::create([ 'setting_id' => $setting->id, 'type' => $type, 'string' => $value, 'ordering' => $ordering ]); $this->assertInstanceOf(TuneSettingAttribute::class, $model); $this->assertEquals($setting->id, $model->setting_id); $this->assertEquals($type, $model->type); $this->assertEquals($value, $model->string); $this->assertEquals($ordering, $model->ordering); } public function testFactory() { $model = factory(TuneSettingAttribute::class)->make([]); $this->assertInstanceOf(TuneSettingAttribute::class, $model); $this->assertNotNull($model->setting_id); $this->assertNotNull($model->type); $this->assertNotNull($model->string); $this->assertNotNull($model->ordering); $this->assertTrue($model->save(), json_encode($model->getMessages())); } public function testValidationAppliedOnSave() { $model = factory(TuneSettingAttribute::class)->make([]); $model->type = 'NotType'; $this->assertFalse($model->save()); } public function testTypeValidation() { $model = factory(TuneSettingAttribute::class)->make([]); $model->type = 'NotType'; $this->assertFalse($model->validate()); } public function testTuneSettingIdValidation() { $model = factory(TuneSettingAttribute::class)->make([]); $model->setting_id += 1; $this->assertFalse($model->validate()); } public function testStringValidation() { $longString = ''; for ($i=0; $i < 300; $i++) { $longString .= 's'; } $model = factory(TuneSettingAttribute::class)->make([]); $model->string = $longString; $this->assertFalse($model->validate()); } public function testOrderingValidation() { $model = factory(TuneSettingAttribute::class)->make([]); $model->ordering = "fourth"; $this->assertFalse($model->validate()); } }