本文整理匯總了PHP中Artist::validateModel方法的典型用法代碼示例。如果您正苦於以下問題:PHP Artist::validateModel方法的具體用法?PHP Artist::validateModel怎麽用?PHP Artist::validateModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Artist
的用法示例。
在下文中一共展示了Artist::validateModel方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testValidateModelWithoutMbid
/**
* @covers Artist::validateModel
*/
public function testValidateModelWithoutMbid()
{
$artistDummy = $this->dummyArtistProvider();
$artistDummy->mbid = null;
$this->assertTrue($this->object->validateModel($artistDummy, $error), 'Artist validation should be ok, but returned reason:' . $error);
$this->assertEquals($artistDummy->id, $this->object->id, 'Artist id should have been set during validation');
$this->assertEquals($artistDummy->name, $this->object->name, 'Artist name should have been set during validation');
$this->assertEquals($artistDummy->country, $this->object->country, 'Artist country should have been set during validation');
$this->assertEquals($artistDummy->summary, $this->object->summary, 'Artist summary should have been set during validation');
$this->assertNull($this->object->mbid, 'Artist MBID should not have been set during validation');
$artistDummy->mbid = '';
$this->assertTrue($this->object->validateModel($artistDummy, $error), 'Artist validation should be ok, but returned reason:' . $error);
$this->assertNull($this->object->mbid, 'Artist MBID should not have been set during validation');
$artistDummy->mbid = 'MbidShorterThan36';
$this->assertFalse($this->object->validateModel($artistDummy, $error), 'Artist validation should not be ok');
$this->assertEquals('String with a valid format must be provided in MBID attribute', $error, 'Error message should be "String with a valid format must be provided in MBID attribute" but returned: ' . $error);
}
示例2: Artist
$api->output(403, 'Admin scope is required for editing artist');
//indicate the requester do not have the required scope for updating artist
return;
}
if (!$api->checkParameterExists('id', $id)) {
$api->output(400, 'Artist identifier must be provided');
//artist was not provided, return an error
return;
}
$artist = new Artist($id);
if (!$artist->populate(['id' => $id])) {
$api->output(404, 'Artist not found');
//indicate the artist was not found
return;
}
//adapt and validate object received
$updatedArtist = $api->query['body'];
if (!$artist->validateModel($updatedArtist, $errorMessage)) {
$api->output(400, 'Artist is not valid: ' . $errorMessage);
//provided user is not valid
return;
}
if (!$artist->update($errorMessage)) {
$api->output(500, 'Error during artist update' . $errorMessage);
//something gone wrong :(
return;
}
$artist->getTracks();
$api->output(200, $artist->structureData());
break;
}