From e04af5edbec32570ec9a8ab9749505f57136f5aa Mon Sep 17 00:00:00 2001 From: CodeCasterNL Date: Wed, 3 Aug 2022 19:58:37 +0200 Subject: [PATCH] fix: Annotation parameters v2 (#19) * Add failing test to indicate commandLine parsing bug * Fix commandLine parsing bug * Fix process test --- Tests/HelperTest.php | 9 ++++++--- Util/Helper.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Tests/HelperTest.php b/Tests/HelperTest.php index 5664593..28c7595 100644 --- a/Tests/HelperTest.php +++ b/Tests/HelperTest.php @@ -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]; @@ -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); @@ -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); } } diff --git a/Util/Helper.php b/Util/Helper.php index 12ab698..8975351 100644 --- a/Util/Helper.php +++ b/Util/Helper.php @@ -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) {