diff --git a/composer.json b/composer.json
index fe93274..1dec2fd 100644
--- a/composer.json
+++ b/composer.json
@@ -31,8 +31,8 @@
"bin/yaml-cli"
],
"scripts": {
- "cs": "phpcs -n --standard=PSR2 src tests/src bin --exclude=Generic.Files.LineLength",
- "cbf": "phpcbf -n --standard=PSR2 src tests/src bin --exclude=Generic.Files.LineLength",
+ "cs": "phpcs -n --standard=PSR2 src tests bin --exclude=Generic.Files.LineLength",
+ "cbf": "phpcbf -n --standard=PSR2 src tests bin --exclude=Generic.Files.LineLength",
"unit": "phpunit",
"lint": [
"find src -name '*.php' -print0 | xargs -0 -n1 php -l",
@@ -48,5 +48,10 @@
"squizlabs/php_codesniffer": "^2.7",
"phpunit/phpunit": "^5.5.4",
"satooshi/php-coveralls": "^1.0"
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.x-dev"
+ }
}
}
diff --git a/composer.lock b/composer.lock
index 282ea00..9a4e676 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "f0f0b7370d03ab3edee6b94fc9147d46",
+ "content-hash": "1f123a5a1e0ac60f3ff0af3e3bea94d7",
"packages": [
{
"name": "dflydev/dot-access-data",
@@ -116,16 +116,16 @@
},
{
"name": "symfony/console",
- "version": "v4.4.4",
+ "version": "v4.4.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
- "reference": "f512001679f37e6a042b51897ed24a2f05eba656"
+ "reference": "4fa15ae7be74e53f6ec8c83ed403b97e23b665e9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/console/zipball/f512001679f37e6a042b51897ed24a2f05eba656",
- "reference": "f512001679f37e6a042b51897ed24a2f05eba656",
+ "url": "https://api.github.com/repos/symfony/console/zipball/4fa15ae7be74e53f6ec8c83ed403b97e23b665e9",
+ "reference": "4fa15ae7be74e53f6ec8c83ed403b97e23b665e9",
"shasum": ""
},
"require": {
@@ -188,11 +188,11 @@
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
- "time": "2020-01-25T12:44:29+00:00"
+ "time": "2020-02-24T13:10:00+00:00"
},
{
"name": "symfony/filesystem",
- "version": "v5.0.4",
+ "version": "v5.0.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
@@ -475,16 +475,16 @@
},
{
"name": "symfony/yaml",
- "version": "v4.4.4",
+ "version": "v4.4.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
- "reference": "cd014e425b3668220adb865f53bff64b3ad21767"
+ "reference": "94d005c176db2080e98825d98e01e8b311a97a88"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/yaml/zipball/cd014e425b3668220adb865f53bff64b3ad21767",
- "reference": "cd014e425b3668220adb865f53bff64b3ad21767",
+ "url": "https://api.github.com/repos/symfony/yaml/zipball/94d005c176db2080e98825d98e01e8b311a97a88",
+ "reference": "94d005c176db2080e98825d98e01e8b311a97a88",
"shasum": ""
},
"require": {
@@ -530,7 +530,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
- "time": "2020-01-21T11:12:16+00:00"
+ "time": "2020-02-03T10:46:43+00:00"
}
],
"packages-dev": [
@@ -785,16 +785,16 @@
},
{
"name": "phpdocumentor/reflection-docblock",
- "version": "5.0.0",
+ "version": "5.1.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
- "reference": "a48807183a4b819072f26e347bbd0b5199a9d15f"
+ "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/a48807183a4b819072f26e347bbd0b5199a9d15f",
- "reference": "a48807183a4b819072f26e347bbd0b5199a9d15f",
+ "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e",
+ "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e",
"shasum": ""
},
"require": {
@@ -834,30 +834,29 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
- "time": "2020-02-09T09:16:15+00:00"
+ "time": "2020-02-22T12:28:44+00:00"
},
{
"name": "phpdocumentor/type-resolver",
- "version": "1.0.1",
+ "version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
- "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9"
+ "reference": "7462d5f123dfc080dfdf26897032a6513644fc95"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9",
- "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9",
+ "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95",
+ "reference": "7462d5f123dfc080dfdf26897032a6513644fc95",
"shasum": ""
},
"require": {
- "php": "^7.1",
+ "php": "^7.2",
"phpdocumentor/reflection-common": "^2.0"
},
"require-dev": {
- "ext-tokenizer": "^7.1",
- "mockery/mockery": "~1",
- "phpunit/phpunit": "^7.0"
+ "ext-tokenizer": "^7.2",
+ "mockery/mockery": "~1"
},
"type": "library",
"extra": {
@@ -881,7 +880,7 @@
}
],
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
- "time": "2019-08-22T18:11:29+00:00"
+ "time": "2020-02-18T18:59:58+00:00"
},
{
"name": "phpspec/prophecy",
@@ -2039,16 +2038,16 @@
},
{
"name": "symfony/config",
- "version": "v4.4.4",
+ "version": "v4.4.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/config.git",
- "reference": "4d3979f54472637169080f802dc82197e21fdcce"
+ "reference": "cbfef5ae91ccd3b06621c18d58cd355c68c87ae9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/config/zipball/4d3979f54472637169080f802dc82197e21fdcce",
- "reference": "4d3979f54472637169080f802dc82197e21fdcce",
+ "url": "https://api.github.com/repos/symfony/config/zipball/cbfef5ae91ccd3b06621c18d58cd355c68c87ae9",
+ "reference": "cbfef5ae91ccd3b06621c18d58cd355c68c87ae9",
"shasum": ""
},
"require": {
@@ -2099,20 +2098,20 @@
],
"description": "Symfony Config Component",
"homepage": "https://symfony.com",
- "time": "2020-01-04T13:00:46+00:00"
+ "time": "2020-02-04T09:32:40+00:00"
},
{
"name": "symfony/event-dispatcher",
- "version": "v4.4.4",
+ "version": "v4.4.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
- "reference": "9e3de195e5bc301704dd6915df55892f6dfc208b"
+ "reference": "4ad8e149799d3128621a3a1f70e92b9897a8930d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9e3de195e5bc301704dd6915df55892f6dfc208b",
- "reference": "9e3de195e5bc301704dd6915df55892f6dfc208b",
+ "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/4ad8e149799d3128621a3a1f70e92b9897a8930d",
+ "reference": "4ad8e149799d3128621a3a1f70e92b9897a8930d",
"shasum": ""
},
"require": {
@@ -2169,7 +2168,7 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
- "time": "2020-01-10T21:54:01+00:00"
+ "time": "2020-02-04T09:32:40+00:00"
},
{
"name": "symfony/event-dispatcher-contracts",
@@ -2231,7 +2230,7 @@
},
{
"name": "symfony/stopwatch",
- "version": "v4.4.4",
+ "version": "v4.4.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/stopwatch.git",
diff --git a/src/Command/GetValueCommand.php b/src/Command/GetValueCommand.php
index a9c992b..e0ed1ce 100644
--- a/src/Command/GetValueCommand.php
+++ b/src/Command/GetValueCommand.php
@@ -40,7 +40,7 @@ protected function configure()
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
- * @return bool
+ * @return int 0 if everything went fine, or an exit code
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@@ -59,5 +59,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$value = $data->get($key);
$output->writeln(trim(Yaml::dump($value)));
+ return 0;
}
}
diff --git a/src/Command/LintCommand.php b/src/Command/LintCommand.php
index 7902fef..a77136c 100644
--- a/src/Command/LintCommand.php
+++ b/src/Command/LintCommand.php
@@ -35,7 +35,7 @@ protected function configure()
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
- * @return bool
+ * @return int 0 if everything went fine, or an exit code
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@@ -49,5 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
$output->writeln("The file $filename contains valid YAML.");
}
+
+ return 0;
}
}
diff --git a/src/Command/UnsetKeyCommand.php b/src/Command/UnsetKeyCommand.php
index 5f55536..36b8839 100644
--- a/src/Command/UnsetKeyCommand.php
+++ b/src/Command/UnsetKeyCommand.php
@@ -40,7 +40,7 @@ protected function configure()
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
- * @return bool
+ * @return int 0 if everything went fine, or an exit code
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@@ -54,6 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$data = new Data($yaml_parsed);
if (!$this->checkKeyExists($data, $key)) {
+ $this->output->writeln("The key '$key' does not exist in $filename.");
return 1;
}
@@ -61,6 +62,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($this->writeYamlFile($filename, $data)) {
$this->output->writeln("The key '$key' was removed from $filename.");
+ return 0;
}
+
+ return 1;
}
}
diff --git a/src/Command/UpdateKeyCommand.php b/src/Command/UpdateKeyCommand.php
index ea16f29..0ea6842 100644
--- a/src/Command/UpdateKeyCommand.php
+++ b/src/Command/UpdateKeyCommand.php
@@ -45,7 +45,7 @@ protected function configure()
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
- * @return bool
+ * @return int 0 if everything went fine, or an exit code
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@@ -60,6 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$data = new Data($yaml_parsed);
if (!$this->checkKeyExists($data, $key)) {
+ $this->output->writeln("The key '$key' does not exist in $filename.");
return 1;
}
@@ -69,6 +70,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($this->writeYamlFile($filename, $data)) {
$this->output->writeln("The key '$key' was changed to '$new_key' in $filename.");
+ return 0;
}
+
+ return 1;
}
}
diff --git a/src/Command/UpdateValueCommand.php b/src/Command/UpdateValueCommand.php
index 64752c6..8a4d644 100644
--- a/src/Command/UpdateValueCommand.php
+++ b/src/Command/UpdateValueCommand.php
@@ -45,7 +45,7 @@ protected function configure()
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
- * @return bool
+ * @return int 0 if everything went fine, or an exit code
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@@ -59,18 +59,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$data = new Data($yaml_parsed);
-
+
$typed_value = $value;
if (strtolower($value) === 'false') {
$typed_value = false;
} elseif (strtolower($value) === 'true') {
$typed_value = true;
}
-
+
$data->set($key, $typed_value);
if ($this->writeYamlFile($filename, $data)) {
$this->output->writeln("The value for key '$key' was set to '$value' in $filename.");
+ return 0;
}
+
+ return 1;
}
}
diff --git a/tests/phpunit/GetValueCommandTest.php b/tests/phpunit/GetValueCommandTest.php
index 1573db5..203beef 100644
--- a/tests/phpunit/GetValueCommandTest.php
+++ b/tests/phpunit/GetValueCommandTest.php
@@ -14,7 +14,7 @@ class GetValueCommandTest extends TestBase
*
* @dataProvider getValueProvider
*/
- public function testGetValue($file, $key, $expected)
+ public function testGetValue($file, $key, $expected_output, $expected_exit_code)
{
$this->application->add(new GetValueCommand());
@@ -27,7 +27,8 @@ public function testGetValue($file, $key, $expected)
));
$output = $commandTester->getDisplay();
- $this->assertContains($expected, $output);
+ $this->assertContains($expected_output, $output);
+ $this->assertEquals($expected_exit_code, $commandTester->getStatusCode());
}
/**
@@ -42,15 +43,15 @@ public function getValueProvider()
$file = 'tests/resources/good.yml';
return [
- [$file, 'not-real', "The key not-real does not exist."],
- ['missing.yml', 'not-real', "The file missing.yml does not exist."],
- [$file, 'deep-array.second.third.fourth', 'hello world'],
+ [$file, 'not-real', "The key not-real does not exist.", 1],
+ ['missing.yml', 'not-real', "The file missing.yml does not exist.", 1],
+ [$file, 'deep-array.second.third.fourth', 'hello world', 0],
[$file, 'flat-array', '- one
- two
-- three'],
+- three', 0],
[$file, 'inline-array', '- one
- two
-- three'],
+- three', 0],
];
}
}
diff --git a/tests/phpunit/LintCommandTest.php b/tests/phpunit/LintCommandTest.php
index a1df639..79e7556 100644
--- a/tests/phpunit/LintCommandTest.php
+++ b/tests/phpunit/LintCommandTest.php
@@ -16,7 +16,7 @@ class LintCommandTest extends TestBase
*
* @dataProvider getValueProvider
*/
- public function testLint($file, $expected)
+ public function testLint($file, $expected_output, $expected_exit_code)
{
$this->application->add(new LintCommand());
@@ -28,7 +28,8 @@ public function testLint($file, $expected)
), ['verbosity' => Output::VERBOSITY_VERBOSE]);
$output = $commandTester->getDisplay();
- $this->assertContains($expected, $output);
+ $this->assertContains($expected_output, $output);
+ $this->assertEquals($expected_exit_code, $commandTester->getStatusCode());
}
/**
@@ -41,9 +42,9 @@ public function getValueProvider()
{
return [
- ['tests/resources/good.yml', "The file tests/resources/good.yml contains valid YAML."],
- ['tests/resources/bad.yml', "There was an error parsing tests/resources/bad.yml. The contents are not valid YAML."],
- ['missing.yml', "The file missing.yml does not exist."],
+ ['tests/resources/good.yml', "The file tests/resources/good.yml contains valid YAML.", 0],
+ ['tests/resources/bad.yml', "There was an error parsing tests/resources/bad.yml. The contents are not valid YAML.", 1],
+ ['missing.yml', "The file missing.yml does not exist.", 1],
];
}
}
diff --git a/tests/phpunit/UnsetKeyCommandTest.php b/tests/phpunit/UnsetKeyCommandTest.php
index ebae582..60dd980 100644
--- a/tests/phpunit/UnsetKeyCommandTest.php
+++ b/tests/phpunit/UnsetKeyCommandTest.php
@@ -27,20 +27,23 @@ public function setUp()
*
* @dataProvider getValueProvider
*/
- public function testUnsetKey($filename, $key, $expected) {
+ public function testUnsetKey($filename, $key, $expected_output, $expected_exit_code)
+ {
$commandTester = $this->runCommand($filename, $key);
$output = $commandTester->getDisplay();
- $this->assertContains($expected, $output);
+ $this->assertContains($expected_output, $output);
$contents = $this->getCommand()->loadYamlFile($filename);
$data = new Data($contents);
$this->assertNotTrue($data->has($key), "The file $filename contains the old key $key. It should not.");
+ $this->assertEquals($expected_exit_code, $commandTester->getStatusCode());
}
/**
* Tests that passing a missing file outputs expected error.
*/
- public function testMissingFile() {
+ public function testMissingFile()
+ {
$commandTester = $this->runCommand('missing.yml', 'not-real');
$this->assertContains("The file missing.yml does not exist.", $commandTester->getDisplay());
}
@@ -50,7 +53,8 @@ public function testMissingFile() {
*
* @return UnsetKeyCommand
*/
- protected function getCommand() {
+ protected function getCommand()
+ {
$this->application->add(new UnsetKeyCommand());
$command = $this->application->find('unset:key');
@@ -67,7 +71,8 @@ protected function getCommand() {
*
* @return \Symfony\Component\Console\Tester\CommandTester
*/
- protected function runCommand($filename, $key) {
+ protected function runCommand($filename, $key)
+ {
$command = $this->getCommand();
$commandTester = new CommandTester($command);
$commandTester->execute(array(
@@ -87,16 +92,14 @@ protected function runCommand($filename, $key) {
*/
public function getValueProvider()
{
-
$filename = 'tests/resources/temp.yml';
return [
- [$filename, 'deep-array.second.third.fourth', "The key 'deep-array.second.third.fourth' was removed from $filename."],
- [$filename, 'flat-array.0', "The key 'flat-array.0' was removed from $filename."],
- [$filename, 'inline-array.0', "The key 'inline-array.0' was removed from $filename."],
- // @todo Uncomment after this is merged:
- // https://github.com/dflydev/dflydev-dot-access-data/pull/7
- // [$filename, 'null-value', "The key 'null-value' was removed from $filename."],
+ [$filename, 'deep-array.second.third.fourth', "The key 'deep-array.second.third.fourth' was removed from $filename.", 0],
+ [$filename, 'flat-array.0', "The key 'flat-array.0' was removed from $filename.", 0],
+ [$filename, 'inline-array.0', "The key 'inline-array.0' was removed from $filename.", 0],
+ [$filename, 'null-value', "The key 'null-value' was removed from $filename.", 0],
+ [$filename, 'fake-value', "The key 'fake-value' does not exist in $filename.", 1],
];
}
}
diff --git a/tests/phpunit/UpdateKeyCommandTest.php b/tests/phpunit/UpdateKeyCommandTest.php
index 5a6a476..8dab9ef 100644
--- a/tests/phpunit/UpdateKeyCommandTest.php
+++ b/tests/phpunit/UpdateKeyCommandTest.php
@@ -28,26 +28,36 @@ public function setUp()
*
* @dataProvider getValueProvider
*/
- public function testUpdateKey($file, $key, $new_key, $expected) {
+ public function testUpdateKey($file, $key, $new_key, $expected_output, $expected_exit_code)
+ {
$contents = $this->getCommand()->loadYamlFile($file);
$data = new Data($contents);
$value = $data->get($key);
$commandTester = $this->runCommand($file, $key, $new_key);
$output = $commandTester->getDisplay();
- $this->assertContains($expected, $output);
+ $this->assertContains($expected_output, $output);
+ $this->assertEquals($expected_exit_code, $commandTester->getStatusCode());
- $contents = $this->getCommand()->loadYamlFile($file);
- $data = new Data($contents);
- $this->assertTrue($data->has($new_key), "The file $file does not contain the new key $new_key. It should.");
- $this->assertNotTrue($data->has($key), "The file $file contains the old key $key. It should not.");
- $this->assertEquals($value, $data->get($new_key), "The value of key $new_key does not equal the value of the original key $key");
+ // If we expected the command to be successful, test the file contents.
+ if (!$expected_exit_code) {
+ $contents = $this->getCommand()->loadYamlFile($file);
+ $data = new Data($contents);
+ $this->assertTrue($data->has($new_key), "The file $file does not contain the new key $new_key. It should.");
+ $this->assertNotTrue($data->has($key), "The file $file contains the old key $key. It should not.");
+ $this->assertEquals(
+ $value,
+ $data->get($new_key),
+ "The value of key $new_key does not equal the value of the original key $key"
+ );
+ }
}
/**
* Tests that passing a missing file outputs expected error.
*/
- public function testMissingFile() {
+ public function testMissingFile()
+ {
$commandTester = $this->runCommand('missing.yml', 'not-real', 'still-not-real');
$this->assertContains("The file missing.yml does not exist.", $commandTester->getDisplay());
}
@@ -57,7 +67,8 @@ public function testMissingFile() {
*
* @return UpdateKeyCommand
*/
- protected function getCommand() {
+ protected function getCommand()
+ {
$this->application->add(new UpdateKeyCommand());
$command = $this->application->find('update:key');
@@ -76,7 +87,8 @@ protected function getCommand() {
*
* @return \Symfony\Component\Console\Tester\CommandTester
*/
- protected function runCommand($file, $key, $new_key) {
+ protected function runCommand($file, $key, $new_key)
+ {
$command = $this->getCommand();
$commandTester = new CommandTester($command);
$commandTester->execute(array(
@@ -100,9 +112,10 @@ public function getValueProvider()
$file = 'tests/resources/temp.yml';
return [
- [$file, 'deep-array.second.third.fourth', 'deep-array.second.third.fifth', "The key 'deep-array.second.third.fourth' was changed to 'deep-array.second.third.fifth' in tests/resources/temp.yml."],
- [$file, 'flat-array.0', 'flat-array.10', "The key 'flat-array.0' was changed to 'flat-array.10' in tests/resources/temp.yml."],
- [$file, 'inline-array.0', 'inline-array.10', "The key 'inline-array.0' was changed to 'inline-array.10' in tests/resources/temp.yml."],
+ [$file, 'deep-array.second.third.fourth', 'deep-array.second.third.fifth', "The key 'deep-array.second.third.fourth' was changed to 'deep-array.second.third.fifth' in $file.", 0],
+ [$file, 'flat-array.0', 'flat-array.10', "The key 'flat-array.0' was changed to 'flat-array.10' in $file.", 0],
+ [$file, 'inline-array.0', 'inline-array.10', "The key 'inline-array.0' was changed to 'inline-array.10' in $file.", 0],
+ [$file, 'fake-key', 'new-key', "The key 'fake-key' does not exist in $file.", 1],
];
}
}
diff --git a/tests/phpunit/UpdateValueCommandTest.php b/tests/phpunit/UpdateValueCommandTest.php
index 7b742d4..1d5fe0d 100644
--- a/tests/phpunit/UpdateValueCommandTest.php
+++ b/tests/phpunit/UpdateValueCommandTest.php
@@ -27,7 +27,7 @@ public function setUp()
*
* @dataProvider getValueProvider
*/
- public function testUpdateValue($file, $key, $value, $expected_value, $expected_output)
+ public function testUpdateValue($file, $key, $value, $expected_value, $expected_output, $expected_exit_code)
{
$commandTester = $this->runCommand($file, $key, $value);
$output = $commandTester->getDisplay();
@@ -36,12 +36,14 @@ public function testUpdateValue($file, $key, $value, $expected_value, $expected_
$contents = $this->getCommand()->loadYamlFile($file);
$data = new Data($contents);
$this->assertEquals($expected_value, $data->get($key));
+ $this->assertEquals($expected_exit_code, $commandTester->getStatusCode());
}
/**
* Tests that passing a missing file outputs expected error.
*/
- public function testMissingFile() {
+ public function testMissingFile()
+ {
$commandTester = $this->runCommand('missing.yml', 'not-real', 'still-not-real');
$this->assertContains("The file missing.yml does not exist.", $commandTester->getDisplay());
}
@@ -51,7 +53,8 @@ public function testMissingFile() {
*
* @return UpdateValueCommand
*/
- protected function getCommand() {
+ protected function getCommand()
+ {
$this->application->add(new UpdateValueCommand());
$command = $this->application->find('update:value');
@@ -70,7 +73,8 @@ protected function getCommand() {
*
* @return \Symfony\Component\Console\Tester\CommandTester
*/
- protected function runCommand($file, $key, $value) {
+ protected function runCommand($file, $key, $value)
+ {
$command = $this->getCommand();
$commandTester = new CommandTester($command);
$commandTester->execute(array(
@@ -94,12 +98,12 @@ public function getValueProvider()
$file = 'tests/resources/temp.yml';
return [
- [$file, 'deep-array.second.third.fourth', 'goodbye world', 'goodbye world', "The value for key 'deep-array.second.third.fourth' was set to 'goodbye world' in tests/resources/temp.yml."],
- [$file, 'flat-array.0', 'goodbye world', 'goodbye world', "The value for key 'flat-array.0' was set to 'goodbye world' in tests/resources/temp.yml."],
- [$file, 'inline-array.0', 'goodbye world', 'goodbye world', "The value for key 'inline-array.0' was set to 'goodbye world' in tests/resources/temp.yml."],
- [$file, 'new-key.sub-key', 'hello world', 'hello world', "The value for key 'new-key.sub-key' was set to 'hello world' in tests/resources/temp.yml."],
- [$file, 'boolean.0', 'false', false, "The value for key 'boolean.0' was set to 'false' in tests/resources/temp.yml."],
- [$file, 'boolean.1', 'true', true, "The value for key 'boolean.1' was set to 'true' in tests/resources/temp.yml."],
+ [$file, 'deep-array.second.third.fourth', 'goodbye world', 'goodbye world', "The value for key 'deep-array.second.third.fourth' was set to 'goodbye world' in $file.", 0],
+ [$file, 'flat-array.0', 'goodbye world', 'goodbye world', "The value for key 'flat-array.0' was set to 'goodbye world' in $file.", 0],
+ [$file, 'inline-array.0', 'goodbye world', 'goodbye world', "The value for key 'inline-array.0' was set to 'goodbye world' in $file.", 0],
+ [$file, 'new-key.sub-key', 'hello world', 'hello world', "The value for key 'new-key.sub-key' was set to 'hello world' in $file.", 0],
+ [$file, 'boolean.0', 'false', false, "The value for key 'boolean.0' was set to 'false' in $file.", 0],
+ [$file, 'boolean.1', 'true', true, "The value for key 'boolean.1' was set to 'true' in $file.", 0],
];
}
}