svn: /pear2/BugManager/trunk/ src/BugManager/ContextContainer.php src/BugManager/Issue.php tests/Issue/diff/diff.phpt

From: Date: Tue, 11 Aug 2009 21:06:10 +0000
Subject: svn: /pear2/BugManager/trunk/ src/BugManager/ContextContainer.php src/BugManager/Issue.php tests/Issue/diff/diff.phpt
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-57048@lists.php.net to get a copy of this message
cellog Tue, 11 Aug 2009 21:06:10 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=287115 Log: implement diffing of contexts so we can see what was added/deleted/changed Changed paths: U pear2/BugManager/trunk/src/BugManager/ContextContainer.php U pear2/BugManager/trunk/src/BugManager/Issue.php U pear2/BugManager/trunk/tests/Issue/diff/diff.phpt Modified: pear2/BugManager/trunk/src/BugManager/ContextContainer.php =================================================================== --- pear2/BugManager/trunk/src/BugManager/ContextContainer.php 2009-08-11 20:10:46 UTC (rev 287114) +++ pear2/BugManager/trunk/src/BugManager/ContextContainer.php 2009-08-11 21:06:10 UTC (rev 287115) @@ -61,6 +61,9 @@ if (!($value instanceof Context)) { if (isset($this[$name])) { $new = $this[$name]; + if ($source != $this[$name]->source()) { + $this->modified(); + } } else { $new = new Context($name, $this->parent, $source); $new->setContainer($this); @@ -71,6 +74,13 @@ return parent::offsetSet($name, $value); } + function __clone() + { + foreach ($this as $key => $obj) { + $this[$key] = clone $obj; + } + } + function equals(ContextContainer $c) { if (count($c) != count($this)) { Modified: pear2/BugManager/trunk/src/BugManager/Issue.php =================================================================== --- pear2/BugManager/trunk/src/BugManager/Issue.php 2009-08-11 20:10:46 UTC (rev 287114) +++ pear2/BugManager/trunk/src/BugManager/Issue.php 2009-08-11 21:06:10 UTC (rev 287115) @@ -184,6 +184,31 @@ } /** + * @return array an array of context names that have changed + */ + function diffContext() + { + if (!isset($this->newvalues['context'])) { + return array(); + } + $added = array_diff(array_keys($this->newvalues['context']->getArrayCopy()), + array_keys($this->oldvalues['context']->getArrayCopy())); + $removed = array_diff(array_keys($this->oldvalues['context']->getArrayCopy()), + array_keys($this->newvalues['context']->getArrayCopy())); + $changed = array(); + foreach ($this->newvalues['context'] as $key => $value) { + if (in_array($key, $removed) || in_array($key, $added)) { + continue; + } + + if ($this->newvalues['context'][$key]->value() !== $this->oldvalues['context'][$key]->value()) { + $changed[] = $key; + } + } + return array('new' => $added, 'deleted' => $removed, 'changed' => $changed); + } + + /** * @return array an array of pear2\BugManager\Issue */ function history($limit) Modified: pear2/BugManager/trunk/tests/Issue/diff/diff.phpt =================================================================== --- pear2/BugManager/trunk/tests/Issue/diff/diff.phpt 2009-08-11 20:10:46 UTC (rev 287114) +++ pear2/BugManager/trunk/tests/Issue/diff/diff.phpt 2009-08-11 21:06:10 UTC (rev 287115) @@ -44,6 +44,8 @@ $test->assertEquals(array('type'), $bug->diff(), 'type diff'); $bug->context['phpversion'] = '5.3.0'; $test->assertEquals(array('type', 'context'), $bug->diff(), 'context/type diff'); +$test->assertEquals(array('new' => array(), 'deleted' => array(), 'changed' => array('phpversion')), + $bug->diffContext(), 'context diff'); $bug->category->setPrimary(new pear2\BugManager\Category\PearPackage('pear')); $test->assertEquals(array('type', 'category', 'context'), $bug->diff(), 'context/type/category diff'); ?>

« previous php.pear.cvs (#57048) next »