-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Unit test for BaseApplication
- Loading branch information
1 parent
c9edc12
commit ed06e1f
Showing
1 changed file
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |