Browse Source

Merge pull request #4062 from markstory/issue-4031

Ensure that the driver schema dialects use is connected.
José Lorenzo Rodríguez 11 years ago
parent
commit
2959a17626

+ 4 - 0
src/Database/Schema/BaseSchema.php

@@ -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;
 	}
 

+ 12 - 0
tests/TestCase/Database/Schema/MysqlSchemaTest.php

@@ -846,6 +846,18 @@ SQL;
 	}
 
 /**
+ * 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
  *
  * @return MysqlSchema