当前位置: 首页>>代码示例>>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;未经允许,请勿转载。