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' => true, // 'username' => 'abc-api', // 'password' => 'sio2nf0d' // ]); $app['config']->set('database.connections.testbench', [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ]); $app->setBasePath(dirname(dirname(dirname(__DIR__)))); $Artisan = $app->make('Artisan'); $Artisan::call('migrate'); } 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() { $model = new Tune(); $this->assertInstanceOf(Tune::class, $model); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); } public function testMassAssignable() { $xId = 44; $model = Tune::create([ 'x_id' => $xId, ]); $this->assertInstanceOf(Tune::class, $model); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $this->assertEquals($xId, $model->x_id); } public function testFactory() { $model = factory(Tune::class)->make([]); $this->assertInstanceOf(Tune::class, $model); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $this->assertNotNull($model->x_id); } public function testCanGetTitleAttribute() { $title = 'Wombles Forever'; $model = factory(Tune::class)->create([]); $attr = factory(TuneAttribute::class)->create([ 'tune_id' => $model->id, 'type' => 'Title', 'string' => $title, ]); $model = $model->fresh(); $this->assertInstanceOf(Tune::class, $model); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $this->assertEquals($title, $model->T[0]); } public function testSetTitleAttribute() { $titles = ['Title1', 'Womble2']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->T = $titles; $this->assertEquals($titles[0], $model->T[0]); $this->assertEquals($titles[1], $model->T[1]); } public function testTitleAttributeSaves() { $titles = ['Title1', 'Womble2']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->T = $titles; $model->save(); $model = $model->fresh(); $this->assertEquals($titles[0], $model->T[0]); $this->assertEquals($titles[1], $model->T[1]); } public function testCanGetGroupAttribute() { $group = 'Flute'; $model = factory(Tune::class)->create([]); $attr = factory(TuneAttribute::class)->create([ 'tune_id' => $model->id, 'type' => 'Group', 'string' => $group, ]); $model = $model->fresh(); $this->assertInstanceOf(Tune::class, $model); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $this->assertEquals($group, $model->G[0]); } public function testSetGroupAttribute() { $groups = ['Flute', 'Oboe']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->G = $groups; $this->assertEquals($groups[0], $model->G[0]); $this->assertEquals($groups[1], $model->G[1]); } public function testGroupAttributeSaves() { $groups = ['Flute', 'Oboe']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->G = $groups; $model->save(); $model = $model->fresh(); $this->assertEquals($groups[0], $model->G[0]); $this->assertEquals($groups[1], $model->G[1]); } public function testCanGetOriginAttribute() { $origin = 'England'; $model = factory(Tune::class)->create([]); $attr = factory(TuneAttribute::class)->create([ 'tune_id' => $model->id, 'type' => 'Origin', 'string' => $origin, ]); $model = $model->fresh(); $this->assertInstanceOf(Tune::class, $model); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $this->assertEquals($origin, $model->O[0]); } public function testSetOriginAttribute() { $origins = ['England', 'Scotland']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->O = $origins; $this->assertEquals($origins[0], $model->O[0]); $this->assertEquals($origins[1], $model->O[1]); } public function testOriginAttributeSaves() { $origins = ['England', 'Scotland']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->O = $origins; $model->save(); $model = $model->fresh(); $this->assertEquals($origins[0], $model->O[0]); $this->assertEquals($origins[1], $model->O[1]); } public function testCanGetRhythmAttribute() { $rhythm = 'Reel'; $model = factory(Tune::class)->create([]); $attr = factory(TuneAttribute::class)->create([ 'tune_id' => $model->id, 'type' => 'Rhythm', 'string' => $rhythm, ]); $model = $model->fresh(); $this->assertInstanceOf(Tune::class, $model); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $this->assertEquals($rhythm, $model->R[0]); } public function testSetRhythmAttribute() { $rhythms = ['Reel', 'March']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->R = $rhythms; $this->assertEquals($rhythms[0], $model->R[0]); $this->assertEquals($rhythms[1], $model->R[1]); } public function testRhythmAttributeSaves() { $rhythms = ['England', 'Scotland']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->R = $rhythms; $model->save(); $model = $model->fresh(); $this->assertEquals($rhythms[0], $model->R[0]); $this->assertEquals($rhythms[1], $model->R[1]); } public function testCanGetHistoryAttribute() { $history = 'England'; $model = factory(Tune::class)->create([]); $attr = factory(TuneAttribute::class)->create([ 'tune_id' => $model->id, 'type' => 'History', 'string' => $history, ]); $model = $model->fresh(); $this->assertInstanceOf(Tune::class, $model); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $this->assertEquals($history, $model->H[0]); } public function testSetHistoryAttribute() { $history = ['some ', 'lines']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->H = $history; $this->assertEquals($history[0], $model->H[0]); $this->assertEquals($history[1], $model->H[1]); } public function testHistoryAttributeSaved() { $history = ['some ', 'lines']; $model = factory(Tune::class)->create([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->H = $history; $model->save(); $model = $model->fresh(); $this->assertEquals($history[0], $model->H[0]); $this->assertEquals($history[1], $model->H[1]); } public function testValidationAppliedOnSave() { $model = factory(Tune::class)->make([]); $this->assertEmpty($model->getMessages(), json_encode($model->getMessages())); $model->x_id = 'NotType'; $this->assertFalse($model->save()); } }