Skip to content

Commit

Permalink
fix: Annotation parameters v2 (#19)
Browse files Browse the repository at this point in the history
* Add failing test to indicate commandLine parsing bug

* Fix commandLine parsing bug

* Fix process test
  • Loading branch information
CodeCasterNL authored Aug 3, 2022
1 parent 2985f2f commit e04af5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Tests/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function should_ignore_irrelevant_attributes()
public function should_process_jobs()
{
$command = $this->createMock(Command::class);
$command->expects($this->once())->method('getName')->willReturn('my:job');
$command->expects($this->never())->method('getName'); // custom command line provided, no call for default

$commands = [$command];

Expand All @@ -253,7 +253,7 @@ public function should_process_jobs()

$annotationReader = $this->createMock(AnnotationReader::class);
$annotationReader->expects($this->once())->method('getClassAnnotations')->willReturn([
new Job('*', '*', '*', '*', '*', null, 'myjob.log'),
new Job('*', '*', '*', '*', '*', null, 'myjob.log', 'my:job 42 --first-option --second-option true'),
]);

$helper = new Helper($application, $annotationReader);
Expand All @@ -266,8 +266,11 @@ public function should_process_jobs()

$job = $tab->getJobs()[0];

// logFile parameter
$this->assertEquals($this->getConfig()['log_dir'] . '/myjob.log', $job->logFile);

// commandLine parameter
$this->assertStringStartsWith($this->getConfig()['php_binary'], $job->commandLine);
$this->assertStringEndsWith('my:job', $job->commandLine);
$this->assertStringEndsWith('my:job 42 --first-option --second-option true', $job->commandLine);
}
}
2 changes: 1 addition & 1 deletion Util/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private function processJob(Job $job, InputInterface $input, array $config, Comm
'%s %s %s',
$config['php_binary'],
realpath($_SERVER['argv'][0]),
$annotation->commandLine ?? $commandInstance->getName()
$job->commandLine ?? $commandInstance->getName()
);

if ($config['log_dir'] !== null && $job->logFile !== null) {
Expand Down

0 comments on commit e04af5e

Please sign in to comment.