diff --git a/README.md b/README.md
index 9f5226d..68b153a 100644
--- a/README.md
+++ b/README.md
@@ -144,6 +144,8 @@ In order to use psh as a script executor, you need to define the locations in wh
PSH will then search in all these locations for `*.sh` files. These scripts can then be executed through PSH.
+> Notice: If the script name starts with a dot (`.`) it will be excluded from the listing, but is callable like any other script. `> psh.phar .hidden-action`
+
#### Placeholders
Placeholders in your scripts looks like this:
@@ -276,6 +278,15 @@ A environment called `foo` may look like this:
This environment loads all scripts from `foo/sh/scripts` and `bar/sh/scripts`, adds a constant `TEST` and a variable `ID`.
If you want to call a script in this environment you have to prefix your call with `foo:`.
+In order to exclude a whole environment from the listing add the `hidden` attribute to the environment tag and set it to `true`, like this:
+
+```xml
+
+ internal/only/scripts
+
+```
+
+These scripts can be executed like any regular script, they will just not be shown in the listing.
#### Headers
diff --git a/resource/config.xsd b/resource/config.xsd
index 184f47a..eb993f3 100644
--- a/resource/config.xsd
+++ b/resource/config.xsd
@@ -22,6 +22,7 @@
+
diff --git a/src/Application/Application.php b/src/Application/Application.php
index cc7e420..bf19dca 100644
--- a/src/Application/Application.php
+++ b/src/Application/Application.php
@@ -103,7 +103,7 @@ public function run(array $inputArgs): int
return self::RESULT_ERROR;
}
- $this->showListing($scriptFinder->getAllScripts());
+ $this->showListing($scriptFinder->getAllVisibleScripts());
return self::RESULT_SUCCESS;
}
@@ -245,7 +245,7 @@ private function showAutocompleteListing(Config $config)
$scriptFinder = $this->applicationFactory
->createScriptFinder($config);
- $scripts = $scriptFinder->getAllScripts();
+ $scripts = $scriptFinder->getAllVisibleScripts();
$commands = array_map(function (Script $script) {
return $script->getName();
diff --git a/src/Application/ApplicationFactory.php b/src/Application/ApplicationFactory.php
index fa29be2..031691d 100644
--- a/src/Application/ApplicationFactory.php
+++ b/src/Application/ApplicationFactory.php
@@ -36,6 +36,7 @@ class ApplicationFactory
*/
public function createConfig(string $rootDirectory, array $params): Config
{
+ $overwrittenConsts = (new ParameterParser())->parseParams($params);
$configFinder = new ConfigFileFinder();
$configFiles = $configFinder->discoverFiles($rootDirectory);
@@ -51,7 +52,7 @@ public function createConfig(string $rootDirectory, array $params): Config
continue;
}
- $configs[] = $configLoader->load($configFile, $this->reformatParams($params));
+ $configs[] = $configLoader->load($configFile, $overwrittenConsts);
}
}
@@ -114,45 +115,6 @@ public function createCommands(Script $script, ScriptFinder $scriptFinder): arra
return $scriptLoader->loadScript($script);
}
- /**
- * @param array $params
- * @return array
- */
- private function reformatParams(array $params): array
- {
- if (count($params) < 2) {
- return [];
- }
-
- $reformattedParams = [];
- $paramsCount = count($params);
- for ($i = 2; $i < $paramsCount; $i++) {
- $key = $params[$i];
-
- if (strpos($key, '--') !== 0) {
- throw new InvalidParameterException(
- sprintf('Unable to parse parameter %s. Use -- for correct usage', $key)
- );
- }
-
- if (strpos($key, '=')) {
- list($key, $value) = explode('=', $key, 2);
-
- if (strpos($value, '"') === 0) {
- $value = substr($value, 1, -1);
- }
- } else {
- $i++;
- $value = $params[$i];
- }
-
- $key = str_replace('--', '', $key);
- $reformattedParams[strtoupper($key)] = $value;
- }
-
- return $reformattedParams;
- }
-
/**
* @param $directory
* @return array
diff --git a/src/Application/ParameterParser.php b/src/Application/ParameterParser.php
new file mode 100644
index 0000000..774ae37
--- /dev/null
+++ b/src/Application/ParameterParser.php
@@ -0,0 +1,73 @@
+testParameterFormat($key);
+
+ if ($this->isKeyValuePair($key)) {
+ list($key, $value) = explode('=', $key, 2);
+
+ if ($this->isEnclosedInAmpersand($value)) {
+ $value = substr($value, 1, -1);
+ }
+ } else {
+ $i++;
+ $value = $params[$i];
+ }
+
+ $key = str_replace('--', '', $key);
+ $reformattedParams[strtoupper($key)] = $value;
+ }
+
+ return $reformattedParams;
+ }
+
+ /**
+ * @param $key
+ */
+ private function testParameterFormat(string $key)
+ {
+ if (strpos($key, '--') !== 0) {
+ throw new InvalidParameterException(
+ sprintf('Unable to parse parameter %s. Use -- for correct usage', $key)
+ );
+ }
+ }
+
+ /**
+ * @param $key
+ * @return bool|int
+ */
+ private function isKeyValuePair($key)
+ {
+ return strpos($key, '=');
+ }
+
+ /**
+ * @param $value
+ * @return bool
+ */
+ private function isEnclosedInAmpersand($value): bool
+ {
+ return strpos($value, '"') === 0;
+ }
+}
diff --git a/src/Config/Config.php b/src/Config/Config.php
index e1d06fd..b76c15c 100644
--- a/src/Config/Config.php
+++ b/src/Config/Config.php
@@ -55,9 +55,9 @@ public function getAllScriptsPaths(): array
foreach ($this->environments as $name => $environmentConfig) {
foreach ($environmentConfig->getAllScriptsPaths() as $path) {
if ($name !== $this->defaultEnvironment) {
- $paths[] = new ScriptsPath($path, $name);
+ $paths[] = new ScriptsPath($path, $environmentConfig->isHidden(), $name);
} else {
- $paths[] = new ScriptsPath($path);
+ $paths[] = new ScriptsPath($path, false);
}
}
}
@@ -173,7 +173,7 @@ private function createResult(callable ...$valueProviders): array
*/
private function getEnvironment(string $name = null): ConfigEnvironment
{
- if (!$name) {
+ if ($name === null) {
return $this->environments[$this->defaultEnvironment];
}
diff --git a/src/Config/ConfigBuilder.php b/src/Config/ConfigBuilder.php
index ff2b0b1..6c124ce 100644
--- a/src/Config/ConfigBuilder.php
+++ b/src/Config/ConfigBuilder.php
@@ -27,6 +27,8 @@ class ConfigBuilder
private $currentConstants;
+ private $hidden;
+
/**
* @param string|null $header
* @return ConfigBuilder
@@ -44,7 +46,7 @@ public function setHeader(string $header = null): ConfigBuilder
public function start(string $environment = null): ConfigBuilder
{
$this->reset();
- if (!$environment) {
+ if ($environment === null) {
$environment = self::DEFAULT_ENV;
}
@@ -52,6 +54,16 @@ public function start(string $environment = null): ConfigBuilder
return $this;
}
+ /**
+ * @param bool $set
+ * @return ConfigBuilder
+ */
+ public function setHidden(bool $set): ConfigBuilder
+ {
+ $this->hidden = $set;
+ return $this;
+ }
+
/**
* @param array $commandPaths
* @return ConfigBuilder
@@ -146,6 +158,7 @@ private function reset()
{
if ($this->currentEnvironment) {
$this->environments[$this->currentEnvironment] = new ConfigEnvironment(
+ $this->hidden,
$this->currentCommandPaths,
$this->currentDynamicVariables,
$this->currentConstants,
@@ -159,5 +172,6 @@ private function reset()
$this->currentDynamicVariables = [];
$this->currentConstants = [];
$this->templates = [];
+ $this->hidden = false;
}
}
diff --git a/src/Config/ConfigEnvironment.php b/src/Config/ConfigEnvironment.php
index 8ea70ec..dee4451 100644
--- a/src/Config/ConfigEnvironment.php
+++ b/src/Config/ConfigEnvironment.php
@@ -8,6 +8,11 @@
*/
class ConfigEnvironment
{
+ /**
+ * @var bool
+ */
+ private $hidden;
+
/**
* @var array
*/
@@ -39,14 +44,17 @@ class ConfigEnvironment
* @param array $constants
* @param array $templates
* @param array $dotenvPaths
+ * @param bool $hidden
*/
public function __construct(
+ bool $hidden,
array $commandPaths = [],
array $dynamicVariables = [],
array $constants = [],
array $templates = [],
array $dotenvPaths = []
) {
+ $this->hidden = $hidden;
$this->commandPaths = $commandPaths;
$this->dynamicVariables = $dynamicVariables;
$this->constants = $constants;
@@ -54,6 +62,14 @@ public function __construct(
$this->dotenvPaths = $dotenvPaths;
}
+ /**
+ * @return bool
+ */
+ public function isHidden(): bool
+ {
+ return $this->hidden;
+ }
+
/**
* @return array
*/
diff --git a/src/Config/ConfigFileFinder.php b/src/Config/ConfigFileFinder.php
index fdcbde5..d1654e6 100644
--- a/src/Config/ConfigFileFinder.php
+++ b/src/Config/ConfigFileFinder.php
@@ -28,7 +28,7 @@ public function findFirstDirectoryWithConfigFile(string $fromDirectory): array
do {
$globResult = glob($currentDirectory . '/' . self::VALID_FILE_NAME_GLOB);
- if ($globResult) {
+ if (is_array($globResult) && count($globResult) > 0) {
return $globResult;
}
@@ -66,7 +66,7 @@ public function determineResultInDirectory(array $globResult): array
return $extension !== 'override' && $extension !== 'dist';
});
- if ($configFiles) {
+ if (count($configFiles) > 0) {
return array_merge($configFiles, $overrideFiles);
}
diff --git a/src/Config/ConfigMerger.php b/src/Config/ConfigMerger.php
index ef21f84..5c0f020 100644
--- a/src/Config/ConfigMerger.php
+++ b/src/Config/ConfigMerger.php
@@ -42,21 +42,41 @@ public function merge(Config $config, Config $override = null): Config
private function mergeConfigEnvironments(Config $config, Config $override): array
{
$environments = [];
- foreach ($override->getEnvironments() as $name => $overrideEnv) {
- $originalConfigEnv = $config->getEnvironments()[$name];
-
- $environments[$name] = new ConfigEnvironment(
- $this->overrideScriptsPaths($originalConfigEnv, $overrideEnv),
- $this->mergeDynamicVariables($config->getEnvironments()[$name], $overrideEnv),
- $this->mergeConstants($config->getEnvironments()[$name], $overrideEnv),
- $this->overrideTemplates($config->getEnvironments()[$name], $overrideEnv),
- $this->mergeDotenvPaths($originalConfigEnv, $overrideEnv)
- );
+
+ $foundEnvironments = array_keys(array_merge($config->getEnvironments(), $override->getEnvironments()));
+
+ foreach ($foundEnvironments as $name) {
+ if (!isset($override->getEnvironments()[$name])) {
+ $environments[$name] = $config->getEnvironments()[$name];
+
+ continue;
+ }
+
+ if (!isset($config->getEnvironments()[$name])) {
+ $environments[$name] = $override->getEnvironments()[$name];
+
+ continue;
+ }
+
+ $environments[$name] = $this
+ ->mergeEnvironments($config->getEnvironments()[$name], $override->getEnvironments()[$name]);
}
return $environments;
}
+ private function mergeEnvironments(ConfigEnvironment $original, ConfigEnvironment $override): ConfigEnvironment
+ {
+ return new ConfigEnvironment(
+ $this->overrideHidden($original, $override),
+ $this->overrideScriptsPaths($original, $override),
+ $this->mergeDynamicVariables($original, $override),
+ $this->mergeConstants($original, $override),
+ $this->overrideTemplates($original, $override),
+ $this->mergeDotenvPaths($original, $override)
+ );
+ }
+
/**
* @param ConfigEnvironment $configEnvironment
* @param ConfigEnvironment $overrideEnv
@@ -114,4 +134,13 @@ private function overrideTemplates(ConfigEnvironment $configEnvironment, ConfigE
return $configEnvironment->getTemplates();
}
+
+ private function overrideHidden(ConfigEnvironment $originalConfigEnv, ConfigEnvironment $overrideEnv): bool
+ {
+ if ($overrideEnv->isHidden()) {
+ return true;
+ }
+
+ return $originalConfigEnv->isHidden();
+ }
}
diff --git a/src/Config/ScriptsPath.php b/src/Config/ScriptsPath.php
index 6540a30..1e5f650 100644
--- a/src/Config/ScriptsPath.php
+++ b/src/Config/ScriptsPath.php
@@ -8,18 +8,29 @@ class ScriptsPath
* @var string
*/
private $namespace;
+
+ /**
+ * @var bool
+ */
+ private $hidden;
+
/**
* @var string
*/
private $path;
/**
- * @param string $namespace
* @param string $path
+ * @param bool $hidden
+ * @param string $namespace
*/
- public function __construct(string $path, string $namespace = null)
- {
+ public function __construct(
+ string $path,
+ bool $hidden,
+ string $namespace = null
+ ) {
$this->namespace = $namespace;
+ $this->hidden = $hidden;
$this->path = $path;
}
@@ -38,4 +49,20 @@ public function getPath(): string
{
return $this->path;
}
+
+ /**
+ * @return bool
+ */
+ public function isHidden(): bool
+ {
+ return $this->hidden;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isValid(): bool
+ {
+ return is_dir($this->path);
+ }
}
diff --git a/src/Config/XmlConfigFileLoader.php b/src/Config/XmlConfigFileLoader.php
index 47d981d..2727a2b 100644
--- a/src/Config/XmlConfigFileLoader.php
+++ b/src/Config/XmlConfigFileLoader.php
@@ -80,6 +80,7 @@ public function load(string $file, array $params): Config
foreach ($environments as $node) {
$this->configBuilder->start($node->getAttribute('name'));
+ $this->configBuilder->setHidden('true' === $node->getAttribute('hidden'));
$this->setConfigData($file, $node);
}
diff --git a/src/Listing/Script.php b/src/Listing/Script.php
index 58f10af..32d6411 100644
--- a/src/Listing/Script.php
+++ b/src/Listing/Script.php
@@ -28,18 +28,30 @@ class Script
*/
public $description;
+ /**
+ * @var bool
+ */
+ private $inHiddenPath;
+
/**
* @param string $directory
* @param string $scriptName
+ * @param bool $inHiddenPath
* @param string $environment
* @param string $description
*/
- public function __construct(string $directory, string $scriptName, string $environment = null, $description = '')
- {
+ public function __construct(
+ string $directory,
+ string $scriptName,
+ bool $inHiddenPath,
+ string $environment = null,
+ $description = ''
+ ) {
$this->directory = $directory;
$this->scriptName = $scriptName;
$this->environment = $environment;
$this->description = $description;
+ $this->inHiddenPath = $inHiddenPath;
}
/**
@@ -96,4 +108,12 @@ public function getDescription(): string
{
return $this->description;
}
+
+ /**
+ * @return bool
+ */
+ public function isHidden(): bool
+ {
+ return $this->inHiddenPath || strpos($this->scriptName, '.') === 0;
+ }
}
diff --git a/src/Listing/ScriptFinder.php b/src/Listing/ScriptFinder.php
index 9950313..1d1e13a 100644
--- a/src/Listing/ScriptFinder.php
+++ b/src/Listing/ScriptFinder.php
@@ -44,24 +44,15 @@ public function getAllScripts(): array
$scripts = [];
foreach ($this->scriptsPaths as $path) {
- if (!is_dir($path->getPath())) {
- throw new ScriptPathNotValidException("The given script path: '{$path->getPath()}' is not a valid directory");
- }
+ $this->testPathValidity($path);
foreach (scandir($path->getPath(), SCANDIR_SORT_ASCENDING) as $fileName) {
- if (strpos($fileName, '.') === 0) {
- continue;
- }
-
- $extension = pathinfo($fileName, PATHINFO_EXTENSION);
-
- if (!in_array($extension, self::VALID_EXTENSIONS, true)) {
+ if (!$this->isValidScript($fileName)) {
continue;
}
$description = $this->scriptDescriptionReader->read($path->getPath() . '/' . $fileName);
-
- $newScript = new Script($path->getPath(), $fileName, $path->getNamespace(), $description);
+ $newScript = new Script($path->getPath(), $fileName, $path->isHidden(), $path->getNamespace(), $description);
$scripts[$newScript->getName()] = $newScript;
}
@@ -70,13 +61,20 @@ public function getAllScripts(): array
return $scripts;
}
+ public function getAllVisibleScripts(): array
+ {
+ return array_filter($this->getAllScripts(), function (Script $script): bool {
+ return !$script->isHidden();
+ });
+ }
+
/**
* @param string $query
* @return array
*/
public function findScriptsByPartialName(string $query): array
{
- $scripts = $this->getAllScripts();
+ $scripts = $this->getAllVisibleScripts();
return array_filter($scripts, function ($key) use ($query) {
return strpos($key, $query) > -1 || levenshtein($key, $query) < 3;
@@ -98,4 +96,25 @@ public function findScriptByName(string $scriptName): Script
throw (new ScriptNotFoundException('Unable to find script named "' . $scriptName . '"'))->setScriptName($scriptName);
}
+
+ /**
+ * @param $fileName
+ * @return bool
+ */
+ private function isValidScript(string $fileName): bool
+ {
+ $extension = pathinfo($fileName, PATHINFO_EXTENSION);
+
+ return in_array($extension, self::VALID_EXTENSIONS, true);
+ }
+
+ /**
+ * @param ScriptsPath $path
+ */
+ private function testPathValidity(ScriptsPath $path)
+ {
+ if (!$path->isValid()) {
+ throw new ScriptPathNotValidException("The given script path: '{$path->getPath()}' is not a valid directory");
+ }
+ }
}
diff --git a/src/ScriptRuntime/Execution/ProcessEnvironment.php b/src/ScriptRuntime/Execution/ProcessEnvironment.php
index fbd5ab4..7e5f673 100644
--- a/src/ScriptRuntime/Execution/ProcessEnvironment.php
+++ b/src/ScriptRuntime/Execution/ProcessEnvironment.php
@@ -9,7 +9,6 @@
use const PATHINFO_BASENAME;
use const PATHINFO_DIRNAME;
use Shopware\Psh\Config\DotenvFile;
-use Shopware\Psh\Config\ScriptsPath;
use Symfony\Component\Process\Process;
/**
@@ -41,7 +40,7 @@ class ProcessEnvironment
* @param array $constants
* @param array $variables
* @param array $templates
- * @param ScriptsPath[] $dotenvPaths
+ * @param DotenvFile[] $dotenvPaths
*/
public function __construct(array $constants, array $variables, array $templates, array $dotenvPaths)
{
diff --git a/src/ScriptRuntime/Execution/ProcessExecutor.php b/src/ScriptRuntime/Execution/ProcessExecutor.php
index 9c48d68..a1b627a 100644
--- a/src/ScriptRuntime/Execution/ProcessExecutor.php
+++ b/src/ScriptRuntime/Execution/ProcessExecutor.php
@@ -117,6 +117,7 @@ private function executeCommand(Command $command, int $index, int $totalCount)
case $command instanceof SynchronusProcessCommand:
$parsedCommand = $this->getParsedShellCommand($command);
$process = $this->environment->createProcess($parsedCommand);
+
$this->setProcessDefaults($process, $command);
$this->logSynchronousProcessStart($command, $index, $totalCount, $parsedCommand);
$this->runProcess($process);
@@ -126,6 +127,7 @@ private function executeCommand(Command $command, int $index, int $totalCount)
case $command instanceof DeferredProcessCommand:
$parsedCommand = $this->getParsedShellCommand($command);
$process = $this->environment->createProcess($parsedCommand);
+
$this->setProcessDefaults($process, $command);
$this->logDeferedStart($command, $index, $totalCount, $parsedCommand);
$this->deferProcess($parsedCommand, $command, $process);
@@ -133,6 +135,7 @@ private function executeCommand(Command $command, int $index, int $totalCount)
break;
case $command instanceof TemplateCommand:
$template = $command->createTemplate();
+
$this->logTemplateStart($command, $index, $totalCount, $template);
$this->renderTemplate($template);
diff --git a/src/ScriptRuntime/ScriptLoader/PshScriptParser.php b/src/ScriptRuntime/ScriptLoader/PshScriptParser.php
index 97d010c..cf59ae9 100644
--- a/src/ScriptRuntime/ScriptLoader/PshScriptParser.php
+++ b/src/ScriptRuntime/ScriptLoader/PshScriptParser.php
@@ -90,7 +90,7 @@ private function createTokenHandler(ScriptLoader $loader): array
self::TOKEN_INCLUDE => function (string $currentLine, int $lineNumber, Script $script) use ($loader): string {
$path = $this->findInclude($script, $this->removeFromStart(self::TOKEN_INCLUDE, $currentLine));
- $includeScript = new Script(pathinfo($path, PATHINFO_DIRNAME), pathinfo($path, PATHINFO_BASENAME));
+ $includeScript = new Script(pathinfo($path, PATHINFO_DIRNAME), pathinfo($path, PATHINFO_BASENAME), false);
$commands = $loader->loadScript($includeScript);
$this->commandBuilder->replaceCommands($commands);
diff --git a/tests/Acceptance/ApplicationTest.php b/tests/Acceptance/ApplicationTest.php
index 91171dd..5b2406b 100644
--- a/tests/Acceptance/ApplicationTest.php
+++ b/tests/Acceptance/ApplicationTest.php
@@ -29,6 +29,17 @@ public function test_application_listing()
$this->assertContains('test:env2', MockWriter::$content);
$this->assertContains('6 script(s) available', MockWriter::$content);
$this->assertNotContains('Duration:', MockWriter::$content);
+ $this->assertNotContains('test:.hidden', MockWriter::$content);
+ }
+
+ public function test_hidden_execution()
+ {
+ $application = new Application(__DIR__ . '/_app');
+ MockWriter::addToApplication($application);
+
+ $exitCode = $application->run(['', 'test:.hidden']);
+
+ $this->assertSimpleScript($exitCode, 'test');
}
public function test_application_execution()
@@ -38,19 +49,7 @@ public function test_application_execution()
$exitCode = $application->run(['', 'simple']);
- $this->assertNoErrorExitCode($exitCode);
- $this->assertContains('ls -al', MockWriter::$content);
- $this->assertContains('Using .psh.xml', MockWriter::$content);
- $this->assertContains('(1/4) Starting', MockWriter::$content);
- $this->assertContains('(2/4) Starting', MockWriter::$content);
- $this->assertContains('(3/4) Starting', MockWriter::$content);
- $this->assertContains('(4/4) Deferring', MockWriter::$content);
- $this->assertContains('WAITING...', MockWriter::$content);
- $this->assertContains('(1/1) Output from', MockWriter::$content);
- $this->assertContains(' echo "prod"', MockWriter::$content);
- $this->assertContains('All commands successfully executed!', MockWriter::$content);
- $this->assertContains('Duration:', MockWriter::$content);
- self::assertStringEqualsFile(__DIR__ . '/_app/result.txt', 'prod');
+ $this->assertSimpleScript($exitCode, 'prod');
}
public function test_environment_application_execution()
@@ -60,17 +59,17 @@ public function test_environment_application_execution()
$exitCode = $application->run(['', 'test:env']);
- $this->assertNoErrorExitCode($exitCode);
- $this->assertContains('ls -al', MockWriter::$content);
- $this->assertContains('Using .psh.xml', MockWriter::$content);
- $this->assertContains('(1/4) Starting', MockWriter::$content);
- $this->assertContains('(2/4) Starting', MockWriter::$content);
- $this->assertContains('(3/4) Starting', MockWriter::$content);
- $this->assertContains('(4/4) Deferring', MockWriter::$content);
- $this->assertContains(' echo "test"', MockWriter::$content);
- $this->assertContains('All commands successfully executed!', MockWriter::$content);
- $this->assertContains('Duration:', MockWriter::$content);
- self::assertStringEqualsFile(__DIR__ . '/_app/result.txt', 'test');
+ $this->assertSimpleScript($exitCode, 'test');
+ }
+
+ public function test_hidden_environment_application_execution()
+ {
+ $application = new Application(__DIR__ . '/_app');
+ MockWriter::addToApplication($application);
+
+ $exitCode = $application->run(['', 'hidden:env']);
+
+ $this->assertSimpleScript($exitCode, 'hidden');
}
public function test_environment_deferred_application_execution()
@@ -245,4 +244,22 @@ private function assertNoErrorExitCode(int $exitCode)
{
$this->assertEquals(0, $exitCode, 'Application errored unexpextedly: ' . MockWriter::$content);
}
+
+ private function assertSimpleScript(int $exitCode, string $envName)
+ {
+ $this->assertNoErrorExitCode($exitCode);
+ $this->assertContains('ls -al', MockWriter::$content);
+ $this->assertContains('Using .psh.xml', MockWriter::$content);
+ $this->assertContains('(1/4) Starting', MockWriter::$content);
+ $this->assertContains('(2/4) Starting', MockWriter::$content);
+ $this->assertContains('(3/4) Starting', MockWriter::$content);
+ $this->assertContains('(4/4) Deferring', MockWriter::$content);
+ $this->assertContains('WAITING...', MockWriter::$content);
+ $this->assertContains('(1/1) Output from', MockWriter::$content);
+ $this->assertContains(' echo "' . $envName . '"', MockWriter::$content);
+ $this->assertContains('All commands successfully executed!', MockWriter::$content);
+ $this->assertContains('Duration:', MockWriter::$content);
+
+ self::assertStringEqualsFile(__DIR__ . '/_app/result.txt', $envName);
+ }
}
diff --git a/tests/Acceptance/_app/.psh.xml b/tests/Acceptance/_app/.psh.xml
index a5c3180..2ca2a18 100644
--- a/tests/Acceptance/_app/.psh.xml
+++ b/tests/Acceptance/_app/.psh.xml
@@ -19,4 +19,11 @@
test
+
+ envpath/
+ envpath2/
+
+ hidden
+
+
diff --git a/tests/Acceptance/_app/envpath/.hidden.sh b/tests/Acceptance/_app/envpath/.hidden.sh
new file mode 100644
index 0000000..394e44c
--- /dev/null
+++ b/tests/Acceptance/_app/envpath/.hidden.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+INCLUDE: ../scripts/simple.sh
\ No newline at end of file
diff --git a/tests/Integration/Listing/ScriptFinderTest.php b/tests/Integration/Listing/ScriptFinderTest.php
index 418e27c..a930b82 100644
--- a/tests/Integration/Listing/ScriptFinderTest.php
+++ b/tests/Integration/Listing/ScriptFinderTest.php
@@ -21,7 +21,7 @@ public function test_script_finder_holds_contract_if_no_paths_present()
public function test_script_finder_finds_scripts_if_one_directory_is_passed()
{
$finder = new ScriptFinder(
- [new ScriptsPath(__DIR__ . '/_scripts')],
+ [$this->createScriptsPath(__DIR__ . '/_scripts')],
new DescriptionReader()
);
@@ -32,19 +32,23 @@ public function test_script_finder_finds_scripts_if_one_directory_is_passed()
public function test_script_finder_finds_scripts_if_two_directories_are_passed_and_filters_noise()
{
$finder = new ScriptFinder(
- [new ScriptsPath(__DIR__ . '/_scripts'), new ScriptsPath(__DIR__ . '/_scripts_with_misc_stuff')],
+ [$this->createScriptsPath(__DIR__ . '/_scripts'), $this->createScriptsPath(__DIR__ . '/_scripts_with_misc_stuff')],
new DescriptionReader()
);
+ $scripts = $finder->getAllScripts();
$this->assertInstanceOf(ScriptFinder::class, $finder);
- $this->assertCount(5, $finder->getAllScripts());
+ $this->assertCount(6, $scripts);
$this->assertContainsOnlyInstancesOf(Script::class, $finder->getAllScripts());
+
+ $this->assertFalse($scripts['test']->isHidden());
+ $this->assertTrue($scripts['.hidden']->isHidden());
}
public function test_script_finder_finds_script_by_name_if_two_directories_are_passed_and_filters_noise()
{
$finder = new ScriptFinder(
- [new ScriptsPath(__DIR__ . '/_scripts'), new ScriptsPath(__DIR__ . '/_scripts_with_misc_stuff')],
+ [$this->createScriptsPath(__DIR__ . '/_scripts'), $this->createScriptsPath(__DIR__ . '/_scripts_with_misc_stuff')],
new DescriptionReader()
);
$this->assertInstanceOf(ScriptFinder::class, $finder);
@@ -57,7 +61,7 @@ public function test_script_finder_finds_script_by_name_if_two_directories_are_p
public function test_script_finder_prefixes_script_names_with_namespace_if_present()
{
$finder = new ScriptFinder(
- [new ScriptsPath(__DIR__ . '/_scripts'), new ScriptsPath(__DIR__ . '/_scripts_with_misc_stuff', 'biz')],
+ [$this->createScriptsPath(__DIR__ . '/_scripts'), $this->createScriptsPath(__DIR__ . '/_scripts_with_misc_stuff', 'biz')],
new DescriptionReader()
);
$this->assertInstanceOf(ScriptFinder::class, $finder);
@@ -70,7 +74,7 @@ public function test_script_finder_prefixes_script_names_with_namespace_if_prese
public function test_script_finder_throws_exception_if_path_is_not_valid()
{
$finder = new ScriptFinder(
- [new ScriptsPath(__DIR__ . '/_scripts_not_valid_directory')],
+ [$this->createScriptsPath(__DIR__ . '/_scripts_not_valid_directory')],
new DescriptionReader()
);
@@ -81,7 +85,7 @@ public function test_script_finder_throws_exception_if_path_is_not_valid()
public function test_script_finder_adds_description_to_script()
{
$finder = new ScriptFinder(
- [new ScriptsPath(__DIR__ . '/_scripts')],
+ [$this->createScriptsPath(__DIR__ . '/_scripts')],
new DescriptionReader()
);
@@ -92,7 +96,7 @@ public function test_script_finder_adds_description_to_script()
public function test_script_finder_finds_partial_name()
{
$finder = new ScriptFinder(
- [new ScriptsPath(__DIR__ . '/_scripts'), new ScriptsPath(__DIR__ . '/_scripts_with_misc_stuff')],
+ [$this->createScriptsPath(__DIR__ . '/_scripts'), $this->createScriptsPath(__DIR__ . '/_scripts_with_misc_stuff')],
new DescriptionReader()
);
@@ -100,4 +104,9 @@ public function test_script_finder_finds_partial_name()
$this->assertCount(2, $finder->findScriptsByPartialName('test'));
$this->assertContainsOnlyInstancesOf(Script::class, $finder->getAllScripts());
}
+
+ private function createScriptsPath(string $path, string $namespace = null): ScriptsPath
+ {
+ return new ScriptsPath($path, false, $namespace);
+ }
}
diff --git a/tests/Integration/ScriptRuntime/ProcessExecutorTest.php b/tests/Integration/ScriptRuntime/ProcessExecutorTest.php
index 94a87cf..1f36f2a 100644
--- a/tests/Integration/ScriptRuntime/ProcessExecutorTest.php
+++ b/tests/Integration/ScriptRuntime/ProcessExecutorTest.php
@@ -36,7 +36,7 @@ protected function tearDown()
public function test_environment_and_export_work()
{
- $script = new Script(__DIR__ . '/_scripts', 'environment.sh');
+ $script = $this->createScript(__DIR__ . '/_scripts', 'environment.sh');
$commands = $this->loadCommands($script);
$logger = new BlackholeLogger();
@@ -55,7 +55,7 @@ public function test_environment_and_export_work()
public function test_root_dir_is_application_directory()
{
- $script = new Script(__DIR__ . '/_scripts', 'root-dir.sh');
+ $script = $this->createScript(__DIR__ . '/_scripts', 'root-dir.sh');
$commands = $this->loadCommands($script);
$logger = new BlackholeLogger();
@@ -74,7 +74,7 @@ public function test_root_dir_is_application_directory()
public function test_template_engine_works_with_template_destinations()
{
- $script = new Script(__DIR__ . '/_scripts', 'root-dir.sh');
+ $script = $this->createScript(__DIR__ . '/_scripts', 'root-dir.sh');
$commands = $this->loadCommands($script);
$logger = new BlackholeLogger();
@@ -98,7 +98,7 @@ public function test_template_engine_works_with_template_destinations()
public function test_executor_recognises_template_commands()
{
- $script = new Script(__DIR__ . '/_scripts', 'template.sh');
+ $script = $this->createScript(__DIR__ . '/_scripts', 'template.sh');
$commands = $this->loadCommands($script);
$logger = new BlackholeLogger();
@@ -116,7 +116,7 @@ public function test_executor_recognises_template_commands()
public function test_non_executable_bash_commands_throw()
{
- $script = new Script(__DIR__ . '/_scripts', 'bash-non-executable.sh');
+ $script = $this->createScript(__DIR__ . '/_scripts', 'bash-non-executable.sh');
$this->expectException(\RuntimeException::class);
$this->loadCommands($script);
@@ -125,7 +125,7 @@ public function test_non_executable_bash_commands_throw()
public function test_non_writable_bash_commands_throw()
{
chmod(__DIR__ . '/_non_writable', 0555);
- $script = new Script(__DIR__ . '/_non_writable', 'bash.sh');
+ $script = $this->createScript(__DIR__ . '/_non_writable', 'bash.sh');
$this->expectException(\RuntimeException::class);
$this->loadCommands($script);
@@ -133,7 +133,7 @@ public function test_non_writable_bash_commands_throw()
public function test_executor_recognises_bash_commands()
{
- $script = new Script(__DIR__ . '/_scripts', 'bash.sh');
+ $script = $this->createScript(__DIR__ . '/_scripts', 'bash.sh');
$commands = $this->loadCommands($script);
$logger = new BlackholeLogger();
@@ -156,7 +156,7 @@ public function test_executor_recognises_bash_commands()
public function test_executor_recognises_secure_bash_commands()
{
- $script = new Script(__DIR__ . '/_scripts', 'better_bash.sh');
+ $script = $this->createScript(__DIR__ . '/_scripts', 'better_bash.sh');
$commands = $this->loadCommands($script);
$logger = new BlackholeLogger();
@@ -180,7 +180,7 @@ public function test_executor_recognises_secure_bash_commands()
public function test_executor_recognises_defered_commands()
{
- $script = new Script(__DIR__ . '/_scripts', 'deferred.sh');
+ $script = $this->createScript(__DIR__ . '/_scripts', 'deferred.sh');
$commands = $this->loadCommands($script);
$this->assertCount(5, $commands);
@@ -220,7 +220,7 @@ public function test_executor_recognises_defered_commands()
public function test_deferred_commands_get_executed_even_with_error_in_between()
{
- $script = new Script(__DIR__ . '/_scripts', 'deferred_with_error.sh');
+ $script = $this->createScript(__DIR__ . '/_scripts', 'deferred_with_error.sh');
$commands = $this->loadCommands($script);
$this->assertCount(4, $commands);
@@ -300,4 +300,9 @@ private function createTemplateEngine(): TemplateEngine
{
return new TemplateEngine();
}
+
+ private function createScript(string $directory, string $scriptName): Script
+ {
+ return new Script($directory, $scriptName, false);
+ }
}
diff --git a/tests/Unit/Application/ApplicationFactoryTest.php b/tests/Unit/Application/ApplicationFactoryTest.php
index e2d0708..7118c30 100644
--- a/tests/Unit/Application/ApplicationFactoryTest.php
+++ b/tests/Unit/Application/ApplicationFactoryTest.php
@@ -3,6 +3,7 @@
namespace Shopware\Psh\Test\Unit\Application;
use Shopware\Psh\Application\ApplicationFactory;
+use Shopware\Psh\Application\ParameterParser;
use Shopware\Psh\Config\Config;
class ApplicationFactoryTest extends \PHPUnit_Framework_TestCase
@@ -16,19 +17,15 @@ public function test_createConfig()
'--filter aaaa',
];
- $factory = $this->getApplicationFactory();
-
- $result = $factory->createConfig(__DIR__ . '/_fixtures/config/.psh.yaml', $testParams);
+ $factory = new ParameterParser();
- $property = $this->getPrivateProperty(Config::class, 'params');
- $result2 = $property->getValue($result);
+ $parsedParams = $factory->parseParams($testParams);
$expectedResult = [
'FILTER' => '--filter aaaa',
];
- $this->assertInstanceOf(Config::class, $result);
- $this->assertEquals($expectedResult, $result2);
+ $this->assertEquals($expectedResult, $parsedParams);
}
public function test_createConfig_with_invalid_config_file()
@@ -50,15 +47,15 @@ public function test_createConfig_with_invalid_config_file()
public function test_reformatParams_expects_exception()
{
- $factory = $this->getApplicationFactory();
- $method = $this->getPrivateMethod(ApplicationFactory::class, 'reformatParams');
+ $paramParser = new ParameterParser();
$this->expectException(\RuntimeException::class);
- $method->invokeArgs($factory, [['./psh', 'unit', 'someFalseParameter']]);
+ $paramParser->parseParams(['./psh', 'unit', 'someFalseParameter']);
}
public function test_reformatParams_expects_array()
{
+ $paramParser = new ParameterParser();
$testParams = [
'./psh',
'unit',
@@ -71,10 +68,8 @@ public function test_reformatParams_expects_array()
'--env6="gh""t=tg"',
];
- $factory = $this->getApplicationFactory();
- $method = $this->getPrivateMethod(ApplicationFactory::class, 'reformatParams');
- $result = $method->invokeArgs($factory, [$testParams]);
+ $result = $paramParser->parseParams($testParams);
$expectedResult = [
'ENV1' => 'dev',
@@ -88,34 +83,6 @@ public function test_reformatParams_expects_array()
$this->assertEquals($expectedResult, $result);
}
- /**
- * @param string $class
- * @param string $method
- * @return \ReflectionMethod
- */
- private function getPrivateMethod(string $class, string $method): \ReflectionMethod
- {
- $reflectionClass = new \ReflectionClass($class);
- $method = $reflectionClass->getMethod($method);
- $method->setAccessible(true);
-
- return $method;
- }
-
- /**
- * @param string $class
- * @param string $property
- * @return \ReflectionProperty
- */
- private function getPrivateProperty(string $class, string $property): \ReflectionProperty
- {
- $reflectionClass = new \ReflectionClass($class);
- $property = $reflectionClass->getProperty($property);
- $property->setAccessible(true);
-
- return $property;
- }
-
/**
* @return ApplicationFactory
*/
diff --git a/tests/Unit/Config/ConfigMergerTest.php b/tests/Unit/Config/ConfigMergerTest.php
index 3e546b8..8170912 100644
--- a/tests/Unit/Config/ConfigMergerTest.php
+++ b/tests/Unit/Config/ConfigMergerTest.php
@@ -53,7 +53,7 @@ public function test_it_should_override_default_environment()
public function test_it_should_use_original_config_if_override_is_empty()
{
- $config = new Config('my header', 'default env', [self::DEFAULT_ENV => new ConfigEnvironment()], []);
+ $config = new Config('my header', 'default env', [self::DEFAULT_ENV => new ConfigEnvironment(false)], []);
$override = new Config('', '', [], []);
$merger = new ConfigMerger();
@@ -61,12 +61,30 @@ public function test_it_should_use_original_config_if_override_is_empty()
$this->assertEquals('my header', $result->getHeader());
$this->assertEquals('default env', $result->getDefaultEnvironment());
- $this->assertEquals([self::DEFAULT_ENV => new ConfigEnvironment()], $result->getEnvironments());
+ $this->assertEquals([self::DEFAULT_ENV => new ConfigEnvironment(false)], $result->getEnvironments());
+ }
+
+ public function test_it_should_add_environment_from_override()
+ {
+ $envs = [self::DEFAULT_ENV => new ConfigEnvironment(false, ['actions'], [], ['foo' => 'bar'])];
+ $newEnv = ['newEnv' => new ConfigEnvironment(false, ['actions'])];
+
+ $config = new Config('', self::DEFAULT_ENV, $envs, []);
+ $override = new Config('', '', $newEnv, []);
+
+ $merger = new ConfigMerger();
+ $mergedConfig = $merger->merge($config, $override);
+
+ $this->assertInstanceOf(Config::class, $mergedConfig);
+
+ $this->assertArrayHasKey(self::DEFAULT_ENV, $mergedConfig->getEnvironments());
+ $this->assertArrayHasKey('newEnv', $mergedConfig->getEnvironments());
+ $this->assertEquals(['foo' => 'bar'], $mergedConfig->getConstants());
}
public function test_it_should_use_original_environments()
{
- $envs = [self::DEFAULT_ENV => new ConfigEnvironment(['actions'])];
+ $envs = [self::DEFAULT_ENV => new ConfigEnvironment(false, ['actions'])];
$config = new Config('', '', $envs, []);
$override = new Config('', '', [], []);
@@ -80,9 +98,9 @@ public function test_it_should_use_original_environments()
public function test_it_should_override_environment_paths()
{
- $envs = [self::DEFAULT_ENV => new ConfigEnvironment(['actions'])];
+ $envs = [self::DEFAULT_ENV => new ConfigEnvironment(false, ['actions'])];
- $overrideEnvs = [self::DEFAULT_ENV => new ConfigEnvironment(['override/actions'])];
+ $overrideEnvs = [self::DEFAULT_ENV => new ConfigEnvironment(false, ['override/actions'])];
$config = new Config('', self::DEFAULT_ENV, $envs, []);
$override = new Config('', self::DEFAULT_ENV, $overrideEnvs, []);
@@ -96,9 +114,9 @@ public function test_it_should_override_environment_paths()
public function test_it_should_override_environment_dynamic_values()
{
- $envs = [self::DEFAULT_ENV => new ConfigEnvironment([], ['DYNAMIC_VAR' => 'dynamic value'])];
+ $envs = [self::DEFAULT_ENV => new ConfigEnvironment(false, [], ['DYNAMIC_VAR' => 'dynamic value'])];
- $overrideEnvs = [self::DEFAULT_ENV => new ConfigEnvironment([], ['DYNAMIC_VAR' => 'dynamic value override'])];
+ $overrideEnvs = [self::DEFAULT_ENV => new ConfigEnvironment(false, [], ['DYNAMIC_VAR' => 'dynamic value override'])];
$config = new Config('', self::DEFAULT_ENV, $envs, []);
$override = new Config('', self::DEFAULT_ENV, $overrideEnvs, []);
@@ -113,9 +131,9 @@ public function test_it_should_override_environment_dynamic_values()
public function test_it_should_add_dynamic_values()
{
- $envs = [self::DEFAULT_ENV => new ConfigEnvironment([], ['DYNAMIC_VAR' => 'dynamic value', 'DYNAMIC_VAR2' => 'dynamic value 2'])];
+ $envs = [self::DEFAULT_ENV => new ConfigEnvironment(false, [], ['DYNAMIC_VAR' => 'dynamic value', 'DYNAMIC_VAR2' => 'dynamic value 2'])];
- $overrideEnvs = [self::DEFAULT_ENV => new ConfigEnvironment([], ['DYNAMIC_VAR' => 'dynamic value override', 'DYNAMIC_OVERRIDE_VAR' => 'dynamic override value'])];
+ $overrideEnvs = [self::DEFAULT_ENV => new ConfigEnvironment(false, [], ['DYNAMIC_VAR' => 'dynamic value override', 'DYNAMIC_OVERRIDE_VAR' => 'dynamic override value'])];
$config = new Config('', self::DEFAULT_ENV, $envs, []);
$override = new Config('', self::DEFAULT_ENV, $overrideEnvs, []);
@@ -133,14 +151,14 @@ public function test_it_should_add_dynamic_values()
public function test_it_should_add_and_override_constant_values()
{
$envs = [
- self::DEFAULT_ENV => new ConfigEnvironment([], [], [
+ self::DEFAULT_ENV => new ConfigEnvironment(false, [], [], [
'CONST' => 'constant value',
'ORIGINAL_CONST' => 'original constant value'
])
];
$overrideEnvs = [
- self::DEFAULT_ENV => new ConfigEnvironment([], [], [
+ self::DEFAULT_ENV => new ConfigEnvironment(false, [], [], [
'CONST' => 'override constant value',
'ADDED_CONST' => 'override constant'
])
@@ -162,13 +180,13 @@ public function test_it_should_add_and_override_constant_values()
public function test_it_should_override_templates()
{
$envs = [
- self::DEFAULT_ENV => new ConfigEnvironment([], [], [], [
+ self::DEFAULT_ENV => new ConfigEnvironment(false, [], [], [], [
[ 'source' => '/tmp/template.tpl', 'destination' => '/tmp/template.php' ]
])
];
$overrideEnvs = [
- self::DEFAULT_ENV => new ConfigEnvironment([], [], [], [
+ self::DEFAULT_ENV => new ConfigEnvironment(false, [], [], [], [
[ 'source' => '/tmp/override.tpl', 'destination' => '/tmp/override.php' ]
])
];
@@ -189,13 +207,13 @@ public function test_dotenv_paths()
{
$configMerge = (new ConfigMerger())->merge(
new Config('', self::DEFAULT_ENV, [
- self::DEFAULT_ENV => new ConfigEnvironment([], [], [], [], [
+ self::DEFAULT_ENV => new ConfigEnvironment(false, [], [], [], [], [
'.a' => 'first/.a',
'.b' => 'first/.b',
])
], []),
new Config('', self::DEFAULT_ENV, [
- self::DEFAULT_ENV => new ConfigEnvironment([], [], [], [], [
+ self::DEFAULT_ENV => new ConfigEnvironment(false, [], [], [], [], [
'.a' => 'overwrite/.a',
'.c' => 'overwrite/.c',
])
@@ -210,4 +228,46 @@ public function test_dotenv_paths()
$this->assertEquals('first/.b', $paths['.b']->getPath());
$this->assertEquals('overwrite/.c', $paths['.c']->getPath());
}
+
+ public function test_hidden_override_with_both_false()
+ {
+ $configMerge = (new ConfigMerger())->merge(
+ new Config('', self::DEFAULT_ENV, [
+ self::DEFAULT_ENV => new ConfigEnvironment(false)
+ ], []),
+ new Config('', self::DEFAULT_ENV, [
+ self::DEFAULT_ENV => new ConfigEnvironment(false)
+ ], [])
+ );
+
+ $this->assertFalse($configMerge->getEnvironments()[$configMerge->getDefaultEnvironment()]->isHidden());
+ }
+
+ public function test_hidden_override_with_hidden_base()
+ {
+ $configMerge = (new ConfigMerger())->merge(
+ new Config('', self::DEFAULT_ENV, [
+ self::DEFAULT_ENV => new ConfigEnvironment(true)
+ ], []),
+ new Config('', self::DEFAULT_ENV, [
+ self::DEFAULT_ENV => new ConfigEnvironment(false)
+ ], [])
+ );
+
+ $this->assertTrue($configMerge->getEnvironments()[$configMerge->getDefaultEnvironment()]->isHidden());
+ }
+
+ public function test_hidden_override_with_hidden_override()
+ {
+ $configMerge = (new ConfigMerger())->merge(
+ new Config('', self::DEFAULT_ENV, [
+ self::DEFAULT_ENV => new ConfigEnvironment(false)
+ ], []),
+ new Config('', self::DEFAULT_ENV, [
+ self::DEFAULT_ENV => new ConfigEnvironment(true)
+ ], [])
+ );
+
+ $this->assertTrue($configMerge->getEnvironments()[$configMerge->getDefaultEnvironment()]->isHidden());
+ }
}
diff --git a/tests/Unit/Config/XmlConfigFileLoaderTest.php b/tests/Unit/Config/XmlConfigFileLoaderTest.php
index 08fefab..aeaa36e 100644
--- a/tests/Unit/Config/XmlConfigFileLoaderTest.php
+++ b/tests/Unit/Config/XmlConfigFileLoaderTest.php
@@ -192,6 +192,27 @@ public function test_environment_paths_do_not_influence_default_environment()
$this->assertEquals('namespace', $scripts[1]->getNamespace());
}
+ public function test_environment_hidden_get_loaded()
+ {
+ $dir = __DIR__;
+
+ $this->writeTempFile(<<$dir/_foo
+
+ $dir/_bar
+
+EOD
+);
+
+ $loader =$this->createConfigLoader();
+ $config = $loader->load(self::TEMP_FILE, []);
+
+ $this->assertTrue($config->getEnvironments()['namespace']->isHidden());
+
+ $this->assertFalse($config->getAllScriptsPaths()[0]->isHidden());
+ $this->assertTrue($config->getAllScriptsPaths()[1]->isHidden());
+ }
+
public function test_it_loads_environment_paths()
{
$dir = __DIR__;
@@ -227,6 +248,7 @@ public function test_it_loads_environment_paths()
$this->assertEquals(__DIR__ . '/_foo', $scripts[0]->getPath());
$this->assertEquals(__DIR__ . '/_bar', $scripts[1]->getPath());
$this->assertEquals('namespace', $scripts[1]->getNamespace());
+ $this->assertFalse($config->getEnvironments()['namespace']->isHidden());
}
public function test_it_loads_environments_with_vars()
diff --git a/tests/Unit/ScriptRuntime/PshScriptParserTest.php b/tests/Unit/ScriptRuntime/PshScriptParserTest.php
index d4c47a7..82c95e5 100644
--- a/tests/Unit/ScriptRuntime/PshScriptParserTest.php
+++ b/tests/Unit/ScriptRuntime/PshScriptParserTest.php
@@ -17,7 +17,7 @@ class PshScriptParserTest extends \PHPUnit_Framework_TestCase
{
public function test_it_loads_all_simple_commands_from_a_script()
{
- $commands = $this->createCommands(new Script(__DIR__ . '/_scripts', 'simple.sh'));
+ $commands = $this->createCommands($this->createScript(__DIR__ . '/_scripts', 'simple.sh'));
$this->assertCount(3, $commands);
$this->assertContainsOnlyInstancesOf(SynchronusProcessCommand::class, $commands);
@@ -30,7 +30,7 @@ public function test_it_loads_all_simple_commands_from_a_script()
public function test_it_concatenates_commands()
{
- $commands = $this->createCommands(new Script(__DIR__ . '/_scripts', 'concatenate.sh'));
+ $commands = $this->createCommands($this->createScript(__DIR__ . '/_scripts', 'concatenate.sh'));
$this->assertCount(2, $commands);
$this->assertContainsOnlyInstancesOf(SynchronusProcessCommand::class, $commands);
@@ -43,7 +43,7 @@ public function test_it_concatenates_commands()
public function test_it_sets_ignore_error()
{
- $commands = $this->createCommands(new Script(__DIR__ . '/_scripts', 'ignore_error.sh'));
+ $commands = $this->createCommands($this->createScript(__DIR__ . '/_scripts', 'ignore_error.sh'));
$this->assertCount(3, $commands);
$this->assertContainsOnlyInstancesOf(SynchronusProcessCommand::class, $commands);
@@ -56,7 +56,7 @@ public function test_it_sets_ignore_error()
public function test_it_sets_tty()
{
- $commands = $this->createCommands(new Script(__DIR__ . '/_scripts', 'tty.sh'));
+ $commands = $this->createCommands($this->createScript(__DIR__ . '/_scripts', 'tty.sh'));
$this->assertCount(1, $commands);
$this->assertContainsOnlyInstancesOf(SynchronusProcessCommand::class, $commands);
@@ -69,7 +69,7 @@ public function test_it_sets_tty()
public function test_includes_with_local_commands()
{
- $commands = $this->createCommands(new Script(__DIR__ . '/_scripts', 'local_include.sh'));
+ $commands = $this->createCommands($this->createScript(__DIR__ . '/_scripts', 'local_include.sh'));
$this->assertCount(8, $commands);
$this->assertContainsOnlyInstancesOf(SynchronusProcessCommand::class, $commands);
@@ -87,14 +87,14 @@ public function test_includes_with_local_commands()
public function test_include_throws_exception()
{
$this->expectException(\RuntimeException::class);
- $this->createCommands(new Script(__DIR__ . '/_scripts', 'exception_include.sh'));
+ $this->createCommands($this->createScript(__DIR__ . '/_scripts', 'exception_include.sh'));
}
public function test_action_with_local_commands()
{
- $commands = $this->createCommands(new Script(__DIR__ . '/_scripts', 'local_action.sh'), [
- new ScriptsPath(__DIR__ . '/_scripts/'),
- new ScriptsPath(__DIR__ . '/_scripts/', 'env'),
+ $commands = $this->createCommands($this->createScript(__DIR__ . '/_scripts', 'local_action.sh'), [
+ new ScriptsPath(__DIR__ . '/_scripts/', false),
+ new ScriptsPath(__DIR__ . '/_scripts/', false, 'env'),
]);
$this->assertCount(8, $commands);
@@ -113,12 +113,12 @@ public function test_action_with_local_commands()
public function test_action_throws_exception()
{
$this->expectException(\RuntimeException::class);
- $this->createCommands(new Script(__DIR__ . '/_scripts', 'exception_action.sh'));
+ $this->createCommands($this->createScript(__DIR__ . '/_scripts', 'exception_action.sh'));
}
public function test_renders_templates_on_demand()
{
- $commands = $this->createCommands(new Script(__DIR__ . '/_scripts', 'template.sh'));
+ $commands = $this->createCommands($this->createScript(__DIR__ . '/_scripts', 'template.sh'));
$this->assertCount(3, $commands);
$this->assertContainsOnlyInstancesOf(Command::class, $commands);
@@ -149,4 +149,9 @@ public function createCommands(Script $script, array $availableSubScripts = []):
return $scriptLoader->loadScript($script);
}
+
+ private function createScript(string $directory, string $scriptName): Script
+ {
+ return new Script($directory, $scriptName, false);
+ }
}
diff --git a/tests/Unit/ScriptRuntime/ScriptLoaderTest.php b/tests/Unit/ScriptRuntime/ScriptLoaderTest.php
index 7c9b4ea..1cb3fe2 100644
--- a/tests/Unit/ScriptRuntime/ScriptLoaderTest.php
+++ b/tests/Unit/ScriptRuntime/ScriptLoaderTest.php
@@ -14,6 +14,6 @@ public function test_no_parser_equals_no_support()
$loader = new ScriptLoader();
$this->expectException(ScriptNotSupportedByParser::class);
- $loader->loadScript(new Script(__DIR__ . '/_scripts', 'empty.txt', ''));
+ $loader->loadScript(new Script(__DIR__ . '/_scripts', 'empty.txt', false, ''));
}
}