本文整理汇总了PHP中Dog::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Dog::exists方法的具体用法?PHP Dog::exists怎么用?PHP Dog::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dog
的用法示例。
在下文中一共展示了Dog::exists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCallback_ManyConditions_CalledBack
/**
* @throws \ValidationException
* @throws null
*/
public function testCallback_ManyConditions_CalledBack()
{
$dog = new Dog();
$dog->Name = 'Johnny';
$owner1 = new Human();
$owner1->Name = 'Bob';
$owner2 = new Human();
$owner2->Name = 'Wot';
$cat = new Cat();
$cat->Name = 'Agnis';
$afterExists = new \OnAfterExists(function () use($dog) {
$dog->write();
});
$afterExists->addCondition($owner1, function ($owner) use($dog) {
$dog->Name .= ' ' . $owner->Name;
$dog->OwnerID = $owner->ID;
});
$afterExists->addCondition($owner2, function ($owner) use($dog) {
$dog->Name .= ' ' . $owner->Name;
$dog->OwnerID = $owner->ID;
});
$afterExists->addCondition($cat, function ($cat) use($dog) {
$dog->Name .= ' ' . $cat->Name;
});
$owner1->write();
$this->assertFalse($dog->exists());
$owner2->write();
$this->assertFalse($dog->exists());
$cat->write();
$this->assertTrue($dog->exists());
$this->assertEquals($owner2->ID, $dog->OwnerID);
$this->assertEquals('Johnny Bob Wot Agnis', $dog->Name);
}
示例2: testBatchWrite_DifferentClasses_WritesObjects
/**
*
*/
public function testBatchWrite_DifferentClasses_WritesObjects()
{
$dog = new Dog();
$dog->Name = 'Snuffins';
$dog->Color = 'Red';
$cat = new Cat();
$cat->Name = 'Puff daddy';
$cat->HasClaws = true;
$batch = new \Batch();
$batch->write(array($dog, $cat));
$this->assertTrue($dog->exists());
$this->assertTrue($cat->exists());
$dog = Dog::get()->first();
$this->assertEquals('Snuffins', $dog->Name);
$this->assertEquals('Red', $dog->Color);
$cat = Cat::get()->first();
$this->assertEquals('Puff daddy', $cat->Name);
$this->assertEquals(1, $cat->HasClaws);
}
示例3: testCallback_SetOnAfterExistsCallback_CallbackCalled
/**
* @throws \ValidationException
* @throws null
*/
public function testCallback_SetOnAfterExistsCallback_CallbackCalled()
{
$dog1 = new Dog();
$dog1->Name = 'Jim bob';
$dog2 = new Dog();
$dog2->Name = 'Super Dog';
$owner = new Human();
$owner->Name = 'Hilly Stewart';
$owner->write();
$owner->onAfterExistsCallback(function ($owner) use($dog1) {
$dog1->OwnerID = $owner->ID;
$dog1->write();
});
$owner->write();
$owner->onAfterExistsCallback(function ($owner) use($dog2) {
$dog2->OwnerID = $owner->ID;
$dog2->write();
});
$this->assertTrue($owner->exists());
$this->assertTrue($dog1->exists());
$this->assertTrue($dog2->exists());
$this->assertEquals(1, Human::get()->Count());
$this->assertEquals(2, Dog::get()->Count());
$this->assertEquals($owner->ID, $dog1->OwnerID);
$this->assertEquals($owner->ID, $dog2->OwnerID);
}