當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Cron::setDeleteDatabaseEntriesAfter方法代碼示例

本文整理匯總了PHP中Cron::setDeleteDatabaseEntriesAfter方法的典型用法代碼示例。如果您正苦於以下問題:PHP Cron::setDeleteDatabaseEntriesAfter方法的具體用法?PHP Cron::setDeleteDatabaseEntriesAfter怎麽用?PHP Cron::setDeleteDatabaseEntriesAfter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cron的用法示例。


在下文中一共展示了Cron::setDeleteDatabaseEntriesAfter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testDeleteOldDatabaseEntries

 /**
  * Test method for testing the delete old database entries function
  *
  * @covers \Liebig\Cron\Cron::setDeleteDatabaseEntriesAfter
  * @covers \Liebig\Cron\Cron::run
  */
 public function testDeleteOldDatabaseEntries()
 {
     $manager1 = new \Liebig\Cron\Models\Manager();
     $date1 = new \DateTime();
     date_sub($date1, date_interval_create_from_date_string('240 hours'));
     $manager1->rundate = $date1;
     $manager1->runtime = 0.01;
     $this->assertNotNull($manager1->save());
     $newError1 = new \Liebig\Cron\Models\Job();
     $newError1->name = "test1";
     $newError1->return = "test1 fails";
     $newError1->runtime = 0.001;
     $newError1->cron_manager_id = $manager1->id;
     $this->assertNotNull($newError1->save());
     $newError2 = new \Liebig\Cron\Models\Job();
     $newError2->name = "test2";
     $newError2->return = "test2 fails";
     $newError2->runtime = 0.002;
     $newError2->cron_manager_id = $manager1->id;
     $this->assertNotNull($newError2->save());
     $manager2 = new \Liebig\Cron\Models\Manager();
     $date2 = new \DateTime();
     date_sub($date2, date_interval_create_from_date_string('240 hours'));
     $manager2->rundate = $date2;
     $manager2->runtime = 0.02;
     $this->assertNotNull($manager2->save());
     $newError3 = new \Liebig\Cron\Models\Job();
     $newError3->name = "test3";
     $newError3->return = "tes31 fails";
     $newError3->runtime = 0.003;
     $newError3->cron_manager_id = $manager2->id;
     $this->assertNotNull($newError3->save());
     $manager3 = new \Liebig\Cron\Models\Manager();
     $date3 = new \DateTime();
     date_sub($date3, date_interval_create_from_date_string('10 hours'));
     $manager3->rundate = $date3;
     $manager3->runtime = 0.03;
     $this->assertNotNull($manager3->save());
     $newError4 = new \Liebig\Cron\Models\Job();
     $newError4->name = "test4";
     $newError4->return = "test4 fails";
     $newError4->runtime = 0.004;
     $newError4->cron_manager_id = $manager3->id;
     $this->assertNotNull($newError4->save());
     $newError5 = new \Liebig\Cron\Models\Job();
     $newError5->name = "test5";
     $newError5->return = "test5 fails";
     $newError5->runtime = 0.005;
     $newError5->cron_manager_id = $manager3->id;
     $this->assertNotNull($newError5->save());
     $this->assertEquals(3, \Liebig\Cron\Models\Manager::count());
     $this->assertEquals(5, \Liebig\Cron\Models\Job::count());
     Cron::setDeleteDatabaseEntriesAfter(240);
     Cron::run();
     $this->assertEquals(2, \Liebig\Cron\Models\Manager::count());
     $this->assertEquals(2, \Liebig\Cron\Models\Job::count());
     Cron::setDeleteDatabaseEntriesAfter(0);
     $manager4 = new \Liebig\Cron\Models\Manager();
     $date4 = new \DateTime();
     date_sub($date4, date_interval_create_from_date_string('2400 hours'));
     $manager4->rundate = $date4;
     $manager4->runtime = 0.04;
     $this->assertNotNull($manager4->save());
     $newError6 = new \Liebig\Cron\Models\Job();
     $newError6->name = "test6";
     $newError6->return = "test6 fails";
     $newError6->runtime = 0.006;
     $newError6->cron_manager_id = $manager4->id;
     $this->assertNotNull($newError6->save());
     $newError7 = new \Liebig\Cron\Models\Job();
     $newError7->name = "test7";
     $newError7->return = "test7 fails";
     $newError7->runtime = 0.007;
     $newError7->cron_manager_id = $manager3->id;
     $this->assertNotNull($newError7->save());
     Cron::run();
     $this->assertEquals(4, \Liebig\Cron\Models\Manager::count());
     $this->assertEquals(4, \Liebig\Cron\Models\Job::count());
 }
開發者ID:hilltool,項目名稱:cron,代碼行數:85,代碼來源:CronTest.php


注:本文中的Cron::setDeleteDatabaseEntriesAfter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。