Skip to content

Commit

Permalink
[TASK] Test flow application and add type declarations (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Mar 8, 2020
1 parent e3830c8 commit 5ad1da5
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 33 deletions.
15 changes: 0 additions & 15 deletions src/Application/BaseApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ public function registerTasks(Workflow $workflow, Deployment $deployment): void
}
}

/**
* Override all symlinks to be created with the given array of symlinks.
* @see addSymlinks()
*/
public function setSymlinks(array $symlinks): self
{
$this->symlinks = $symlinks;
Expand All @@ -143,20 +139,13 @@ public function getSymlinks(): array
return $this->symlinks;
}

/**
* Register an additional symlink to be created for the application
*/
public function addSymlink(string $linkPath, string $sourcePath): self
{
$this->symlinks[$linkPath] = $sourcePath;

return $this;
}

/**
* Register an array of additional symlinks to be created for the application
* @see setSymlinks()
*/
public function addSymlinks(array $symlinks): self
{
foreach ($symlinks as $linkPath => $sourcePath) {
Expand All @@ -166,10 +155,6 @@ public function addSymlinks(array $symlinks): self
return $this;
}

/**
* Override all directories to be created for the application
* @see addDIrectories()
*/
public function setDirectories(array $directories): self
{
$this->directories = $directories;
Expand Down
13 changes: 5 additions & 8 deletions src/Application/Neos/Flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
use TYPO3\Surf\Task\Neos\Flow\SymlinkConfigurationTask;
use TYPO3\Surf\Task\Neos\Flow\SymlinkDataTask;

/**
* A Neos Flow application template
*/
class Flow extends BaseApplication
{
/**
Expand Down Expand Up @@ -85,7 +82,7 @@ public function getContext(): string
return $this->context;
}

public function setVersion(string $version)
public function setVersion(string $version): void
{
$this->version = $version;
}
Expand All @@ -102,7 +99,7 @@ public function getVersion(): string
*/
public function getBuildEssentialsDirectoryName(): string
{
if ($this->getVersion() <= '1.1') {
if (version_compare($this->getVersion(), '1.1', '<=')) {
return 'Common';
}
return 'BuildEssentials';
Expand All @@ -115,18 +112,18 @@ public function getBuildEssentialsDirectoryName(): string
*/
public function getFlowScriptName(): string
{
if ($this->getVersion() <= '1.1') {
if (version_compare($this->getVersion(), '1.1', '<=')) {
return 'flow3';
}
return 'flow';
}

public function getCommandPackageKey(string $command = ''): string
{
if ($this->getVersion() < '2.0') {
if (version_compare($this->getVersion(), '2.0', '<')) {
return 'typo3.flow3';
}
if ($this->getVersion() < '4.0') {
if (version_compare($this->getVersion(), '4.0', '<')) {
return 'typo3.flow';
}
return 'neos.flow';
Expand Down
12 changes: 3 additions & 9 deletions src/Application/Neos/Neos.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
* file that was distributed with this source code.
*/

/**
* A Neos application template
*/
class Neos extends Flow
{
/**
Expand Down Expand Up @@ -48,10 +45,7 @@ class Neos extends Flow
'workspace:list'
];

/**
* @param string $name
*/
public function __construct($name = 'Neos')
public function __construct(string $name = 'Neos')
{
parent::__construct($name);

Expand All @@ -60,9 +54,9 @@ public function __construct($name = 'Neos')
]);
}

protected function isNeosCommand($command): bool
protected function isNeosCommand(string $command): bool
{
return in_array($command, $this->neosCommands, false);
return in_array($command, $this->neosCommands, true);
}

public function getCommandPackageKey(string $command = ''): string
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Model/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(string $name)
*
* $workflow->addTask(CreateDirectoriesTask::class, 'initialize', $this);
*/
public function registerTasks(Workflow $workflow, Deployment $deployment)
public function registerTasks(Workflow $workflow, Deployment $deployment): void
{
}

Expand Down
99 changes: 99 additions & 0 deletions tests/Unit/Application/Neos/FlowTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace TYPO3\Surf\Tests\Unit\Application\Neos;

/*
* 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 TYPO3\Surf\Application\Neos\Flow;
use TYPO3\Surf\Domain\Model\Deployment;
use TYPO3\Surf\Domain\Model\SimpleWorkflow;
use TYPO3\Surf\Task\Composer\InstallTask;

class FlowTest extends TestCase
{
/**
* @var Flow
*/
protected $subject;

public function commandPackageKeyProvider(): array
{
return [
['2.0', 'typo3.flow'],
['3.8', 'typo3.flow'],
['4.0', 'neos.flow'],
];
}

public function flowScriptNameProvider(): array
{
return [
['1.0', 'flow3'],
['1.1', 'flow3'],
['1.2', 'flow']
];
}

public function essentialsDirectoryNameProvider(): array
{
return [
['1.0', 'Common'],
['1.1', 'Common'],
['1.2', 'BuildEssentials']
];
}

protected function setUp()
{
$this->subject = new Flow();
}

/**
* @test
* @dataProvider commandPackageKeyProvider
*/
public function getCommandPackageKey(string $version, string $expectedCommandPackageKey): void
{
$this->subject->setVersion($version);
$this->assertEquals($expectedCommandPackageKey, $this->subject->getCommandPackageKey());
}

/**
* @test
* @dataProvider essentialsDirectoryNameProvider
*/
public function getBuildEssentialsDirectoryName(string $version, string $expectedEssentialsDirectoryName): void
{
$this->subject->setVersion($version);
$this->assertEquals($expectedEssentialsDirectoryName, $this->subject->getBuildEssentialsDirectoryName());
}

/**
* @test
* @dataProvider flowScriptNameProvider
*/
public function getFlowScriptName(string $version, string $expectedFlowScriptName): void
{
$this->subject->setVersion($version);
$this->assertEquals($expectedFlowScriptName, $this->subject->getFlowScriptName());
}

/**
* @test
*/
public function registerComposerInstallTask(): void
{
$deployment = $this->prophesize(Deployment::class);
$workflow = new SimpleWorkflow();
$this->subject->setOption('updateMethod', 'composer');
$this->subject->registerTasks($workflow, $deployment->reveal());
$tasks = $workflow->getTasks();
$this->assertContains(InstallTask::class, $tasks['stage'][$this->subject->getName()]['update']['tasks']);
}
}

0 comments on commit 5ad1da5

Please sign in to comment.