Page MenuHomeDevCentral

D324.id766.diff
No OneTemporary

D324.id766.diff

diff --git a/tests/Phabricator/ProjectsMapTest.php b/tests/Phabricator/ProjectsMapTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Phabricator/ProjectsMapTest.php
@@ -0,0 +1,137 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Phabricator;
+
+use Nasqueron\Notifications\Phabricator\ProjectsMap;
+use Nasqueron\Notifications\Tests\TestCase;
+
+class ProjectsMapTest extends TestCase {
+
+ /**
+ * @var Nasqueron\Notifications\Phabricator\ProjectsMap
+ */
+ private $map;
+
+ public function setUp () {
+ parent::setUp();
+
+ //
+ // We mock the API, so an imaginary instance of Phabricator
+ // will return 3 results: Accounts, Agora & architecture.
+ //
+ // Agora has the key 'PHID-PROJ-cztcgpvqr6smnnekotq7'.
+ //
+
+ $this->mockPhabricatorAPIForProjectsMap();
+ $this->map = ProjectsMap::fetch("http://phabricator.acme.tld");
+ }
+
+ public function testIteratorIsTraversable () {
+ $this->assertInstanceOf(
+ "Traversable",
+ $this->map->getIterator()
+ );
+ }
+
+ ///
+ /// Tests for ArrayAccess
+ ///
+
+ public function testOffsetExistsWhenItDoes () {
+ $this->assertTrue(
+ $this->map->offsetExists('PHID-PROJ-cztcgpvqr6smnnekotq7')
+ );
+ }
+
+ public function testOffsetExistsWhenItDoesNot () {
+ $this->assertFalse(
+ $this->map->offsetExists('non-existing-key')
+ );
+ }
+
+ public function testOffsetGetWhenItDoesExist () {
+ $this->assertSame(
+ "Agora",
+ $this->map->offsetGet('PHID-PROJ-cztcgpvqr6smnnekotq7')
+ );
+ }
+
+ /**
+ * @expectedException ErrorException
+ */
+ public function testOffsetGetWhenItDoesNotExist () {
+ $this->map->offsetGet('non-existing-key');
+ }
+
+ /**
+ * @covers ProjectsMap::offsetSet
+ */
+ public function testOffsetSet () {
+ $this->map->offsetSet('newkey', 'quux');
+ $this->assertSame('quux', $this->map->offsetGet('newkey'));
+ }
+
+ /**
+ * @covers ProjectsMap::offsetUnset
+ */
+ public function testOffsetUnset () {
+ unset($this->map['PHID-PROJ-cztcgpvqr6smnnekotq7']);
+ $this->assertFalse(
+ $this->map->offsetExists('PHID-PROJ-cztcgpvqr6smnnekotq7')
+ );
+ }
+
+ ///
+ /// Tests for cache
+ ///
+
+ ///
+ /// Tests for helper methods
+ ///
+
+ public function testGetProjectName () {
+ $this->assertSame(
+ "Agora",
+ $this->map->getProjectName('PHID-PROJ-cztcgpvqr6smnnekotq7')
+ );
+ }
+
+ public function testGetProjectNameForNewInstance () {
+ $map = new ProjectsMap("http://phabricator.acme.tld");
+ $this->assertSame(
+ "Agora",
+ $map->getProjectName('PHID-PROJ-cztcgpvqr6smnnekotq7')
+ );
+ }
+
+ public function testGetProjectNameWhenItDoesNotExist () {
+ $this->assertSame(
+ "",
+ $this->map->getProjectName('non-existing-key')
+ );
+ }
+
+ public function testToArrayProducesArray () {
+ $array = $this->map->toArray();
+ $this->assertTrue(
+ is_array($array),
+ "Test if toArray return an array"
+ );
+ }
+
+ public function testThatArrayCount () {
+ $array = $this->map->toArray();
+ $this->assertSame(3, count($array));
+ }
+
+ public function testThatArrayContainsExpectedData () {
+ $this->assertSame(
+ [
+ ["PHID-PROJ-6dg6ogx5pjmk24ur4tp4", "Accounts"],
+ ["PHID-PROJ-cztcgpvqr6smnnekotq7", "Agora"],
+ ["PHID-PROJ-3iew3cqf3htpazfyzb5a", "architecture"]
+ ],
+ $this->map->toArray()
+ );
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 09:23 (14 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259923
Default Alt Text
D324.id766.diff (3 KB)

Event Timeline