-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Skpr plugin Signed-off-by: Karl Hepworth <[email protected]> * Quick fixes Signed-off-by: Karl Hepworth <[email protected]> Signed-off-by: Karl Hepworth <[email protected]>
- Loading branch information
1 parent
399bd23
commit 49ec2b9
Showing
4 changed files
with
147 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,28 @@ | ||
<?php | ||
|
||
namespace Consolidation\SiteProcess\Factory; | ||
|
||
use Consolidation\SiteAlias\SiteAliasInterface; | ||
use Consolidation\SiteProcess\Transport\SkprTransport; | ||
|
||
/** | ||
* SkprTransportFactory will create an SkprTransport for applicable site aliases. | ||
*/ | ||
class SkprTransportFactory implements TransportFactoryInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function check(SiteAliasInterface $siteAlias) | ||
{ | ||
return $siteAlias->has('skpr'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function create(SiteAliasInterface $siteAlias) | ||
{ | ||
return new SkprTransport($siteAlias); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Consolidation\SiteProcess\Transport; | ||
|
||
use Consolidation\SiteProcess\SiteProcess; | ||
use Consolidation\SiteAlias\SiteAliasInterface; | ||
use Consolidation\SiteProcess\Util\Shell; | ||
|
||
/** | ||
* SkprTransport knows how to wrap a command to run on a site hosted | ||
* on the Skpr platform. | ||
*/ | ||
class SkprTransport implements TransportInterface | ||
{ | ||
|
||
/** @var \Consolidation\SiteAlias\SiteAliasInterface */ | ||
protected $siteAlias; | ||
|
||
public function __construct(SiteAliasInterface $siteAlias) | ||
{ | ||
$this->siteAlias = $siteAlias; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function configure(SiteProcess $process) | ||
{ | ||
$path = $this->siteAlias->getDefault('skpr.path', getcwd()); | ||
if ($path) { | ||
$process->chdirToSiteRoot($path); | ||
} | ||
} | ||
|
||
/** | ||
* inheritdoc | ||
*/ | ||
public function wrap($args) | ||
{ | ||
$environment = $this->siteAlias->get('skpr.env'); | ||
|
||
$transport = [ | ||
'skpr', | ||
'exec', | ||
"$environment", | ||
]; | ||
$transport[] = "--"; | ||
|
||
return array_merge($transport, $args); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function addChdir($cd_remote, $args) | ||
{ | ||
return array_merge( | ||
[ | ||
'cd', | ||
$cd_remote, | ||
Shell::op('&&'), | ||
], | ||
$args | ||
); | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace Consolidation\SiteProcess; | ||
|
||
use Consolidation\SiteProcess\Transport\SkprTransport; | ||
use PHPUnit\Framework\TestCase; | ||
use Consolidation\SiteAlias\SiteAlias; | ||
|
||
class SkprTransportTest extends TestCase | ||
{ | ||
/** | ||
* Data provider for testWrap. | ||
*/ | ||
public function wrapTestValues() | ||
{ | ||
return [ | ||
// Everything explicit. | ||
[ | ||
'skpr exec dev -- ls', | ||
['ls'], | ||
[ | ||
'skpr' => [ | ||
'env' => 'dev', | ||
] | ||
], | ||
], | ||
|
||
// Ensure we aren't escaping arguments after "--" | ||
[ | ||
'skpr exec dev -- monday "tuesday" \'wednesday\'', | ||
['monday', '"tuesday"', "'wednesday'"], | ||
[ | ||
'skpr' => [ | ||
'env' => 'dev' | ||
] | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider wrapTestValues | ||
*/ | ||
public function testWrap($expected, $args, $siteAliasData) | ||
{ | ||
$siteAlias = new SiteAlias($siteAliasData, '@alias.dev'); | ||
$dockerTransport = new SkprTransport($siteAlias); | ||
$actual = $dockerTransport->wrap($args); | ||
$this->assertEquals($expected, implode(' ', $actual)); | ||
} | ||
} |