public function setUp() { parent::setUp(); $container_opts = array('type' => 'mdb2', 'dsn' => $this->dsn, 'mail_table' => $this->table); /** * @see Mail_mock */ $mail_opts = array('driver' => 'mock'); $this->queueMock = $this->getMock('Mail_Queue', array('get'), array($container_opts, $mail_opts)); $this->queueMock->expects($this->once())->method('get')->will($this->returnValue(Pear::raiseError("OH NOEZ"))); }
/** * Add a Node to the Graph * * @param Structures_Graph_Node $newNode The node to be added. * * @return void */ public function addNode(&$newNode) { // We only add nodes if (!is_a($newNode, 'Structures_Graph_Node')) { return Pear::raiseError('Structures_Graph::addNode received an object that is not' . ' a Structures_Graph_Node', STRUCTURES_GRAPH_ERROR_GENERIC); } //Graphs are node *sets*, so duplicates are forbidden. // We allow nodes that are exactly equal, but disallow equal references. foreach ($this->_nodes as $key => $node) { /* ZE1 equality operators choke on the recursive cycle introduced by the _graph field in the Node object. So, we'll check references the hard way (change $this->_nodes[$key] and check if the change reflects in $node) */ $savedData = $this->_nodes[$key]; $referenceIsEqualFlag = false; $this->_nodes[$key] = true; if ($node === true) { $this->_nodes[$key] = false; if ($node === false) { $referenceIsEqualFlag = true; } } $this->_nodes[$key] = $savedData; if ($referenceIsEqualFlag) { return Pear::raiseError('Structures_Graph::addNode received an object that is' . ' a duplicate for this dataset', STRUCTURES_GRAPH_ERROR_GENERIC); } } $this->_nodes[] =& $newNode; $newNode->setGraph($this); }
/** * * sort returns the graph's nodes, sorted by topological order. * * The result is an array with * as many entries as topological levels. Each entry in this array is an array of nodes within * the given topological level. * * @return array The graph's nodes, sorted by topological order. * @access public */ function sort(&$graph) { // We only sort graphs if (!is_a($graph, 'Structures_Graph')) { return Pear::raiseError('Structures_Graph_Manipulator_TopologicalSorter::sort received an object that is not a Structures_Graph', STRUCTURES_GRAPH_ERROR_GENERIC); } if (!Structures_Graph_Manipulator_AcyclicTest::isAcyclic($graph)) { return Pear::raiseError('Structures_Graph_Manipulator_TopologicalSorter::sort received an graph that has cycles', STRUCTURES_GRAPH_ERROR_GENERIC); } Structures_Graph_Manipulator_TopologicalSorter::_sort($graph); $result = array(); // Fill out result array $nodes =& $graph->getNodes(); $nodeKeys = array_keys($nodes); foreach ($nodeKeys as $key) { if (!array_key_exists($nodes[$key]->getMetadata('topological-sort-level'), $result)) { $result[$nodes[$key]->getMetadata('topological-sort-level')] = array(); } $result[$nodes[$key]->getMetadata('topological-sort-level')][] =& $nodes[$key]; $nodes[$key]->unsetMetadata('topological-sort-level'); } return $result; }
/** * * Connect this node to another one. * * If the graph is not directed, the reverse arc, connecting $destinationNode to $this is also created. * * @param Structures_Graph Node to connect to * @access public */ function connectTo(&$destinationNode) { // We only connect to nodes if (!is_a($destinationNode, 'Structures_Graph_Node')) { return Pear::raiseError('Structures_Graph_Node::connectTo received an object that is not a Structures_Graph_Node', STRUCTURES_GRAPH_ERROR_GENERIC); } // Nodes must already be in graphs to be connected if ($this->_graph == null) { return Pear::raiseError('Structures_Graph_Node::connectTo Tried to connect a node that is not in a graph', STRUCTURES_GRAPH_ERROR_GENERIC); } if ($destinationNode->getGraph() == null) { return Pear::raiseError('Structures_Graph_Node::connectTo Tried to connect to a node that is not in a graph', STRUCTURES_GRAPH_ERROR_GENERIC); } // Connect here $this->_connectTo($destinationNode); // If graph is undirected, connect back if (!$this->_graph->isDirected()) { $destinationNode->_connectTo($this); } }
/** * * isAcyclic returns true if a graph contains no cycles, false otherwise. * * @return boolean true iff graph is acyclic * @access public */ function isAcyclic(&$graph) { // We only test graphs if (!is_a($graph, 'Structures_Graph')) { return Pear::raiseError('Structures_Graph_Manipulator_AcyclicTest::isAcyclic received an object that is not a Structures_Graph', STRUCTURES_GRAPH_ERROR_GENERIC); } if (!$graph->isDirected()) { return false; } // Only directed graphs may be acyclic return Structures_Graph_Manipulator_AcyclicTest::_isAcyclic($graph); }