@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 PhabricatorEdgeTestCase extends PhabricatorTestCase {
4
5 protected function getPhabricatorTestCaseConfiguration() {
6 return array(
7 self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
8 );
9 }
10
11 public function testCycleDetection() {
12
13 // The editor should detect that this introduces a cycle and prevent the
14 // edit.
15
16 $user = new PhabricatorUser();
17
18 $obj1 = id(new HarbormasterObject())->save();
19 $obj2 = id(new HarbormasterObject())->save();
20 $phid1 = $obj1->getPHID();
21 $phid2 = $obj2->getPHID();
22
23 $editor = id(new PhabricatorEdgeEditor())
24 ->addEdge($phid1, PhabricatorTestNoCycleEdgeType::EDGECONST , $phid2)
25 ->addEdge($phid2, PhabricatorTestNoCycleEdgeType::EDGECONST , $phid1);
26
27 $caught = null;
28 try {
29 $editor->save();
30 } catch (Exception $ex) {
31 $caught = $ex;
32 }
33
34 $this->assertTrue($caught instanceof Exception);
35
36
37 // The first edit should go through (no cycle), bu the second one should
38 // fail (it introduces a cycle).
39
40 $editor = id(new PhabricatorEdgeEditor())
41 ->addEdge($phid1, PhabricatorTestNoCycleEdgeType::EDGECONST , $phid2)
42 ->save();
43
44 $editor = id(new PhabricatorEdgeEditor())
45 ->addEdge($phid2, PhabricatorTestNoCycleEdgeType::EDGECONST , $phid1);
46
47 $caught = null;
48 try {
49 $editor->save();
50 } catch (Exception $ex) {
51 $caught = $ex;
52 }
53
54 $this->assertTrue($caught instanceof Exception);
55 }
56
57
58}