Skip to content

Commit

Permalink
Merge f4cd5ef into ea21eef
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Apr 6, 2023
2 parents ea21eef + f4cd5ef commit 39cfc03
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Cli/Symfony/ConsoleKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function build(ContainerBuilder $container): void

public function getCacheDir(): string
{
if(Phar::running() !== '') {
if (Phar::running() !== '') {
return sys_get_temp_dir() . '/_surf';
}

Expand All @@ -79,7 +79,7 @@ public function getCacheDir(): string

public function getLogDir(): string
{
if(Phar::running() !== '') {
if (Phar::running() !== '') {
return sys_get_temp_dir() . '/_surf_log';
}

Expand Down
8 changes: 7 additions & 1 deletion src/Task/Generic/CreateSymlinksTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function execute(Node $node, Application $application, Deployment $deploy

foreach ($options['symlinks'] as $linkPath => $sourcePath) {
// creates empty directory if path does not exist
$commands[] = sprintf('test -e %s || mkdir -p %s', $sourcePath, $sourcePath);
if ($options['createNonExistingSharedDirectories'] === true) {
$commands[] = sprintf('test -e %s || mkdir -p %s', $sourcePath, $sourcePath);
}

$commands[] = sprintf('ln -s %s %s', $sourcePath, $linkPath);
}
Expand All @@ -74,6 +76,10 @@ protected function resolveOptions(OptionsResolver $resolver): void
{
$resolver->setDefault('symlinks', []);
$resolver->setAllowedTypes('symlinks', 'array');

$resolver->setDefault('createNonExistingSharedDirectories', true);
$resolver->setAllowedTypes('createNonExistingSharedDirectories', 'bool');

$resolver->setDefault('genericSymlinksBaseDir', null);
$resolver->setAllowedTypes('genericSymlinksBaseDir', ['string', 'null']);
$resolver->setNormalizer('genericSymlinksBaseDir', fn (Options $options, $value) => ! empty($value) ? $value : null);
Expand Down
12 changes: 8 additions & 4 deletions tests/Unit/Task/BaseTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace TYPO3\Surf\Tests\Unit\Task;

use PHPUnit\Framework\Constraint\LogicalNot;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -142,8 +143,11 @@ protected function assertCommandExecuted(string $commandSubstring): void
self::assertThat($this->commands['executed'], new AssertCommandExecuted($commandSubstring));
}

/**
* @return Task
*/
abstract protected function createTask();
protected function assertCommandNotExecuted(string $commandSubstring): void
{
$constraint = new LogicalNot(new AssertCommandExecuted($commandSubstring));
self::assertThat($this->commands['executed'], $constraint);
}

abstract protected function createTask(): Task;
}
14 changes: 14 additions & 0 deletions tests/Unit/Task/Generic/CreateSymlinksTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,23 @@ public function createsSymlinkInConfiguredBasePath(): void
$this->task->execute($this->node, $this->application, $this->deployment, $options);

$this->assertCommandExecuted('cd /home/foobar/data');
$this->assertCommandExecuted('test -e ../media || mkdir -p ../media');
$this->assertCommandExecuted('ln -s ../media media');
}

/**
* @test
*/
public function doNotTryToCreateSymlinksIfOptionIsSetToFalse(): void
{
$options = [
'createNonExistingSharedDirectories' => false
];
$this->task->execute($this->node, $this->application, $this->deployment, $options);

$this->assertCommandNotExecuted('test -e ../media || mkdir -p ../media');
}

/**
* the option "symlinks" is an array of symlinks, the symlinks are created looping through the array
*
Expand Down

0 comments on commit 39cfc03

Please sign in to comment.