Skip to content

Commit

Permalink
Add option for composer outdated (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm authored Oct 11, 2024
1 parent 1962232 commit 03c4fe3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down Expand Up @@ -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)) {
Expand Down
37 changes: 37 additions & 0 deletions tests/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 [
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/outdated_flag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"composer_outdated_flag": 1
}
}
}
9 changes: 9 additions & 0 deletions tests/fixtures/outdated_flag1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extra": {
"violinist": {
"composer_outdated_flag": [
"1",
]
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/outdated_flag2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"composer_outdated_flag": "patch"
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/outdated_flag3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"composer_outdated_flag": ""
}
}
}

0 comments on commit 03c4fe3

Please sign in to comment.