Skip to content

Commit 6e6b5b8

Browse files
committed
Adding __debugInfo to ORM\Query
1 parent b735c5d commit 6e6b5b8

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/ORM/Query.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,4 +708,19 @@ public function __call($method, $arguments) {
708708
);
709709
}
710710

711+
/**
712+
* {@inheritdoc}
713+
*/
714+
public function __debugInfo() {
715+
return parent::__debugInfo() + [
716+
'hydrate' => $this->_hydrate,
717+
'buffered' => $this->_useBufferedResults,
718+
'formatters' => count($this->_formatters),
719+
'mapReducers' => count($this->_mapReduce),
720+
'contain' => $this->contain(),
721+
'extraOptions' => $this->_options,
722+
'repository' => $this->_repository
723+
];
724+
}
725+
711726
}

tests/TestCase/ORM/QueryTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,4 +1767,52 @@ public function testContainInAssociationMatching() {
17671767
$this->assertEquals('tag3', $results[0]->articles->articles_tags->tag->name);
17681768
}
17691769

1770+
/**
1771+
* Tests __debugInfo
1772+
*
1773+
* @return void
1774+
*/
1775+
public function testDebugInfo() {
1776+
$table = TableRegistry::get('authors');
1777+
$table->hasMany('articles');
1778+
$query = $table->find()
1779+
->where(['id > ' => 1])
1780+
->bufferResults(false)
1781+
->hydrate(false)
1782+
->matching('articles')
1783+
->applyOptions(['foo' => 'bar'])
1784+
->formatResults(function($results) {
1785+
return $results;
1786+
})
1787+
->mapReduce(function($item, $key, $mr) {
1788+
$mr->emit($item);
1789+
});
1790+
1791+
$expected = [
1792+
'sql' => $query->sql(),
1793+
'params' => $query->valueBinder()->bindings(),
1794+
'defaultTypes' => [
1795+
'authors.id' => 'integer',
1796+
'id' => 'integer',
1797+
'authors.name' => 'string',
1798+
'name' => 'string'
1799+
],
1800+
'decorators' => 0,
1801+
'executed' => false,
1802+
'hydrate' => false,
1803+
'buffered' => false,
1804+
'formatters' => 1,
1805+
'mapReducers' => 1,
1806+
'contain' => [
1807+
'articles' => [
1808+
'queryBuilder' => null,
1809+
'matching' => true
1810+
]
1811+
],
1812+
'extraOptions' => ['foo' => 'bar'],
1813+
'repository' => $table
1814+
];
1815+
$this->assertSame($expected, $query->__debugInfo());
1816+
}
1817+
17701818
}

0 commit comments

Comments
 (0)