diff --git a/src/Config.php b/src/Config.php index f68a519..4f4c56f 100644 --- a/src/Config.php +++ b/src/Config.php @@ -21,6 +21,7 @@ public function getDefaultConfig() 'allow_list' => [], 'update_dev_dependencies' => 1, 'check_only_direct_dependencies' => 1, + 'composer_outdated_flag' => 'minor', 'bundled_packages' => (object) [], 'blocklist' => [], 'assignees' => [], @@ -77,6 +78,22 @@ public function setConfig($config) } } + public function getComposerOutdatedFlag() : string + { + if (empty($this->config->composer_outdated_flag)) { + return 'minor'; + } + $allowed_values = [ + 'major', + 'minor', + 'patch', + ]; + if (!in_array($this->config->composer_outdated_flag, $allowed_values)) { + return 'minor'; + } + return $this->config->composer_outdated_flag; + } + public function getLabels() : array { if (!is_array($this->config->labels)) { diff --git a/tests/UnitTest.php b/tests/UnitTest.php index a42d5fe..cad7977 100644 --- a/tests/UnitTest.php +++ b/tests/UnitTest.php @@ -31,6 +31,17 @@ public function testGetOptionSet($filename, $option, $expected_result) self::assertEquals($data->hasConfigForKey($option), $expected_result); } + /** + * Test the composer_outdated_flag option. + * + * @dataProvider getOutdatedFlag + */ + public function testOutdatedFlag($filename, $expected_result) + { + $data = $this->createDataFromFixture($filename); + self::assertEquals($expected_result, $data->getComposerOutdatedFlag()); + } + /** * Test that getLabels returns the expected things. * @@ -358,6 +369,32 @@ protected function createDataFromFixture($filename) return Config::createFromComposerData($file_contents); } + public static function getOutdatedFlag() : array + { + return [ + [ + 'empty.json', + 'minor', + ], + [ + 'outdated_flag.json', + 'minor', + ], + [ + 'outdated_flag1.json', + 'minor', + ], + [ + 'outdated_flag2.json', + 'patch', + ], + [ + 'outdated_flag3.json', + 'minor', + ], + ]; + } + public function getUpdateWithDeps() { return [ diff --git a/tests/fixtures/outdated_flag.json b/tests/fixtures/outdated_flag.json new file mode 100644 index 0000000..ed81798 --- /dev/null +++ b/tests/fixtures/outdated_flag.json @@ -0,0 +1,7 @@ +{ + "extra": { + "violinist": { + "composer_outdated_flag": 1 + } + } +} diff --git a/tests/fixtures/outdated_flag1.json b/tests/fixtures/outdated_flag1.json new file mode 100644 index 0000000..0cf02a3 --- /dev/null +++ b/tests/fixtures/outdated_flag1.json @@ -0,0 +1,9 @@ +{ + "extra": { + "violinist": { + "composer_outdated_flag": [ + "1", + ] + } + } +} diff --git a/tests/fixtures/outdated_flag2.json b/tests/fixtures/outdated_flag2.json new file mode 100644 index 0000000..588f9ae --- /dev/null +++ b/tests/fixtures/outdated_flag2.json @@ -0,0 +1,7 @@ +{ + "extra": { + "violinist": { + "composer_outdated_flag": "patch" + } + } +} diff --git a/tests/fixtures/outdated_flag3.json b/tests/fixtures/outdated_flag3.json new file mode 100644 index 0000000..cbefa68 --- /dev/null +++ b/tests/fixtures/outdated_flag3.json @@ -0,0 +1,7 @@ +{ + "extra": { + "violinist": { + "composer_outdated_flag": "" + } + } +}