Skip to content
Permalink
Browse files

Squashed query update type check

  • Loading branch information...
rdcx committed Jan 18, 2017
1 parent e808d23 commit 0fdae8e457035dff0a58e4ea1c386e9160838396
Showing with 22 additions and 1 deletion.
  1. +8 −1 src/Database/Query.php
  2. +14 −0 tests/TestCase/Database/QueryTest.php
@@ -19,6 +19,7 @@
use Cake\Database\Expression\QueryExpression;
use Cake\Database\Expression\ValuesExpression;
use Cake\Database\Statement\CallbackStatement;
use InvalidArgumentException;
use IteratorAggregate;
use RuntimeException;
@@ -1412,11 +1413,17 @@ public function values($data)
*
* Can be combined with set() and where() methods to create update queries.
*
* @param string $table The table you want to update.
* @param string|\Cake\Database\ExpressionInterface $table The table you want to update.
* @return $this
*/
public function update($table)
{
if (!is_string($table) && !($table instanceof ExpressionInterface)) {
$text = 'Table must be of type string or "%s", got "%s"';
$message = sprintf($text, ExpressionInterface::class, gettype($table));
throw new InvalidArgumentException($message);
}
$this->_dirty();
$this->_type = 'update';
$this->_parts['update'][0] = $table;
@@ -2731,6 +2731,20 @@ public function testUpdateSimple()
$result->closeCursor();
}
/**
* Test update with type checking
* by passing an array as table arg
*
* @expectedException \InvalidArgumentException
*
* @return void
*/
public function testUpdateArgTypeChecking()
{
$query = new Query($this->connection);
$query->update(['Articles']);
}
/**
* Test update with multiple fields.
*

0 comments on commit 0fdae8e

Please sign in to comment.
You can’t perform that action at this time.