Path: blob/master/src/infrastructure/edges/__tests__/PhabricatorEdgeTestCase.php
12242 views
<?php12final class PhabricatorEdgeTestCase extends PhabricatorTestCase {34protected function getPhabricatorTestCaseConfiguration() {5return array(6self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,7);8}910public function testCycleDetection() {1112// The editor should detect that this introduces a cycle and prevent the13// edit.1415$user = new PhabricatorUser();1617$obj1 = id(new HarbormasterObject())->save();18$obj2 = id(new HarbormasterObject())->save();19$phid1 = $obj1->getPHID();20$phid2 = $obj2->getPHID();2122$editor = id(new PhabricatorEdgeEditor())23->addEdge($phid1, PhabricatorTestNoCycleEdgeType::EDGECONST , $phid2)24->addEdge($phid2, PhabricatorTestNoCycleEdgeType::EDGECONST , $phid1);2526$caught = null;27try {28$editor->save();29} catch (Exception $ex) {30$caught = $ex;31}3233$this->assertTrue($caught instanceof Exception);343536// The first edit should go through (no cycle), bu the second one should37// fail (it introduces a cycle).3839$editor = id(new PhabricatorEdgeEditor())40->addEdge($phid1, PhabricatorTestNoCycleEdgeType::EDGECONST , $phid2)41->save();4243$editor = id(new PhabricatorEdgeEditor())44->addEdge($phid2, PhabricatorTestNoCycleEdgeType::EDGECONST , $phid1);4546$caught = null;47try {48$editor->save();49} catch (Exception $ex) {50$caught = $ex;51}5253$this->assertTrue($caught instanceof Exception);54}555657}585960