本文整理汇总了PHP中Dog::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Dog::get方法的具体用法?PHP Dog::get怎么用?PHP Dog::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dog
的用法示例。
在下文中一共展示了Dog::get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testWrite_WriteObjects_ObjectsWritten
/**
*
*/
public function testWrite_WriteObjects_ObjectsWritten()
{
$batchSizes = array(10, 30, 100, 300);
foreach ($batchSizes as $size) {
$owners = array();
$dogs = array();
$cats = array();
$writer = new \BatchedWriter($size);
for ($i = 0; $i < 100; $i++) {
$owner = new Human();
$owner->Name = 'Human ' . $i;
$dog = new Dog();
$dog->Name = 'Dog ' . $i;
$cat = new Cat();
$cat->Name = 'Cat ' . $i;
$owner->onAfterExistsCallback(function ($owner) use($dog, $writer) {
$dog->OwnerID = $owner->ID;
$writer->write($dog);
});
$dog->onAfterExistsCallback(function ($dog) use($cat, $writer) {
$cat->EnemyID = $dog->ID;
$writer->write($cat);
});
$owners[] = $owner;
$dogs[] = $dog;
$cats[] = $cat;
}
// writes dogs first time
$writer->write($dogs);
// dogs written again from owner callback
$writer->write($owners);
$writer->finish();
$owners = Human::get();
$dogs = Dog::get();
$cats = Cat::get();
$this->assertEquals(100, $owners->Count());
$this->assertEquals(100, $dogs->Count());
$this->assertEquals(100, $cats->Count());
for ($i = 0; $i < 100; $i++) {
$owner = $owners[$i];
$dog = $dogs[$i];
$cat = $cats[$i];
$this->assertEquals($owner->ID, $dog->OwnerID);
$this->assertEquals($dog->ID, $cat->EnemyID);
}
$writer->delete($owners);
$writer->delete($dogs);
$writer->delete($cats);
$writer->finish();
$this->assertEquals(0, Human::get()->Count());
$this->assertEquals(0, Dog::get()->Count());
$this->assertEquals(0, Cat::get()->Count());
}
}
示例2: testBranchDeleteIDs_DeleteManyIDs_ObjectsDeleted
/**
* @throws \ValidationException
* @throws null
*/
public function testBranchDeleteIDs_DeleteManyIDs_ObjectsDeleted()
{
$className = '';
$ids = array();
for ($i = 0; $i < 100; $i++) {
$dog = new Dog();
$dog->Name = 'Pup ' . $i;
$dog->Color = 'Fifty Shade No. ' . $i;
$dog->write();
$className = $dog->ClassName;
$ids[] = $dog->ID;
}
$batch = new \Batch();
$batch->deleteIDs($className, $ids);
$this->assertEquals(0, Dog::get()->Count());
}
示例3: 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);
}
示例4: 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);
}