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