Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '3.0' of github.com:cakephp/cakephp into 3.0

  • Loading branch information...
commit 91dcfedd7e39f3dbe5a4ff0802ac43e429f6d646 2 parents eb6b7a4 + 662c168
@markstory markstory authored
View
18 src/Database/Query.php
@@ -204,7 +204,7 @@ public function execute() {
$query->_bindStatement($statement);
$statement->execute();
- return $query->_decorateStatement($statement);
+ return $this->_iterator = $query->_decorateStatement($statement);
}
/**
@@ -1821,4 +1821,20 @@ public function __toString() {
return sprintf('(%s)', $this->sql());
}
+/**
+ * Returns an array that can be used to describe the internal state of this
+ * object.
+ *
+ * @return array
+ */
+ public function __debugInfo() {
+ return [
+ 'sql' => $this->sql(),
+ 'params' => $this->valueBinder()->bindings(),
+ 'defaultTypes' => $this->_defaultTypes,
+ 'decorators' => count($this->_resultDecorators),
+ 'executed' => $this->_iterator ? true : false
+ ];
+ }
+
}
View
15 src/ORM/Query.php
@@ -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
+ ];
+ }
+
}
View
13 src/ORM/ResultSet.php
@@ -439,4 +439,17 @@ protected function _bufferResult($result) {
}
}
+/**
+ * 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(),
+ ];
+ }
+
}
View
36 tests/TestCase/Database/QueryTest.php
@@ -2397,6 +2397,42 @@ public function testQuotingInsert() {
}
/**
+ * Tests __debugInfo
+ *
+ * @return void
+ */
+ public function testDebugInfo() {
+ $query = (new Query($this->connection))->select('*')
+ ->from('articles')
+ ->defaultTypes(['id' => 'integer'])
+ ->where(['id' => '1']);
+
+ $expected = [
+ 'sql' => $query->sql(),
+ 'params' => [
+ ':c0' => ['value' => '1', 'type' => 'integer', 'placeholder' => 'c0']
+ ],
+ 'defaultTypes' => ['id' => 'integer'],
+ 'decorators' => 0,
+ 'executed' => false
+ ];
+ $result = $query->__debugInfo();
+ $this->assertEquals($expected, $result);
+
+ $query->execute();
+ $expected = [
+ 'sql' => $query->sql(),
+ 'params' => [
+ ':c0' => ['value' => '1', 'type' => 'integer', 'placeholder' => 'c0']
+ ],
+ 'defaultTypes' => ['id' => 'integer'],
+ 'decorators' => 0,
+ 'executed' => true
+ ];
+ $result = $query->__debugInfo();
+ }
+
+/**
* Assertion for comparing a table's contents with what is in it.
*
* @param string $table
View
48 tests/TestCase/ORM/QueryTest.php
@@ -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());
+ }
+
}
View
15 tests/TestCase/ORM/ResultSetTest.php
@@ -230,4 +230,19 @@ public function testGroupBy() {
$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());
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.