summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
authorMatthew Cillo <matthewacillo@gmail.com>2015-12-03 22:54:27 -0500
committerMatthew Cillo <matthewacillo@gmail.com>2015-12-03 22:54:27 -0500
commit207ee05b0ef2d084489d5b01c071b68a4f5075ca (patch)
treece15861da1b0d4d0786fd128e95edb81f8d6bbaa /tests/units
parent85fa0bf69b078e73c58c5dcf8493769e7f4ba412 (diff)
added tests
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Integration/GitlabWebhookTest.php36
-rw-r--r--tests/units/fixtures/gitlab_issue_reopened.json25
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/units/Integration/GitlabWebhookTest.php b/tests/units/Integration/GitlabWebhookTest.php
index 6d37819b..fa05f292 100644
--- a/tests/units/Integration/GitlabWebhookTest.php
+++ b/tests/units/Integration/GitlabWebhookTest.php
@@ -64,6 +64,35 @@ class GitlabWebhookTest extends Base
$this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_OPENED.'.GitlabWebhookTest::onOpen', $called);
}
+ public function testHandleIssueReopened()
+ {
+ $g = new GitlabWebhook($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $g->setProjectId(1);
+
+ $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_REOPENED, array($this, 'onReopen'));
+
+ $event = json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_issue_reopened.json'), true);
+
+ // Issue not there
+ $this->assertFalse($g->handleIssueReopened($event['object_attributes']));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+
+ $this->assertEquals(1, $tc->create(array('title' => 'A', 'project_id' => 1, 'reference' => 355691)));
+ $task = $tf->getByReference(1, 355691);
+ $this->assertTrue($g->handleIssueReopened($event['object_attributes']));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_REOPENED.'.GitlabWebhookTest::onReopen', $called);
+ }
+
+
public function testHandleIssueClosed()
{
$g = new GitlabWebhook($this->container);
@@ -170,6 +199,13 @@ class GitlabWebhookTest extends Base
$this->assertEquals("There is a bug somewhere.\r\n\r\nBye\n\n[Gitlab Issue](https://gitlab.com/minicoders/test-webhook/issues/1)", $data['description']);
}
+ public function onReopen($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['task_id']);
+ $this->assertEquals(355691, $data['reference']);
+ }
public function onClose($event)
{
$data = $event->getAll();
diff --git a/tests/units/fixtures/gitlab_issue_reopened.json b/tests/units/fixtures/gitlab_issue_reopened.json
new file mode 100644
index 00000000..bf76262d
--- /dev/null
+++ b/tests/units/fixtures/gitlab_issue_reopened.json
@@ -0,0 +1,25 @@
+{
+ "object_kind": "issue",
+ "user": {
+ "name": "Fred",
+ "username": "minicoders",
+ "avatar_url": "https://secure.gravatar.com/avatar/3c44936e5a56f80711bff14987d2733f?s=40&d=identicon"
+ },
+ "object_attributes": {
+ "id": 355691,
+ "title": "Bug",
+ "assignee_id": null,
+ "author_id": 74067,
+ "project_id": 320820,
+ "created_at": "2015-07-17 21:31:47 UTC",
+ "updated_at": "2015-07-17 21:31:47 UTC",
+ "position": 0,
+ "branch_name": null,
+ "description": "There is a bug somewhere.\r\n\r\nBye",
+ "milestone_id": null,
+ "state": "opened",
+ "iid": 1,
+ "url": "https://gitlab.com/minicoders/test-webhook/issues/1",
+ "action": "reopen"
+ }
+}