Skip to content
Permalink
Browse files

Throw exception if argument passed to Table::connection() is of incor…

…rect type

Refs #6199
  • Loading branch information...
ADmad committed Mar 29, 2015
1 parent f6da132 commit 51d9247af15e95ba6156a40def5f8d38ac4c83bb
Showing with 19 additions and 0 deletions.
  1. +6 −0 src/ORM/Table.php
  2. +13 −0 tests/TestCase/ORM/TableTest.php
@@ -17,6 +17,7 @@
use ArrayObject;
use BadMethodCallException;
use Cake\Core\App;
use Cake\Database\Connection;
use Cake\Database\Schema\Table as Schema;
use Cake\Database\Type;
use Cake\Datasource\EntityInterface;
@@ -397,6 +398,11 @@ public function connection($conn = null)
if ($conn === null) {
return $this->_connection;
}
if (!($conn instanceof Connection)) {
throw new RuntimeException('$conn must be an instance of \Cake\Database\Connection');
}
return $this->_connection = $conn;
}
@@ -185,6 +185,19 @@ public function testConnection()
$this->assertSame($this->connection, $table->connection());
}
/**
* Tests exception is thrown in connection is not instance of
* \Cake\Database\Connection
*
* @expectedException \RuntimeException
* @expectedExceptionMessage $conn must be an instance of \Cake\Database\Connection
* @return void
*/
public function testConnectionException()
{
$table = new Table(['table' => 'users', 'connection' => 'default']);
}
/**
* Tests primaryKey method
*

0 comments on commit 51d9247

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