added tests

This commit is contained in:
Matthew Cillo 2015-12-03 22:54:27 -05:00
parent 85fa0bf69b
commit 207ee05b0e
2 changed files with 61 additions and 0 deletions

View File

@ -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();

View File

@ -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"
}
}