Browse Source

Don't emit errors when clauses are undefined.

Refs #10734
Mark Story 8 years ago
parent
commit
8782ba1204
2 changed files with 13 additions and 1 deletions
  1. 1 1
      src/Database/Query.php
  2. 12 0
      tests/TestCase/Database/QueryTest.php

+ 1 - 1
src/Database/Query.php

@@ -1698,7 +1698,7 @@ class Query implements ExpressionInterface, IteratorAggregate
      */
     public function clause($name)
     {
-        return $this->_parts[$name];
+        return isset($this->_parts[$name]) ? $this->_parts[$name] : null;
     }
 
     /**

+ 12 - 0
tests/TestCase/Database/QueryTest.php

@@ -4330,6 +4330,18 @@ class QueryTest extends TestCase
     }
 
     /**
+     * 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.
      *
      * @param string $table