From 886b7522f646c98fe012c35b178922f9f03a15c4 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 10 Oct 2023 07:21:18 +0200 Subject: [PATCH] TASK: Inject Logger for custom task --- src/Domain/Service/TaskFactory.php | 5 +++++ tests/Unit/Domain/Service/CustomTask.php | 6 ++++++ tests/Unit/Domain/Service/TaskFactoryTest.php | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Domain/Service/TaskFactory.php b/src/Domain/Service/TaskFactory.php index a525f142..d35ab878 100644 --- a/src/Domain/Service/TaskFactory.php +++ b/src/Domain/Service/TaskFactory.php @@ -11,6 +11,8 @@ namespace TYPO3\Surf\Domain\Service; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; use TYPO3\Surf\Domain\Model\Task; @@ -35,6 +37,9 @@ private function createTask(string $taskName): Task if ($task instanceof ShellCommandServiceAwareInterface) { $task->setShellCommandService(new ShellCommandService()); } + if($task instanceof LoggerAwareInterface) { + $task->setLogger($this->container->get(LoggerInterface::class)); + } } else { $task = $this->container->get($taskName); } diff --git a/tests/Unit/Domain/Service/CustomTask.php b/tests/Unit/Domain/Service/CustomTask.php index f3972f1d..e3786406 100644 --- a/tests/Unit/Domain/Service/CustomTask.php +++ b/tests/Unit/Domain/Service/CustomTask.php @@ -11,6 +11,7 @@ namespace TYPO3\Surf\Tests\Unit\Domain\Service; +use Psr\Log\LoggerInterface; use TYPO3\Surf\Domain\Model\Application; use TYPO3\Surf\Domain\Model\Deployment; use TYPO3\Surf\Domain\Model\Node; @@ -31,4 +32,9 @@ public function getShell(): ShellCommandService { return $this->shell; } + + public function getLogger(): LoggerInterface + { + return $this->logger; + } } diff --git a/tests/Unit/Domain/Service/TaskFactoryTest.php b/tests/Unit/Domain/Service/TaskFactoryTest.php index e7a4235b..99e6cc37 100644 --- a/tests/Unit/Domain/Service/TaskFactoryTest.php +++ b/tests/Unit/Domain/Service/TaskFactoryTest.php @@ -12,6 +12,8 @@ namespace TYPO3\Surf\Tests\Unit\Domain\Service; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; +use TYPO3\Surf\Domain\Service\ShellCommandService; use TYPO3\Surf\Domain\Service\TaskFactory; use TYPO3\Surf\Task\CreateArchiveTask; use TYPO3\Surf\Tests\Unit\KernelAwareTrait; @@ -52,7 +54,8 @@ public function createSyntheticServiceIfNotExists(): void /** @var CustomTask $customTask */ $customTask = $this->subject->createTaskInstance(CustomTask::class); - self::assertNotNull($customTask->getShell()); + self::assertInstanceOf(ShellCommandService::class, $customTask->getShell()); + self::assertInstanceOf(LoggerInterface::class, $customTask->getLogger()); self::assertInstanceOf(CustomTask::class, $customTask); }