/** * @covers Foote\Ginny\Map\BaseModel::validate * * @expectedException \Foote\Ginny\Exception\GinnyMapException * @expectedExceptionCode 301 */ public function testMissingFields() { $model = new BaseModel('Thing'); $bundle = new BaseBundle('Bundle'); $bundle->addModel($model); $model->validate(); //all is good, no exceptions $this->assertTrue(true); }
/** * @covers Foote\Ginny\Map\BaseMap::validate * * @expectedException \Foote\Ginny\Exception\GinnyMapException * @expectedExceptionCode 301 */ public function testInvalidModel() { $model = new BaseModel('Thing'); $bundle = new BaseBundle('Bundle'); $bundle->addModel($model); $map = new BaseMap('Admin'); $map->addBundle($bundle); //additional model validations tested inside BaseBundleTest $map->validate(); }
/** * @covers Foote\Ginny\Map\BaseAssociation::__construct * @covers Foote\Ginny\Map\BaseAssociation::create * @covers Foote\Ginny\Map\BaseAssociation::pivot * @covers Foote\Ginny\Map\BaseAssociation::pivot_local_key * @covers Foote\Ginny\Map\BaseAssociation::pivot_parent_key * @covers Foote\Ginny\Map\BaseAssociation::dump */ public function testManyToMany() { $user = BaseModel::create('User'); $user->addField(BaseField::create('id', ['type' => 'integer'])); $role = BaseModel::create('Role'); $role->addField(BaseField::create('id', ['type' => 'integer'])); $userRole = BaseModel::create('UserRole'); $userRole->manyToMany = true; $userRole->addField(BaseField::create('user_id', ['type' => 'integer'])); $userRole->addField(BaseField::create('role_id', ['type' => 'integer'])); $bundle = BaseBundle::create('Bundle'); $bundle->addModel($user); $bundle->addModel($role); $bundle->addModel($userRole); /** * * UserRole belongsTo User * UserRole belongsTo Role * User belongsToMany Role * Role belongsToMany User * * we need $userRole to have it's respective "belongsTo" before we * add belongsToMany to $user and $role * * @see BaseAssociation */ BaseAssociation::create('User', ['owner' => $userRole, 'ownerKey' => 'user_id', 'type' => 'belongsTo', 'target' => $user, 'targetKey' => 'id']); BaseAssociation::create('Role', ['owner' => $userRole, 'ownerKey' => 'role_id', 'type' => 'belongsTo', 'target' => $role, 'targetKey' => 'id']); # now we are ready for $user belongsToMany $role, etc $association = BaseAssociation::create('UserRole', ['owner' => $user, 'ownerKey' => 'id', 'type' => 'belongsToMany', 'target' => $role, 'targetKey' => 'id', 'pivot' => $userRole]); $this->assertEquals($userRole, $association->pivot()); $this->assertEquals('user_id', $association->keys('pivot_local')->name); $this->assertEquals('user_id', $association->pivot_local_key()); $this->assertEquals('role_id', $association->keys('pivot_parent')->name); $this->assertEquals('role_id', $association->pivot_parent_key()); $this->assertNotEmpty($association->dump()); }
/** * @covers Foote\Ginny\Map\BaseBundle::validate * * @expectedException \Foote\Ginny\Exception\GinnyMapException * @expectedExceptionCode 301 */ public function testInvalidModel() { $model = new BaseModel('Thing'); $bundle = new BaseBundle('Bundle'); $bundle->addModel($model); //additional model validations tested inside BaseModelTest $bundle->validate(); }