Skip to content

Commit

Permalink
Add config for tags (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm authored Jan 6, 2023
1 parent 43395f5 commit ec510d9
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function getDefaultConfig()
'allow_update_indirect_with_direct' => 0,
'automerge' => 0,
'automerge_security' => 0,
'tags' => [],
'tags_security' => [],
];
}

Expand Down Expand Up @@ -69,6 +71,22 @@ public function setConfig($config)
}
}

public function getTags() : array
{
if (!is_array($this->config->tags)) {
return [];
}
return $this->config->tags;
}

public function getTagsSecurity() : array
{
if (!is_array($this->config->tags_security)) {
return [];
}
return $this->config->tags_security;
}

public function hasConfigForKey($key)
{
return !empty($this->configOptionsSet[$key]);
Expand Down
94 changes: 94 additions & 0 deletions tests/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ public function testGetOptionSet($filename, $option, $expected_result)
self::assertEquals($data->hasConfigForKey($option), $expected_result);
}

/**
* Test that getTags returns the expected things.
*
* @dataProvider getTagsConfig
*/
public function testTags($filename, $expected_result)
{
$this->runTestExpectedResultFromFixture($filename, $expected_result, 'getTags');
}

/**
* Test that getTagsSecurity returns the expected things.
*
* @dataProvider getTagsSecurityConfig
*/
public function testTagsSecurity($filename, $expected_result)
{
$this->runTestExpectedResultFromFixture($filename, $expected_result, 'getTagsSecurity');
}

protected function runTestExpectedResultFromFixture($filename, $expected_result, $method)
{
$data = $this->createDataFromFixture($filename);
self::assertEquals($expected_result, $data->{$method}());
}

/**
* Test the different things we can set in run scripts, and what we expect from it.
*
Expand Down Expand Up @@ -601,6 +627,74 @@ public function getCommitMessage()
];
}

public function getTagsConfig()
{
return [
[
'empty.json',
[],
],
[
'tags.json',
[],
],
[
'tags2.json',
[],
],
[
'tags3.json',
[],
],
[
'tags4.json',
[],
],
[
'tags5.json',
["tag123"],
],
[
'tags6.json',
["tag123", "tag456"],
],
];
}

public function getTagsSecurityConfig()
{
return [
[
'empty.json',
[],
],
[
'tags_security.json',
[],
],
[
'tags_security2.json',
[],
],
[
'tags_security3.json',
[],
],
[
'tags_security4.json',
[],
],
[
'tags_security5.json',
["tag123"],
],
[
'tags_security6.json',
["tag123", "tag456"],
],
];
}

public function getHasConfig()
{
return [
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags": ""
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/tags2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags": 1
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/tags3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags": []
}
}
}
9 changes: 9 additions & 0 deletions tests/fixtures/tags4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extra": {
"violinist": {
"tags": {
"tag1": true
}
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/tags5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags": ["tag123"]
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/tags6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags": ["tag123", "tag456"]
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/tags_security.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags_security": ""
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/tags_security2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags_security": 1
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/tags_security3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags_security": []
}
}
}
9 changes: 9 additions & 0 deletions tests/fixtures/tags_security4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extra": {
"violinist": {
"tags_security": {
"tag1": true
}
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/tags_security5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags_security": ["tag123"]
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/tags_security6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"tags_security": ["tag123", "tag456"]
}
}
}

0 comments on commit ec510d9

Please sign in to comment.