summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--framework/Collections/TQueue.php12
-rw-r--r--tests/unit/Collections/TQueueTest.php7
2 files changed, 18 insertions, 1 deletions
diff --git a/framework/Collections/TQueue.php b/framework/Collections/TQueue.php
index e70b0ded..025fa6d0 100644
--- a/framework/Collections/TQueue.php
+++ b/framework/Collections/TQueue.php
@@ -31,7 +31,7 @@
* @package System.Collections
* @since 3.1
*/
-class TQueue extends TComponent implements IteratorAggregate
+class TQueue extends TComponent implements IteratorAggregate,Countable
{
/**
* internal data storage
@@ -160,6 +160,16 @@ class TQueue extends TComponent implements IteratorAggregate
{
return $this->_c;
}
+
+ /**
+ * Returns the number of items in the queue.
+ * This method is required by Countable interface.
+ * @return integer number of items in the queue.
+ */
+ public function count()
+ {
+ return $this->getCount();
+ }
}
/**
diff --git a/tests/unit/Collections/TQueueTest.php b/tests/unit/Collections/TQueueTest.php
index d0fe1af0..1c755480 100644
--- a/tests/unit/Collections/TQueueTest.php
+++ b/tests/unit/Collections/TQueueTest.php
@@ -118,6 +118,13 @@ class TQueueTest extends PHPUnit_Framework_TestCase {
$queue = new TQueue(array(1, 2, 3));
self::assertEquals(3, $queue->getCount());
}
+
+ public function testCountable() {
+ $queue = new TQueue();
+ self::assertEquals(0, count($queue));
+ $queue = new TQueue(array(1, 2, 3));
+ self::assertEquals(3, count($queue));
+ }
}