diff --git a/Cake/ORM/Table.php b/Cake/ORM/Table.php index fbec09d6aaf..5ccad182e9a 100644 --- a/Cake/ORM/Table.php +++ b/Cake/ORM/Table.php @@ -1266,6 +1266,13 @@ public function _magicFinder($method, $args) { return [$conditions, $order]; }; + if ($hasOr !== false && $hasAnd !== false) { + throw new \Cake\Error\Exception(__d( + 'cake_dev', + 'Cannot mix "and" & "or" in a magic finder. Use find() instead.' + )); + } + if ($hasOr === false && $hasAnd === false) { list($conditions, $order) = $makeConditions([$fields], $args); } elseif ($hasOr !== false) { diff --git a/Cake/Test/TestCase/ORM/TableTest.php b/Cake/Test/TestCase/ORM/TableTest.php index 5ad874f626a..6ebe075508d 100644 --- a/Cake/Test/TestCase/ORM/TableTest.php +++ b/Cake/Test/TestCase/ORM/TableTest.php @@ -1958,7 +1958,7 @@ public function testMagicFindFirst() { } /** - * Test magic findByXX method. + * Test magic findByXX errors on missing arguments. * * @expectedException Cake\Error\Exception * @expectedExceptionMessage Not enough arguments to magic finder. Got 0 required 1 @@ -1971,7 +1971,7 @@ public function testMagicFindError() { } /** - * Test magic findByXX method. + * Test magic findByXX errors on missing arguments. * * @expectedException Cake\Error\Exception * @expectedExceptionMessage Not enough arguments to magic finder. Got 1 required 2 @@ -1983,6 +1983,19 @@ public function testMagicFindErrorMissingField() { $table->findByUsernameAndId('garrett'); } +/** + * Test magic findByXX errors when there is a mix of or & and. + * + * @expectedException Cake\Error\Exception + * @expectedExceptionMessage Cannot mix "and" & "or" in a magic finder. Use find() instead. + * @return void + */ + public function testMagicFindErrorMixOfOperators() { + $table = TableRegistry::get('Users'); + + $table->findByUsernameAndIdOrPassword('garrett', 1, 'sekret'); + } + /** * Test magic findByXX method. *