Skip to content

Commit

Permalink
Merge pull request #4062 from markstory/issue-4031
Browse files Browse the repository at this point in the history
Ensure that the driver schema dialects use is connected.
  • Loading branch information
lorenzo committed Jul 22, 2014
2 parents f9f4bc2 + da8d54c commit 2959a17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Database/Schema/BaseSchema.php
Expand Up @@ -35,9 +35,13 @@ abstract class BaseSchema {
/**
* Constructor
*
* This constructor will connect the driver so that methods like columnSql() and others
* will fail when the driver has not been connected.
*
* @param \Cake\Database\Driver $driver The driver to use.
*/
public function __construct(Driver $driver) {
$driver->connect();
$this->_driver = $driver;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase/Database/Schema/MysqlSchemaTest.php
Expand Up @@ -845,6 +845,18 @@ public function testTruncateSql() {
$this->assertEquals('TRUNCATE TABLE `articles`', $result[0]);
}

/**
* Test that constructing a schema dialect connects the driver.
*
* @return void
*/
public function testConstructConnectsDriver() {
$driver = $this->getMock('Cake\Database\Driver');
$driver->expects($this->once())
->method('connect');
$schema = new MysqlSchema($driver);
}

/**
* Get a schema instance with a mocked driver/pdo instances
*
Expand Down

0 comments on commit 2959a17

Please sign in to comment.