@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at upstream/main 115 lines 3.2 kB view raw
1<?php 2 3final class NuanceGitHubRawEventTestCase 4 extends PhabricatorTestCase { 5 6 public function testIssueEvents() { 7 $path = dirname(__FILE__).'/issueevents/'; 8 9 $cases = $this->readTestCases($path); 10 11 foreach ($cases as $name => $info) { 12 $input = $info['input']; 13 $expect = $info['expect']; 14 15 $event = NuanceGitHubRawEvent::newEvent( 16 NuanceGitHubRawEvent::TYPE_ISSUE, 17 $input); 18 19 $this->assertGitHubRawEventParse($expect, $event, $name); 20 } 21 } 22 23 public function testRepositoryEvents() { 24 $path = dirname(__FILE__).'/repositoryevents/'; 25 26 $cases = $this->readTestCases($path); 27 28 foreach ($cases as $name => $info) { 29 $input = $info['input']; 30 $expect = $info['expect']; 31 32 $event = NuanceGitHubRawEvent::newEvent( 33 NuanceGitHubRawEvent::TYPE_REPOSITORY, 34 $input); 35 36 $this->assertGitHubRawEventParse($expect, $event, $name); 37 } 38 } 39 40 private function assertGitHubRawEventParse( 41 array $expect, 42 NuanceGitHubRawEvent $event, 43 $name) { 44 45 $actual = array( 46 'repository.name.full' => $event->getRepositoryFullName(), 47 'is.issue' => $event->isIssueEvent(), 48 'is.pull' => $event->isPullRequestEvent(), 49 'issue.number' => $event->getIssueNumber(), 50 'pull.number' => $event->getPullRequestNumber(), 51 'id' => $event->getID(), 52 'uri' => $event->getURI(), 53 'title.full' => $event->getEventFullTitle(), 54 'comment' => $event->getComment(), 55 'actor.id' => $event->getActorGitHubUserID(), 56 ); 57 58 // Only verify the keys which are actually present in the test. This 59 // allows tests to specify only relevant keys. 60 $actual = array_select_keys($actual, array_keys($expect)); 61 62 ksort($expect); 63 ksort($actual); 64 65 $this->assertEqual($expect, $actual, $name); 66 } 67 68 private function readTestCases($path) { 69 $files = Filesystem::listDirectory($path, $include_hidden = false); 70 71 $tests = array(); 72 foreach ($files as $file) { 73 $data = Filesystem::readFile($path.$file); 74 75 $parts = preg_split('/^~{5,}$/m', $data); 76 if (count($parts) < 2) { 77 throw new Exception( 78 pht( 79 'Expected test file "%s" to contain an input section in JSON, '. 80 'then an expected result section in JSON, with the two sections '. 81 'separated by a line of "~~~~~", but the divider is not present '. 82 'in the file.', 83 $file)); 84 } else if (count($parts) > 2) { 85 throw new Exception( 86 pht( 87 'Expected test file "%s" to contain exactly two sections, '. 88 'but it has more than two sections.', 89 $file)); 90 } 91 92 list($input, $expect) = $parts; 93 94 try { 95 $input = phutil_json_decode($input); 96 $expect = phutil_json_decode($expect); 97 } catch (Exception $ex) { 98 throw new Exception( 99 pht( 100 'Exception while decoding test data for test "%s".', 101 $file), 102 0, 103 $ex); 104 } 105 106 $tests[$file] = array( 107 'input' => $input, 108 'expect' => $expect, 109 ); 110 } 111 112 return $tests; 113 } 114 115}