-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from lemberg/feature/206-override-sync-direct…
…ories Allow overriding sync directories source/destination
- Loading branch information
Showing
12 changed files
with
176 additions
and
21 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
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
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
12 changes: 7 additions & 5 deletions
12
docs/base_directory_and_document_root.md → docs/sync_directories_and_document_root.md
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
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
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
--- | ||
|
||
ssh_default_directory: "{{ vagrant.base_directory }}" | ||
ssh_default_directory: "{{ vagrant.destination_directory }}" |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# {{ ansible_managed }} | ||
|
||
# Allow executable app dependencies from Composer to be run from the path. | ||
if [ -n {{ vagrant.base_directory }} -a -f {{ vagrant.base_directory }}/composer.json ] ; then | ||
bin=$(composer config bin-dir --working-dir={{ vagrant.base_directory }} --no-interaction 2>/dev/null) | ||
if [ -n {{ vagrant.destination_directory }} -a -f {{ vagrant.destination_directory }}/composer.json ] ; then | ||
bin=$(composer config bin-dir --working-dir={{ vagrant.destination_directory }} --no-interaction 2>/dev/null) | ||
if [ -n "$bin" ] ; then | ||
export PATH="{{ vagrant.base_directory }}/${bin}:${PATH}" | ||
export PATH="{{ vagrant.destination_directory }}/${bin}:${PATH}" | ||
fi | ||
fi |
35 changes: 35 additions & 0 deletions
35
src/Config/Update/Step/ReplaceBaseDirectoryWithDestinationDirectory.php
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lemberg\Draft\Environment\Config\Update\Step; | ||
|
||
use Lemberg\Draft\Environment\Config\Update\UpdateStepInterface; | ||
|
||
/** | ||
* Replace base directory with destination directory. | ||
*/ | ||
final class ReplaceBaseDirectoryWithDestinationDirectory extends AbstractUpdateStep implements UpdateStepInterface { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getWeight(): int { | ||
return 4; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function update(array &$config): void { | ||
$config['vagrant']['source_directory'] = '.'; | ||
$config['vagrant']['destination_directory'] = $config['vagrant']['base_directory'] ?? '/var/www/draft'; | ||
unset($config['vagrant']['base_directory']); | ||
|
||
// Replace the default SSH directory setting as well. | ||
if (array_key_exists('ssh_default_directory', $config)) { | ||
$config['ssh_default_directory'] = str_replace('base_directory', 'destination_directory', $config['ssh_default_directory']); | ||
} | ||
} | ||
|
||
} |
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
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
110 changes: 110 additions & 0 deletions
110
tests/Unit/Config/Update/Step/ReplaceBaseDirectoryWithDestinationDirectoryTest.php
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,110 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lemberg\Tests\Unit\Draft\Environment\Config\Update\Step; | ||
|
||
use Composer\Composer; | ||
use Composer\Config as ComposerConfig; | ||
use Composer\IO\IOInterface; | ||
use Lemberg\Draft\Environment\Config\Config; | ||
use Lemberg\Draft\Environment\Config\Manager\UpdateManager; | ||
use Lemberg\Draft\Environment\Config\Update\Step\ReplaceBaseDirectoryWithDestinationDirectory; | ||
use Lemberg\Draft\Environment\Utility\Filesystem; | ||
use org\bovigo\vfs\vfsStream; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Tests replacing base directory with destination directory update step. | ||
* | ||
* @covers \Lemberg\Draft\Environment\Config\Update\Step\AbstractUpdateStep | ||
* @covers \Lemberg\Draft\Environment\Config\Update\Step\ReplaceBaseDirectoryWithDestinationDirectory | ||
*/ | ||
final class ReplaceBaseDirectoryWithDestinationDirectoryTest extends TestCase { | ||
|
||
/** | ||
* @var \Composer\Composer | ||
*/ | ||
private $composer; | ||
|
||
/** | ||
* @var \Composer\IO\IOInterface | ||
*/ | ||
private $io; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $root; | ||
|
||
/** | ||
* @var \Lemberg\Draft\Environment\Config\Manager\UpdateManagerInterface | ||
*/ | ||
private $configUpdateManager; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp(): void { | ||
$this->composer = new Composer(); | ||
$this->composer->setConfig(new ComposerConfig()); | ||
$this->io = $this->createMock(IOInterface::class); | ||
|
||
// Mock source and target configuration directories. | ||
$this->root = vfsStream::setup()->url(); | ||
$fs = new Filesystem(); | ||
$fs->mkdir(["$this->root/source", "$this->root/target"]); | ||
|
||
$configObject = new Config("$this->root/source", "$this->root/target"); | ||
$this->configUpdateManager = new UpdateManager($this->composer, $this->io, $configObject); | ||
} | ||
|
||
/** | ||
* Tests step weight getter. | ||
*/ | ||
final public function testGetWeight(): void { | ||
$step = new ReplaceBaseDirectoryWithDestinationDirectory($this->composer, $this->io, $this->configUpdateManager); | ||
self::assertSame(4, $step->getWeight()); | ||
} | ||
|
||
/** | ||
* Tests update step execution. | ||
* | ||
* @param array<string,mixed> $config | ||
* @param array<string,mixed> $expectedConfig | ||
* | ||
* @dataProvider updateDataProvider | ||
*/ | ||
final public function testUpdate(array $config, array $expectedConfig): void { | ||
$step = new ReplaceBaseDirectoryWithDestinationDirectory($this->composer, $this->io, $this->configUpdateManager); | ||
|
||
$step->update($config); | ||
self::assertSame($config, $expectedConfig); | ||
} | ||
|
||
/** | ||
* Data provider for the ::testUpdate(). | ||
* | ||
* @return array<int,array<int,string|array<string,mixed>>> | ||
*/ | ||
final public function updateDataProvider(): array { | ||
return [ | ||
[ | ||
[ | ||
'vagrant' => [ | ||
'base_directory' => '/var/www/draft', | ||
], | ||
'ssh_default_directory' => '{{ vagrant.base_directory }}', | ||
], | ||
[ | ||
'vagrant' => [ | ||
'source_directory' => '.', | ||
'destination_directory' => '/var/www/draft', | ||
], | ||
'ssh_default_directory' => '{{ vagrant.destination_directory }}', | ||
], | ||
], | ||
]; | ||
} | ||
|
||
} |