public function testSetterGetter() { $this->assertNull($this->crontab->getUser()); $this->assertEquals('root', $this->crontab->setUser('root')->getUser()); $this->assertCount(0, $this->crontab->getJobs()); $this->crontab->setJobs(array($this->job1, $this->job2)); $this->assertCount(2, $this->crontab->getJobs()); $this->assertEquals("", $this->crontab->getMailto()); $this->assertEquals("*****@*****.**", $this->crontab->setMailto('*****@*****.**')->getMailto()); $this->assertStringStartsWith("MAILTO=contact@yzalis.com" . "\n", $this->crontab->render()); $this->crontab->removeAllJobs(); $this->assertCount(0, $this->crontab->getJobs()); $job = new Job(); $this->crontab->addJob($job); $this->assertCount(1, $this->crontab->getJobs()); $this->crontab->addJob($job); $this->assertCount(1, $this->crontab->getJobs()); $job = new Job(); $job->setCommand('test'); $this->crontab->addJob($job); $this->assertCount(2, $this->crontab->getJobs()); $this->crontab->removeAllJobs(); $this->crontab->setJobs(array($this->job1, $this->job2)); $this->crontab->removeJob($this->job1); $this->assertCount(1, $this->crontab->getJobs()); $job = $this->crontab->getJobs(); $this->assertEquals(array_shift($job), $this->job2); }
/** * Add a new job to the crontab * * @param Yzalis\Components\Job $job * * @return Crontab */ public function addJob(Job $job) { $this->jobs[$job->getHash()] = $job; return $this; }