Beispiel #1
0
 /**
  * Seed test data
  */
 public function create_data()
 {
     // bear 1 is named Lawly. She is extremely dangerous. Especially when hungry.
     $bear_lawly = bear::create(['name' => 'Lawly', 'type' => 'Grizzly', 'danger_level' => 8]);
     // bear 2 is named Cerms. He has a loud growl but is pretty much harmless.
     $bear_cerms = bear::create(['name' => 'Cerms', 'type' => 'Black', 'danger_level' => 4]);
     // bear 3 is named Adobot. He is a polar bear.
     $bear_adobot = bear::create(['name' => 'Adobot', 'type' => 'Polar', 'danger_level' => 3]);
     $this->assertInternalType('object', $bear_lawly);
     $this->assertInstanceOf('yf_model_result', $bear_lawly);
     $this->assertInstanceOf('yf_model', $bear_lawly->_get_model());
     $this->assertInstanceOf('bear', $bear_lawly->_get_model());
     $this->assertObjectHasAttribute('id', $bear_lawly);
     $this->assertObjectHasAttribute('name', $bear_lawly);
     $this->assertObjectHasAttribute('type', $bear_lawly);
     $this->assertObjectHasAttribute('danger_level', $bear_lawly);
     $this->assertSame('Lawly', $bear_lawly->name);
     $this->assertSame('Grizzly', $bear_lawly->type);
     $this->assertEquals('8', $bear_lawly->danger_level);
     $this->assertInternalType('object', $bear_cerms);
     $this->assertInstanceOf('yf_model_result', $bear_cerms);
     $this->assertInstanceOf('yf_model', $bear_cerms->_get_model());
     $this->assertInstanceOf('bear', $bear_cerms->_get_model());
     $this->assertObjectHasAttribute('id', $bear_cerms);
     $this->assertObjectHasAttribute('name', $bear_cerms);
     $this->assertObjectHasAttribute('type', $bear_cerms);
     $this->assertObjectHasAttribute('danger_level', $bear_cerms);
     $this->assertSame('Cerms', $bear_cerms->name);
     $this->assertSame('Black', $bear_cerms->type);
     $this->assertEquals('4', $bear_cerms->danger_level);
     $this->assertInternalType('object', $bear_adobot);
     $this->assertInstanceOf('yf_model_result', $bear_adobot);
     $this->assertInstanceOf('yf_model', $bear_adobot->_get_model());
     $this->assertInstanceOf('bear', $bear_adobot->_get_model());
     $this->assertObjectHasAttribute('id', $bear_adobot);
     $this->assertObjectHasAttribute('name', $bear_adobot);
     $this->assertObjectHasAttribute('type', $bear_adobot);
     $this->assertObjectHasAttribute('danger_level', $bear_adobot);
     $this->assertSame('Adobot', $bear_adobot->name);
     $this->assertSame('Polar', $bear_adobot->type);
     $this->assertEquals('3', $bear_adobot->danger_level);
     // seed our fish table. our fish wont have names... because theyre going to be eaten
     // we will use the variables we used to create the bears to get their id
     $fish1 = fish::create(['weight' => '5', 'bear_id' => $bear_lawly->id]);
     $fish2 = fish::create(['weight' => '12', 'bear_id' => $bear_cerms->id]);
     $fish3 = fish::create(['weight' => '4', 'bear_id' => $bear_adobot->id]);
     $this->assertInternalType('object', $fish1);
     $this->assertInstanceOf('yf_model_result', $fish1);
     $this->assertInstanceOf('yf_model', $fish1->_get_model());
     $this->assertInstanceOf('fish', $fish1->_get_model());
     $this->assertObjectHasAttribute('id', $fish1);
     $this->assertObjectHasAttribute('weight', $fish1);
     $this->assertObjectHasAttribute('bear_id', $fish1);
     $this->assertEquals('5', $fish1->weight);
     $this->assertSame($bear_lawly->id, $fish1->bear_id);
     $this->assertInternalType('object', $fish2);
     $this->assertInstanceOf('yf_model_result', $fish2);
     $this->assertInstanceOf('yf_model', $fish2->_get_model());
     $this->assertInstanceOf('fish', $fish2->_get_model());
     $this->assertObjectHasAttribute('id', $fish2);
     $this->assertObjectHasAttribute('weight', $fish2);
     $this->assertObjectHasAttribute('bear_id', $fish2);
     $this->assertEquals('12', $fish2->weight);
     $this->assertSame($bear_cerms->id, $fish2->bear_id);
     $this->assertInternalType('object', $fish3);
     $this->assertInstanceOf('yf_model_result', $fish3);
     $this->assertInstanceOf('yf_model', $fish3->_get_model());
     $this->assertInstanceOf('fish', $fish3->_get_model());
     $this->assertObjectHasAttribute('id', $fish3);
     $this->assertObjectHasAttribute('weight', $fish3);
     $this->assertObjectHasAttribute('bear_id', $fish3);
     $this->assertEquals('4', $fish3->weight);
     $this->assertSame($bear_adobot->id, $fish3->bear_id);
     // seed our trees table
     $tree1 = tree::create(['type' => 'Redwood', 'age' => '500', 'bear_id' => $bear_lawly->id]);
     $tree2 = tree::create(['type' => 'Oak', 'age' => '400', 'bear_id' => $bear_lawly->id]);
     $this->assertInternalType('object', $tree1);
     $this->assertInstanceOf('yf_model_result', $tree1);
     $this->assertInstanceOf('yf_model', $tree1->_get_model());
     $this->assertInstanceOf('tree', $tree1->_get_model());
     $this->assertObjectHasAttribute('id', $tree1);
     $this->assertObjectHasAttribute('type', $tree1);
     $this->assertObjectHasAttribute('age', $tree1);
     $this->assertObjectHasAttribute('bear_id', $tree1);
     $this->assertSame('Redwood', $tree1->type);
     $this->assertEquals('500', $tree1->age);
     $this->assertSame($bear_lawly->id, $tree1->bear_id);
     $this->assertInternalType('object', $tree2);
     $this->assertInstanceOf('yf_model_result', $tree2);
     $this->assertInstanceOf('yf_model', $tree2->_get_model());
     $this->assertInstanceOf('tree', $tree2->_get_model());
     $this->assertObjectHasAttribute('id', $tree2);
     $this->assertObjectHasAttribute('type', $tree2);
     $this->assertObjectHasAttribute('age', $tree2);
     $this->assertObjectHasAttribute('bear_id', $tree2);
     $this->assertSame('Oak', $tree2->type);
     $this->assertEquals('400', $tree2->age);
     $this->assertSame($bear_lawly->id, $tree2->bear_id);
     // we will create one picnic and apply all bears to this one picnic
     $picnic_yellowstone = picnic::create(['name' => 'Yellowstone', 'taste_level' => '6']);
     $picnic_grand_canyon = picnic::create(['name' => 'Grand Canyon', 'taste_level' => '5']);
     $this->assertInternalType('object', $picnic_yellowstone);
     $this->assertInstanceOf('yf_model_result', $picnic_yellowstone);
     $this->assertInstanceOf('yf_model', $picnic_yellowstone->_get_model());
     $this->assertInstanceOf('picnic', $picnic_yellowstone->_get_model());
     $this->assertObjectHasAttribute('id', $picnic_yellowstone);
     $this->assertObjectHasAttribute('name', $picnic_yellowstone);
     $this->assertObjectHasAttribute('taste_level', $picnic_yellowstone);
     $this->assertSame('Yellowstone', $picnic_yellowstone->name);
     $this->assertEquals('6', $picnic_yellowstone->taste_level);
     $this->assertInternalType('object', $picnic_grand_canyon);
     $this->assertInstanceOf('yf_model_result', $picnic_grand_canyon);
     $this->assertInstanceOf('yf_model', $picnic_grand_canyon->_get_model());
     $this->assertInstanceOf('picnic', $picnic_grand_canyon->_get_model());
     $this->assertObjectHasAttribute('id', $picnic_grand_canyon);
     $this->assertObjectHasAttribute('name', $picnic_grand_canyon);
     $this->assertObjectHasAttribute('taste_level', $picnic_grand_canyon);
     $this->assertSame('Grand Canyon', $picnic_grand_canyon->name);
     $this->assertEquals('5', $picnic_grand_canyon->taste_level);
     // ---------- link our bears to picnics -------------
     // for our purposes we'll just add all bears to both picnics for our many to many relationship
     $bear_lawly->picnics()->attach($picnic_yellowstone->id);
     $bear_lawly->picnics()->attach($picnic_grand_canyon->id);
     $bear_cerms->picnics()->attach($picnic_yellowstone->id);
     $bear_cerms->picnics()->attach($picnic_grand_canyon->id);
     $bear_adobot->picnics()->attach($picnic_yellowstone->id);
     $bear_adobot->picnics()->attach($picnic_grand_canyon->id);
     $this->assertEquals(['bear_id' => $bear_lawly->id, 'picnic_id' => $picnic_yellowstone->id], self::db()->select('bear_id, picnic_id')->from('bears_picnics')->where('bear_id', $bear_lawly->id)->where('picnic_id', $picnic_yellowstone->id)->get());
     $this->assertEquals(['bear_id' => $bear_lawly->id, 'picnic_id' => $picnic_grand_canyon->id], self::db()->select('bear_id, picnic_id')->from('bears_picnics')->where('bear_id', $bear_lawly->id)->where('picnic_id', $picnic_grand_canyon->id)->get());
     $this->assertEquals(['bear_id' => $bear_cerms->id, 'picnic_id' => $picnic_yellowstone->id], self::db()->select('bear_id, picnic_id')->from('bears_picnics')->where('bear_id', $bear_cerms->id)->where('picnic_id', $picnic_yellowstone->id)->get());
     $this->assertEquals(['bear_id' => $bear_cerms->id, 'picnic_id' => $picnic_grand_canyon->id], self::db()->select('bear_id, picnic_id')->from('bears_picnics')->where('bear_id', $bear_cerms->id)->where('picnic_id', $picnic_grand_canyon->id)->get());
     $this->assertEquals(['bear_id' => $bear_adobot->id, 'picnic_id' => $picnic_yellowstone->id], self::db()->select('bear_id, picnic_id')->from('bears_picnics')->where('bear_id', $bear_adobot->id)->where('picnic_id', $picnic_yellowstone->id)->get());
     $this->assertEquals(['bear_id' => $bear_adobot->id, 'picnic_id' => $picnic_grand_canyon->id], self::db()->select('bear_id, picnic_id')->from('bears_picnics')->where('bear_id', $bear_adobot->id)->where('picnic_id', $picnic_grand_canyon->id)->get());
 }