Skip to content

Commit

Permalink
CrontabRepository->findByRegex now search inside all of the crontab line
Browse files Browse the repository at this point in the history
  • Loading branch information
TiBeN committed Jul 6, 2015
1 parent 91155ba commit fbc9409
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CrontabManager/CrontabRepository.php
Expand Up @@ -98,7 +98,7 @@ public function findJobByRegex($regex)

if (!empty($this->crontabJobs)) {
foreach ($this->crontabJobs as $crontabJob) {
if (preg_match($regex, $crontabJob->taskCommandLine)) {
if (preg_match($regex, $crontabJob->formatCrontabLine())) {
array_push($crontabJobs, $crontabJob);
}
}
Expand Down
35 changes: 35 additions & 0 deletions tests/CrontabManager/Tests/CrontabRepositoryTest.php
Expand Up @@ -150,6 +150,41 @@ public function testFindJobByRegex()

}

/**
* Test finding a job by a regular expression
* using the comments
*/
public function testFindJobByRegexUsingComments()
{
/* Create fake crontabAdapter */
$fakeCrontabAdapter = $this->getMock('TiBeN\CrontabManager\CrontabAdapter');
$fakeCrontabAdapter
->expects($this->any())
->method('readCrontab')
->will(
$this->returnValue("")
)
;

$crontabJob = new CrontabJob();
$crontabJob->minutes = '30';
$crontabJob->hours = '23';
$crontabJob->dayOfMonth = '*';
$crontabJob->months = '*';
$crontabJob->dayOfWeek = '*';
$crontabJob->taskCommandLine = 'df >> /tmp/df.log';
$crontabJob->comments = 'Logging disk usage';

$expectedCrontabJobs = array($crontabJob);

$crontabRepository = new CrontabRepository($fakeCrontabAdapter);
$crontabRepository->addJob($crontabJob);

$crontabJobs = $crontabRepository->findJobByRegex('/Logging\ disk\ usage/');

$this->assertEquals($expectedCrontabJobs, $crontabJobs);
}

/**
* This test will modify an existing job and append a new job to the crontab.
*/
Expand Down

0 comments on commit fbc9409

Please sign in to comment.