Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dependency injection for LockDeploymentTask #464

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}