diff --git a/library/Zend/Stdlib/PriorityList.php b/library/Zend/Stdlib/PriorityList.php index 907e306299e..9b3b93b76f7 100644 --- a/library/Zend/Stdlib/PriorityList.php +++ b/library/Zend/Stdlib/PriorityList.php @@ -12,9 +12,6 @@ use Countable; use Iterator; -/** - * Priority list - */ class PriorityList implements Iterator, Countable { const EXTR_DATA = 0x00000001; @@ -23,7 +20,7 @@ class PriorityList implements Iterator, Countable /** * Internal list of all items. * - * @var array + * @var array[] */ protected $items = array(); @@ -58,8 +55,9 @@ class PriorityList implements Iterator, Countable * Insert a new item. * * @param string $name - * @param mixed $value - * @param int $priority + * @param mixed $value + * @param int $priority + * * @return void */ public function insert($name, $value, $priority = 0) @@ -74,13 +72,23 @@ public function insert($name, $value, $priority = 0) ); } + /** + * @param string $name + * @param int $priority + * + * @return $this + * + * @throws \Exception + */ public function setPriority($name, $priority) { if (!isset($this->items[$name])) { throw new \Exception("item $name not found"); } + $this->items[$name]['priority'] = (int) $priority; - $this->sorted = false; + $this->sorted = false; + return $this; } @@ -92,11 +100,10 @@ public function setPriority($name, $priority) */ public function remove($name) { - if (!isset($this->items[$name])) { - return; + if (isset($this->items[$name])) { + $this->count--; } - $this->count--; unset($this->items[$name]); } @@ -107,7 +114,7 @@ public function remove($name) */ public function clear() { - $this->items = array(); + $this->items = array(); $this->serial = 0; $this->count = 0; $this->sorted = false; @@ -158,25 +165,26 @@ protected function compare(array $item1, array $item2) /** * Get/Set serial order mode * - * @param bool $flag + * @param bool|null $flag + * * @return bool */ public function isLIFO($flag = null) { if ($flag !== null) { - if (($flag = ($flag === true ? 1 : -1)) !== $this->isLIFO) { - $this->isLIFO = $flag; + $isLifo = $flag === true ? 1 : -1; + + if ($isLifo !== $this->isLIFO) { + $this->isLIFO = $isLifo; $this->sorted = false; } } - return $this->isLIFO === 1; + + return 1 === $this->isLIFO; } /** - * rewind(): defined by Iterator interface. - * - * @see Iterator::rewind() - * @return void + * {@inheritDoc} */ public function rewind() { @@ -185,23 +193,18 @@ public function rewind() } /** - * current(): defined by Iterator interface. - * - * @see Iterator::current() - * @return mixed + * {@inheritDoc} */ public function current() { $this->sorted || $this->sort(); $node = current($this->items); - return ($node !== false ? $node['data'] : false); + + return $node ? $node['data'] : false; } /** - * key(): defined by Iterator interface. - * - * @see Iterator::key() - * @return string + * {@inheritDoc} */ public function key() { @@ -210,26 +213,21 @@ public function key() } /** - * next(): defined by Iterator interface. - * - * @see Iterator::next() - * @return mixed + * {@inheritDoc} */ public function next() { $node = next($this->items); - return ($node !== false ? $node['data'] : false); + + return $node ? $node['data'] : false; } /** - * valid(): defined by Iterator interface. - * - * @see Iterator::valid() - * @return bool + * {@inheritDoc} */ public function valid() { - return ($this->current() !== false); + return $this->current() !== false; } /** @@ -241,10 +239,7 @@ public function getIterator() } /** - * count(): defined by Countable interface. - * - * @see Countable::count() - * @return int + * {@inheritDoc} */ public function count() { @@ -255,16 +250,19 @@ public function count() * Return list as array * * @param int $flag + * * @return array */ public function toArray($flag = self::EXTR_DATA) { $this->sort(); + if ($flag == self::EXTR_BOTH) { return $this->items; } + return array_map( - ($flag == self::EXTR_PRIORITY) + self::EXTR_PRIORITY === $flag ? function ($item) { return $item['priority']; } : function ($item) { return $item['data']; }, $this->items diff --git a/tests/ZendTest/Db/Sql/UpdateTest.php b/tests/ZendTest/Db/Sql/UpdateTest.php index 364afe1a260..4cb61c84d21 100644 --- a/tests/ZendTest/Db/Sql/UpdateTest.php +++ b/tests/ZendTest/Db/Sql/UpdateTest.php @@ -234,6 +234,19 @@ public function testGetSqlString() $this->assertEquals('UPDATE "sch"."foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform())); } + /** + * @group 6768 + * @group 6773 + */ + public function testGetSqlStringForFalseUpdateValueParameter() + { + $this->update = new Update; + $this->update->table(new TableIdentifier('foo', 'sch')) + ->set(array('bar' => false, 'boo' => 'test', 'bam' => true)) + ->where('x = y'); + $this->assertEquals('UPDATE "sch"."foo" SET "bar" = \'\', "boo" = \'test\', "bam" = \'1\' WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform())); + } + /** * @covers Zend\Db\Sql\Update::__get */ diff --git a/tests/ZendTest/Stdlib/PriorityListTest.php b/tests/ZendTest/Stdlib/PriorityListTest.php index c102a70b9e4..7dd8ae49a7b 100644 --- a/tests/ZendTest/Stdlib/PriorityListTest.php +++ b/tests/ZendTest/Stdlib/PriorityListTest.php @@ -83,7 +83,7 @@ public function testLIFOOnly() $this->list->insert('foobar', new \stdClass()); $this->list->insert('barbaz', new \stdClass()); - $order = array(); + $orders = array(); foreach ($this->list as $key => $value) { $orders[] = $key; @@ -129,7 +129,7 @@ public function testFIFOWithPriority() $this->list->insert('bar', new \stdClass(), 0); $this->list->insert('baz', new \stdClass(), 1); - $order = array(); + $orders = array(); foreach ($this->list as $key => $value) { $orders[] = $key; @@ -147,7 +147,7 @@ public function testFIFOOnly() $this->list->insert('foobar', new \stdClass()); $this->list->insert('barbaz', new \stdClass()); - $order = array(); + $orders = array(); foreach ($this->list as $key => $value) { $orders[] = $key; @@ -162,7 +162,7 @@ public function testPriorityWithNegativesAndNull() $this->list->insert('bar', new \stdClass(), 1); $this->list->insert('baz', new \stdClass(), -1); - $order = array(); + $orders = array(); foreach ($this->list as $key => $value) { $orders[] = $key; @@ -215,4 +215,24 @@ public function testToArray() $this->list->toArray(PriorityList::EXTR_BOTH) ); } + + /** + * @group 6768 + * @group 6773 + */ + public function testBooleanValuesAreValid() + { + $this->list->insert('foo', false, null); + $this->list->insert('foo', null, null); + $this->list->insert('bar', 'test', 1); + $this->list->insert('baz', true, -1); + + $orders = array(); + + foreach ($this->list as $key => $value) { + $orders[] = $value; + } + + $this->assertEquals(array('test', false, true), $orders); + } }