Skip to content

Commit

Permalink
Adding __debugInfo to ORM\Query
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 10, 2014
1 parent b735c5d commit 6e6b5b8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/ORM/Query.php
Expand Up @@ -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
];
}

}
48 changes: 48 additions & 0 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -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.