Browse Source

Added __debugInfo to ResultSet

Jose Lorenzo Rodriguez 12 years ago
parent
commit
ad4c4fdceb
2 changed files with 28 additions and 0 deletions
  1. 13 0
      src/ORM/ResultSet.php
  2. 15 0
      tests/TestCase/ORM/ResultSetTest.php

+ 13 - 0
src/ORM/ResultSet.php

@@ -439,4 +439,17 @@ class ResultSet implements Countable, Iterator, Serializable, JsonSerializable {
 		}
 	}
 
+/**
+ * Returns an array that can be used to describe the internal state of this
+ * object.
+ *
+ * @return array
+ */
+	public function __debugInfo() {
+		return [
+			'query' => $this->_query,
+			'items' => $this->toArray(),
+		];
+	}
+
 }

+ 15 - 0
tests/TestCase/ORM/ResultSetTest.php

@@ -230,4 +230,19 @@ class ResultSetTest extends TestCase {
 		$this->assertEquals($expected, $results);
 	}
 
+/**
+ * Tests __debugInfo
+ *
+ * @return void
+ */
+	public function testDebugInfo() {
+		$query = $this->table->find('all');
+		$results = $query->all();
+		$expected = [
+			'query' => $query,
+			'items' => $results->toArray()
+		];
+		$this->assertSame($expected, $results->__debugInfo());
+	}
+
 }