Permalink
Browse files

Adding __debugInfo to ORM\Query

  • Loading branch information...
1 parent b735c5d commit 6e6b5b8c0282111a541aa182a7aaada2a9498c0a @lorenzo lorenzo committed Mar 10, 2014
Showing with 63 additions and 0 deletions.
  1. +15 −0 src/ORM/Query.php
  2. +48 −0 tests/TestCase/ORM/QueryTest.php
View
@@ -708,4 +708,19 @@ public function __call($method, $arguments) {
);
}
+/**
+ * {@inheritdoc}
+ */
+ public function __debugInfo() {
+ return parent::__debugInfo() + [
+ 'hydrate' => $this->_hydrate,
+ 'buffered' => $this->_useBufferedResults,
+ 'formatters' => count($this->_formatters),
+ 'mapReducers' => count($this->_mapReduce),
+ 'contain' => $this->contain(),
+ 'extraOptions' => $this->_options,
+ 'repository' => $this->_repository
+ ];
+ }
+
}
@@ -1767,4 +1767,52 @@ public function testContainInAssociationMatching() {
$this->assertEquals('tag3', $results[0]->articles->articles_tags->tag->name);
}
+/**
+ * Tests __debugInfo
+ *
+ * @return void
+ */
+ public function testDebugInfo() {
+ $table = TableRegistry::get('authors');
+ $table->hasMany('articles');
+ $query = $table->find()
+ ->where(['id > ' => 1])
+ ->bufferResults(false)
+ ->hydrate(false)
+ ->matching('articles')
+ ->applyOptions(['foo' => 'bar'])
+ ->formatResults(function($results) {
+ return $results;
+ })
+ ->mapReduce(function($item, $key, $mr) {
+ $mr->emit($item);
+ });
+
+ $expected = [
+ 'sql' => $query->sql(),
+ 'params' => $query->valueBinder()->bindings(),
+ 'defaultTypes' => [
+ 'authors.id' => 'integer',
+ 'id' => 'integer',
+ 'authors.name' => 'string',
+ 'name' => 'string'
+ ],
+ 'decorators' => 0,
+ 'executed' => false,
+ 'hydrate' => false,
+ 'buffered' => false,
+ 'formatters' => 1,
+ 'mapReducers' => 1,
+ 'contain' => [
+ 'articles' => [
+ 'queryBuilder' => null,
+ 'matching' => true
+ ]
+ ],
+ 'extraOptions' => ['foo' => 'bar'],
+ 'repository' => $table
+ ];
+ $this->assertSame($expected, $query->__debugInfo());
+ }
+
}

0 comments on commit 6e6b5b8

Please sign in to comment.