From 75aee1c45400af08c89256aa07edad7963c10cb4 Mon Sep 17 00:00:00 2001 From: Jeroen Versteeg Date: Thu, 8 Apr 2021 09:55:46 +0200 Subject: [PATCH] Added end2end test for event logging customization #309 #346 --- tests/EndToEnd/LoggerTest.php | 27 +++++++++++++++++++++ tests/resources/tasks/CustomOutputTasks.php | 16 ++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/resources/tasks/CustomOutputTasks.php diff --git a/tests/EndToEnd/LoggerTest.php b/tests/EndToEnd/LoggerTest.php index 1099532a..b3076cdd 100644 --- a/tests/EndToEnd/LoggerTest.php +++ b/tests/EndToEnd/LoggerTest.php @@ -39,6 +39,33 @@ public function test_outputs_are_logged(): void ); } + public function test_event_logging_override(): void + { + $envBuilder = $this->createEnvironmentBuilder() + ->addTask('CustomOutputTasks') + ->withConfig( + [ + 'log_output' => true, + 'output_log_file' => 'main.log', + ] + ) + ; + $environment = $envBuilder->createEnvironment(); + $logPath = $environment->rootDirectory() . DIRECTORY_SEPARATOR; + + $process = $environment->runCrunzCommand('schedule:run'); + + $this->assertEmpty($process->getOutput()); + + $this->assertFileDoesNotExist("$logPath/main.log"); + + $this->assertFileExists("$logPath/custom.log"); + $this->assertStringContainsString( + 'Usage: php', + file_get_contents("$logPath/custom.log") + ); + } + private function assertLogRecord( string $logRecord, string $level, diff --git a/tests/resources/tasks/CustomOutputTasks.php b/tests/resources/tasks/CustomOutputTasks.php new file mode 100644 index 00000000..a65b21c7 --- /dev/null +++ b/tests/resources/tasks/CustomOutputTasks.php @@ -0,0 +1,16 @@ +run('php --help') + ->description('Custom logging test') + ->everyMinute() + ->appendOutputTo('custom.log') +; + +return $scheduler;