Skip to content

Commit

Permalink
Merge 3d2e11d into 5006382
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Apr 3, 2020
2 parents 5006382 + 3d2e11d commit 9285d4a
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/Command/RollbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$configurationPath = $input->getOption('configurationPath');
$deploymentName = $input->getArgument('deploymentName');
$deployment = $this->factory->getDeployment((string)$deploymentName, $configurationPath, $input->getOption('simulate'), false);
$deployment->rollback($input->getOption('simulate'));
$configurationPath = (string)$input->getOption('configurationPath');
$deploymentName = (string)$input->getArgument('deploymentName');
$simulate = (bool)$input->getOption('simulate');

$deployment = $this->factory->getDeployment($deploymentName, $configurationPath, $simulate, false);
$deployment->rollback($simulate);

return $deployment->getStatus();
}
Expand Down
3 changes: 3 additions & 0 deletions src/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
* @codeCoverageIgnore
*/
class SelfUpdateCommand extends Command
{
/**
Expand Down
8 changes: 5 additions & 3 deletions src/Command/SimulateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$configurationPath = $input->getOption('configurationPath');
$deploymentName = $input->getArgument('deploymentName');
$deployment = $this->factory->getDeployment((string)$deploymentName, $configurationPath, true, true, $input->getOption('force'));
$configurationPath = (string)$input->getOption('configurationPath');
$deploymentName = (string)$input->getArgument('deploymentName');
$force = (bool)$input->getOption('force');

$deployment = $this->factory->getDeployment($deploymentName, $configurationPath, true, true, $force);
$deployment->simulate();

return $deployment->getStatus();
Expand Down
36 changes: 36 additions & 0 deletions tests/Unit/Command/RollbackCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace TYPO3\Surf\Tests\Unit\Command;

/*
* This file is part of TYPO3 Surf.
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use TYPO3\Surf\Command\RollbackCommand;
use TYPO3\Surf\Domain\Model\Deployment;
use TYPO3\Surf\Integration\FactoryInterface;

class RollbackCommandTest extends TestCase
{
/**
* @test
*/
public function executeSuccessfully(): void
{
$deployment = $this->prophesize(Deployment::class);
$deployment->getStatus()->willReturn(Deployment::STATUS_SUCCESS)->shouldBeCalledOnce();
$deployment->rollback(false)->shouldBeCalledOnce();
$factory = $this->prophesize(FactoryInterface::class);
$factory->getDeployment('foo', '.surf', false, false)->willReturn($deployment);
$command = new RollbackCommand($factory->reveal());
$commandTester = new CommandTester($command);
$commandTester->execute(['deploymentName' => 'foo', '--configurationPath' => '.surf', '--simulate' => false]);

$this->assertEquals('', $commandTester->getDisplay());
}
}
40 changes: 40 additions & 0 deletions tests/Unit/Command/ShowCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace TYPO3\Surf\Tests\Unit\Command;

/*
* This file is part of TYPO3 Surf.
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use TYPO3\Surf\Command\ShowCommand;
use TYPO3\Surf\Integration\FactoryInterface;

class ShowCommandTest extends TestCase
{
/**
* @test
*/
public function executeSuccessfully(): void
{
$factory = $this->prophesize(FactoryInterface::class);
$factory->getDeploymentNames('.surf')->willReturn(['foo', 'bar', 'baz']);
$factory->getDeploymentsBasePath('.surf')->willReturn('./surf');
$command = new ShowCommand($factory->reveal());
$commandTester = new CommandTester($command);
$commandTester->execute(['--configurationPath' => '.surf']);

$this->assertEquals('
<u>Deployments in "./surf":</u>
foo
bar
baz
', $commandTester->getDisplay());
}
}
37 changes: 37 additions & 0 deletions tests/Unit/Command/SimulateCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace TYPO3\Surf\Tests\Unit\Command;

/*
* This file is part of TYPO3 Surf.
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use TYPO3\Surf\Command\SimulateCommand;
use TYPO3\Surf\Domain\Model\Deployment;
use TYPO3\Surf\Integration\FactoryInterface;

class SimulateCommandTest extends TestCase
{
/**
* @test
*/
public function executeSuccessfully(): void
{
$deployment = $this->prophesize(Deployment::class);
$deployment->getStatus()->willReturn(Deployment::STATUS_SUCCESS)->shouldBeCalledOnce();
$deployment->simulate()->shouldBeCalledOnce();

$factory = $this->prophesize(FactoryInterface::class);
$factory->getDeployment('foo', '.surf', true, true, true)->willReturn($deployment);
$command = new SimulateCommand($factory->reveal());
$commandTester = new CommandTester($command);
$commandTester->execute(['deploymentName' => 'foo', '--configurationPath' => '.surf', '--force' => true]);

$this->assertEquals('', $commandTester->getDisplay());
}
}

0 comments on commit 9285d4a

Please sign in to comment.