Skip to content

Commit

Permalink
[TASK] Unit test for BaseApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Apr 3, 2020
1 parent c9edc12 commit ed06e1f
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions tests/Unit/Application/BaseApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

namespace TYPO3\Surf\Tests\Unit\Application;

/*
* 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 Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use TYPO3\Surf\Application\BaseApplication;
use TYPO3\Surf\Domain\Model\Deployment;
use TYPO3\Surf\Domain\Model\Workflow;
use TYPO3\Surf\Task\GitCheckoutTask;
use TYPO3\Surf\Task\Transfer\ScpTask;
use TYPO3\Surf\Tests\Unit\FluidPromise;

class BaseApplicationTest extends TestCase
{

/**
* @var BaseApplication
*/
private $subject;

protected function setUp()
{
$this->subject = new BaseApplication('Base Application');
}

/**
* @test
*/
public function addDirectories(): void
{
$directories = ['dir1', 'dir2'];
$this->subject->addDirectories($directories);
$this->assertContains('dir1', $this->subject->getDirectories());
$this->assertContains('dir2', $this->subject->getDirectories());
}

/**
* @test
*/
public function setSymlinks(): void
{
$symlinks = ['toPath' => 'symlink1'];
$this->subject->setSymlinks($symlinks);
$this->assertSame($this->subject->getSymlinks(), $symlinks);
}

/**
* @test
*/
public function setDirectories(): void
{
$directories = ['dir1', 'dir2'];
$this->subject->setDirectories($directories);
$this->assertSame($this->subject->getDirectories(), $directories);
}

/**
* @test
*/
public function registerTasksForGitTransferMethod(): void
{
$workflow = $this->createWorkflow();

$workflow->addTask(GitCheckoutTask::class, 'transfer', $this->subject)->shouldBeCalledOnce();
$deployment = $this->prophesize(Deployment::class);
$this->subject->setOption('transferMethod', 'git');
$this->subject->registerTasks($workflow->reveal(), $deployment->reveal());
}

/**
* @test
*/
public function registerTasksForScpTransferMethod(): void
{
$workflow = $this->createWorkflow();

$workflow->addTask(ScpTask::class, 'transfer', $this->subject)->shouldBeCalledOnce();
$deployment = $this->prophesize(Deployment::class);
$this->subject->setOption('transferMethod', 'scp');
$this->subject->registerTasks($workflow->reveal(), $deployment->reveal());
}

/**
* @test
*/
public function addSymlink(): void
{
$this->subject->addSymlink('toPath', 'fromPath');
$this->assertContains('fromPath', $this->subject->getSymlinks());
}

/**
* @test
*/
public function addSymlinks(): void
{
$symlinks = ['toPath' => 'fromPath'];
$this->subject->addSymlinks($symlinks);
$this->assertContains('fromPath', $this->subject->getSymlinks());
}

/**
* @test
*/
public function addDirectory(): void
{
$this->subject->addDirectory('toPath');
$this->assertContains('toPath', $this->subject->getDirectories());
}

/**
* @return ObjectProphecy|Workflow
*/
private function createWorkflow(): ObjectProphecy
{
$workflow = $this->prophesize(Workflow::class);
$workflow->addTask(Argument::any(), Argument::any(), $this->subject)->will(new FluidPromise());
$workflow->afterTask(Argument::any(), Argument::any(), $this->subject)->will(new FluidPromise());
$workflow->afterStage(Argument::any(), Argument::any(), $this->subject)->will(new FluidPromise());
$workflow->defineTask(Argument::any(), Argument::any(), Argument::type('array'))->will(new FluidPromise());

return $workflow;
}
}

0 comments on commit ed06e1f

Please sign in to comment.