Skip to content

Commit

Permalink
Use dependency injection for LockDeploymentTask
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Feb 7, 2022
1 parent e8ac94b commit 984947f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/Task/LockDeploymentTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use TYPO3\Surf\Domain\Model\Deployment;
use TYPO3\Surf\Domain\Model\Node;
use TYPO3\Surf\Domain\Model\Task;
use TYPO3\Surf\Domain\Service\ShellCommandService;
use TYPO3\Surf\Domain\Service\ShellCommandServiceAwareInterface;
use TYPO3\Surf\Domain\Service\ShellCommandServiceAwareTrait;
use TYPO3\Surf\Exception\DeploymentLockedException;
Expand All @@ -23,10 +22,17 @@
*/
final class LockDeploymentTask extends Task implements ShellCommandServiceAwareInterface
{
const LOCK_FILE_NAME = 'deploy.lock';
public const LOCK_FILE_NAME = 'deploy.lock';

private UnlockDeploymentTask $unlockDeploymentTask;

use ShellCommandServiceAwareTrait;

public function __construct(UnlockDeploymentTask $unlockDeploymentTask)
{
$this->unlockDeploymentTask = $unlockDeploymentTask;
}

public function execute(Node $node, Application $application, Deployment $deployment, array $options = []): void
{
if (! $deployment->isDryRun()) {
Expand All @@ -51,9 +57,7 @@ public function execute(Node $node, Application $application, Deployment $deploy

public function rollback(Node $node, Application $application, Deployment $deployment, array $options = []): void
{
$unLockDeployment = new UnlockDeploymentTask();
$unLockDeployment->setShellCommandService(new ShellCommandService());
$unLockDeployment->execute($node, $application, $deployment, $options);
$this->unlockDeploymentTask->execute($node, $application, $deployment, $options);
}

/**
Expand Down
11 changes: 7 additions & 4 deletions tests/Unit/Task/LockDeploymentTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ public function deploymentIsLockedThrowsException(): void
$this->task->execute($this->node, $this->application, $this->deployment);
}

/**
* @return LockDeploymentTask
*/
protected function createTask(): LockDeploymentTask
{
return new LockDeploymentTask();
$task = static::getKernel()->getContainer()->get(LockDeploymentTask::class);

if (!$task instanceof LockDeploymentTask) {
throw new \UnexpectedValueException(sprintf('Task is not of type "%s"', LockDeploymentTask::class));
}

return $task;
}
}

0 comments on commit 984947f

Please sign in to comment.