From 8782ba12041ecec8652311980dd00a245689fe39 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 7 Jun 2017 12:11:38 -0400 Subject: [PATCH] Don't emit errors when clauses are undefined. Refs #10734 --- src/Database/Query.php | 2 +- tests/TestCase/Database/QueryTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Database/Query.php b/src/Database/Query.php index 9a242a8fe8c..6c6a02aa13d 100644 --- a/src/Database/Query.php +++ b/src/Database/Query.php @@ -1698,7 +1698,7 @@ public function getIterator() */ public function clause($name) { - return $this->_parts[$name]; + return isset($this->_parts[$name]) ? $this->_parts[$name] : null; } /** diff --git a/tests/TestCase/Database/QueryTest.php b/tests/TestCase/Database/QueryTest.php index afd38fa2110..a4a31a404f6 100644 --- a/tests/TestCase/Database/QueryTest.php +++ b/tests/TestCase/Database/QueryTest.php @@ -4329,6 +4329,18 @@ public function testSelectWithObjFetchType() $this->assertEquals($obj, $rows[0]); } + /** + * Test that reading an undefined clause does not emit an error. + * + * @return void + */ + public function testClauseUndefined() + { + $query = new Query($this->connection); + $this->assertEmpty($query->clause('where')); + $this->assertNull($query->clause('nope')); + } + /** * Assertion for comparing a table's contents with what is in it. *