@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<?php
2
3final class HarbormasterAutotargetsTestCase extends PhabricatorTestCase {
4
5 protected function getPhabricatorTestCaseConfiguration() {
6 return array(
7 self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
8 );
9 }
10
11 public function testGenerateHarbormasterAutotargets() {
12 $viewer = $this->generateNewTestUser();
13
14 $raw_diff = <<<EODIFF
15diff --git a/fruit b/fruit
16new file mode 100644
17index 0000000..1c0f49d
18--- /dev/null
19+++ b/fruit
20@@ -0,0 +1,2 @@
21+apal
22+banan
23EODIFF;
24
25 $parser = new ArcanistDiffParser();
26 $changes = $parser->parseDiff($raw_diff);
27
28 $diff = DifferentialDiff::newFromRawChanges($viewer, $changes)
29 ->setLintStatus(DifferentialLintStatus::LINT_AUTO_SKIP)
30 ->setUnitStatus(DifferentialUnitStatus::UNIT_AUTO_SKIP)
31 ->attachRevision(null)
32 ->save();
33
34 $params = array(
35 'objectPHID' => $diff->getPHID(),
36 'targetKeys' => array(
37 HarbormasterArcLintBuildStepImplementation::STEPKEY,
38 HarbormasterArcUnitBuildStepImplementation::STEPKEY,
39 ),
40 );
41
42 // Creation of autotargets should work from an empty state.
43 $result = id(new ConduitCall('harbormaster.queryautotargets', $params))
44 ->setUser($viewer)
45 ->execute();
46
47 $targets = idx($result, 'targetMap');
48 foreach ($params['targetKeys'] as $target_key) {
49 $this->assertTrue((bool)$result['targetMap'][$target_key]);
50 }
51
52 // Querying the same autotargets again should produce the same results,
53 // not make new ones.
54 $retry = id(new ConduitCall('harbormaster.queryautotargets', $params))
55 ->setUser($viewer)
56 ->execute();
57
58 $this->assertEqual($result, $retry);
59 }
60
61}