Browse files

Fixing ConnectionManager tests

  • Loading branch information...
1 parent e33938f commit 8eec05895b65dae39fbd8c71ecfa3f572f00473c @lorenzo lorenzo committed Feb 17, 2014
View
19 tests/TestCase/Datasource/ConnectionManagerTest.php
@@ -73,7 +73,7 @@ public function testConfigVariants($settings) {
/**
* Test invalid classes cause exceptions
*
- * @expectedException Cake\Database\Exception\MissingDriverException
+ * @expectedException Cake\Datasource\Error\MissingDatasourceException
*/
public function testConfigInvalidOptions() {
ConnectionManager::config('test_variant', [
@@ -91,7 +91,7 @@ public function testConfigInvalidOptions() {
*/
public function testConfigDuplicateConfig() {
$settings = [
- 'className' => 'Sqlite',
+ 'className' => __NAMESPACE__ . '\FakeConnection',
'database' => ':memory:',
];
ConnectionManager::config('test_variant', $settings);
@@ -146,7 +146,7 @@ public function testGetNoAlias() {
*/
public function testConfigured() {
ConnectionManager::config('test_variant', [
- 'className' => 'Sqlite',
+ 'className' => __NAMESPACE__ . '\FakeConnection',
'database' => ':memory:'
]);
$results = ConnectionManager::configured();
@@ -161,12 +161,13 @@ public function testConfigured() {
public function testGetPluginDataSource() {
Plugin::load('TestPlugin');
$name = 'test_variant';
- $config = array('className' => 'TestPlugin.TestSource');
+ $config = array('className' => 'TestPlugin.TestSource', 'foo' => 'bar');
ConnectionManager::config($name, $config);
$connection = ConnectionManager::get($name);
- $this->assertInstanceOf('Cake\Database\Connection', $connection);
- $this->assertInstanceOf('TestPlugin\Database\Driver\TestSource', $connection->driver());
+ $this->assertInstanceOf('TestPlugin\Datasource\TestSource', $connection);
+ unset($config['className']);
+ $this->assertSame($config + ['name' => 'test_variant'], $connection->settings);
}
/**
@@ -176,7 +177,7 @@ public function testGetPluginDataSource() {
*/
public function testDrop() {
ConnectionManager::config('test_variant', [
- 'className' => 'Sqlite',
+ 'className' => __NAMESPACE__ . '\FakeConnection',
'database' => ':memory:'
]);
$result = ConnectionManager::configured();
@@ -196,7 +197,7 @@ public function testDrop() {
*/
public function testAlias() {
ConnectionManager::config('test_variant', [
- 'className' => 'Sqlite',
+ 'className' => __NAMESPACE__ . '\FakeConnection',
'database' => ':memory:'
]);
ConnectionManager::alias('test_variant', 'other_name');
@@ -207,7 +208,7 @@ public function testAlias() {
/**
* Test alias() raises an error when aliasing an undefined connection.
*
- * @expectedException Cake\Error\MissingDatasourceConfigException
+ * @expectedException Cake\Datasource\Error\MissingDatasourceConfigException
* @return void
*/
public function testAliasError() {
View
119 tests/test_app/Plugin/TestPlugin/Database/Driver/TestSource.php
@@ -1,119 +0,0 @@
-<?php
-namespace TestPlugin\Database\Driver;
-
-use Cake\Database\Driver;
-
-class TestSource extends Driver {
-
-/**
- * Establishes a connection to the database server
- *
- * @return boolean true con success
- */
- public function connect() {
- }
-
-/**
- * Disconnects from database server
- *
- * @return void
- */
- public function disconnect() {
- }
-
-/**
- * Returns correct connection resource or object that is internally used
- * If first argument is passed,
- *
- * @return void
- */
- public function connection($connection = null) {
- }
-
-/**
- * Returns whether php is able to use this driver for connecting to database
- *
- * @return boolean true if it is valid to use this driver
- */
- public function enabled() {
- return true;
- }
-
-/**
- * Prepares a sql statement to be executed
- *
- * @param string $sql
- * @return Cake\Database\Statement
- */
- public function prepare($sql) {
- }
-
-/**
- * Starts a transaction
- *
- * @return boolean true on success, false otherwise
- */
- public function beginTransaction() {
- }
-
-/**
- * Commits a transaction
- *
- * @return boolean true on success, false otherwise
- */
- public function commitTransaction() {
- }
-
-/**
- * Rollsback a transaction
- *
- * @return boolean true on success, false otherwise
- */
- public function rollbackTransaction() {
- }
-
-/**
- * Returns a value in a safe representation to be used in a query string
- *
- * @return string
- */
- public function quote($value, $type) {
- }
-
-/**
- * Returns a callable function that will be used to transform a passed Query object.
- * This function, in turn, will return an instance of a Query object that has been
- * transformed to accommodate any specificities of the SQL dialect in use.
- *
- * @param string $type the type of query to be transformed
- * (select, insert, update, delete)
- * @return callable
- */
- public function queryTranslator($type) {
- }
-
-/**
- * Get the schema dialect.
- *
- * Used by Cake\Database\Schema package to reflect schema and
- * generate schema.
- *
- * If all the tables that use this Driver specify their
- * own schemas, then this may return null.
- *
- * @return Cake\Database\Schema\BaseSchema
- */
- public function schemaDialect() {
- }
-
-/**
- * Quotes a database identifier (a column name, table name, etc..) to
- * be used safely in queries without the risk of using reserved words
- *
- * @param string $identifier
- * @return string
- */
- public function quoteIdentifier($identifier) {
- }
-
-}
View
23 tests/test_app/Plugin/TestPlugin/Datasource/TestSource.php
@@ -0,0 +1,23 @@
+<?php
+namespace TestPlugin\Datasource;
+
+
+class TestSource {
+
+/**
+ * Settings
+ *
+ * @var array
+ */
+ public $settings;
+
+/**
+ * Constructor
+ *
+ * @return void
+ */
+ public function __construct(array $settings) {
+ $this->settings = $settings;
+ }
+
+}

0 comments on commit 8eec058

Please sign in to comment.