Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3938317
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/app/Analyzers/ItemGroupMapping.php b/app/Analyzers/ItemGroupMapping.php
index 405d228..931f1aa 100644
--- a/app/Analyzers/ItemGroupMapping.php
+++ b/app/Analyzers/ItemGroupMapping.php
@@ -1,60 +1,60 @@
<?php
namespace Nasqueron\Notifications\Analyzers;
/**
* Map items (repositories, projects, items, etc.) names to groups
*/
class ItemGroupMapping {
///
/// Properties
///
/**
* The group the mapped items belong to
*
* @var string
*/
public $group;
/**
* An array of the items to map, each item a string with the name of the
* repository, project or item used for mapping.
* The wildcard '*' is allowed to specify several items.
*
* @var array
*/
- public $items;
+ public $items = [];
///
/// Helper methods
///
/**
* Determines if the specified item matches a pattern.
*
* @param string $pattern The pattern, with * allowed as wildcard character
* @param string $item The item name to compare with the pattern
* @return bool
*/
public static function doesItemMatch (string $pattern, string $item) : bool {
return str_is($pattern, $item);
}
/**
* Determines if the specified item belong to this mapping
*
* @return bool
*/
public function doesItemBelong (string $actualItem) : bool {
foreach ($this->items as $candidateItem) {
if (static::doesItemMatch($candidateItem, $actualItem)) {
return true;
}
}
return false;
}
}
diff --git a/tests/Analyzers/ItemGroupMappingTest.php b/tests/Analyzers/ItemGroupMappingTest.php
index 53b6a50..c54c2a8 100644
--- a/tests/Analyzers/ItemGroupMappingTest.php
+++ b/tests/Analyzers/ItemGroupMappingTest.php
@@ -1,48 +1,78 @@
<?php
namespace Nasqueron\Notifications\Tests\Analyzers;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Nasqueron\Notifications\Analyzers\ItemGroupMapping;
use Nasqueron\Notifications\Tests\TestCase;
class ItemGroupMappingTest extends TestCase {
public function testDoesItemMatch () {
$this->assertTrue(
ItemGroupMapping::doesItemMatch(
'quux*',
'quuxians'
)
);
$this->assertTrue(
ItemGroupMapping::doesItemMatch(
'quux*',
'quux'
)
);
$this->assertFalse(
ItemGroupMapping::doesItemMatch(
'foobar',
'quux'
)
);
$this->assertFalse(
ItemGroupMapping::doesItemMatch(
'',
'quuxians'
)
);
$this->assertFalse(
ItemGroupMapping::doesItemMatch(
'quux*',
''
)
);
}
+
+ /**
+ * @dataProvider payloadProvider
+ */
+ public function testDeserialize (ItemGroupMapping $payload, ItemGroupMapping $expected) {
+ $this->assertEquals($payload, $expected);
+ }
+
+ private function deserialize ($file) : ItemGroupMapping {
+ $mapper = new \JsonMapper();
+ $payload = json_decode(file_get_contents($file));
+ return $mapper->map($payload, new ItemGroupMapping);
+ }
+
+ public function payloadProvider () : array {
+ $toProvide = [];
+
+ $path = __DIR__ . '/../data/ItemGroupMapping';
+ $files = glob($path . "/*.expected.json");
+ foreach ($files as $expectedResultFile) {
+ $resultFile = str_replace(".expected", "", $expectedResultFile);
+ $toProvide[] = [
+ $this->deserialize($resultFile),
+ $this->deserialize($expectedResultFile),
+ ];
+ }
+
+ return $toProvide;
+ }
+
}
diff --git a/tests/data/ItemGroupMapping/incomplete.expected.json b/tests/data/ItemGroupMapping/incomplete.expected.json
new file mode 100644
index 0000000..2a5e1f5
--- /dev/null
+++ b/tests/data/ItemGroupMapping/incomplete.expected.json
@@ -0,0 +1,4 @@
+{
+ "group": "tasacora",
+ "items": []
+}
diff --git a/tests/data/ItemGroupMapping/incomplete.json b/tests/data/ItemGroupMapping/incomplete.json
new file mode 100644
index 0000000..f0650a2
--- /dev/null
+++ b/tests/data/ItemGroupMapping/incomplete.json
@@ -0,0 +1,3 @@
+{
+ "group": "tasacora"
+}
diff --git a/tests/data/ItemGroupMapping/regular.expected.json b/tests/data/ItemGroupMapping/regular.expected.json
new file mode 100644
index 0000000..7bc1623
--- /dev/null
+++ b/tests/data/ItemGroupMapping/regular.expected.json
@@ -0,0 +1,6 @@
+{
+ "group": "tasacora",
+ "items": [
+ "Tasacora"
+ ]
+}
diff --git a/tests/data/ItemGroupMapping/regular.json b/tests/data/ItemGroupMapping/regular.json
new file mode 100644
index 0000000..7bc1623
--- /dev/null
+++ b/tests/data/ItemGroupMapping/regular.json
@@ -0,0 +1,6 @@
+{
+ "group": "tasacora",
+ "items": [
+ "Tasacora"
+ ]
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Dec 26, 01:12 (4 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2314352
Default Alt Text
(4 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment