Beispiel #1
0
 /**
  * @covers Foote\Ginny\Map\BaseModel::update
  * @covers Foote\Ginny\Map\BaseModel::validate
  * @covers Foote\Ginny\Map\BaseModel::dump
  */
 public function testupdate()
 {
     $bundle = new BaseBundle('Bundle');
     $site = BaseModel::create('Site');
     $site->bundle = $bundle;
     $site->addField(BaseField::create('id', ['type' => 'integer']));
     $user = BaseModel::create('User');
     $user->bundle = $bundle;
     $user->addField(BaseField::create('id', ['type' => 'integer']));
     $user->addField(BaseField::create('site_id', ['type' => 'integer']));
     BaseAssociation::create('Site', ['owner' => $user, 'ownerKey' => 'site_id', 'type' => 'belongsTo', 'target' => $site, 'targetKey' => 'id']);
     $user->update();
     $user->validate();
     //all is good, no exceptions
     $this->assertTrue(true);
     $this->assertNotEmpty($user->dump());
 }
 /**
  * @covers Foote\Ginny\Map\BaseAssociation::update
  */
 public function testupdate()
 {
     $bundle = new BaseBundle('Bundle');
     $site = BaseModel::create('Site');
     $site->bundle = $bundle;
     $site->addField(BaseField::create('id', ['type' => 'integer']));
     // Site hasOne Profile
     $profile = BaseModel::create('Profile');
     $profile->bundle = $bundle;
     $profile->addField(BaseField::create('id', ['type' => 'integer']));
     //add unique field to Profile
     $field = BaseField::create('site_id', ['type' => 'integer']);
     $field->unique = true;
     $profile->addField($field);
     $association = BaseAssociation::create('SiteProfile', ['owner' => $site, 'ownerKey' => 'id', 'type' => 'hasMany', 'target' => $profile, 'targetKey' => 'site_id']);
     //hasMany should be converted to hasOne since Profile.site_id is unique
     $association->update();
     $this->assertEquals('hasOne', $association->type);
 }