Skip to content
Permalink
Browse files

Database\Error -> Database\Exception

  • Loading branch information...
lorenzo committed Aug 30, 2014
1 parent 5d30e68 commit 3f6ffe33dd4e8de31e0b420b2c426d13512e8b82
@@ -14,6 +14,9 @@
*/
namespace Cake\Database;
use Cake\Database\Exception\MissingConnectionException;
use Cake\Database\Exception\MissingDriverException;
use Cake\Database\Exception\MissingExtensionException;
use Cake\Database\Log\LoggedQuery;
use Cake\Database\Log\LoggingStatement;
use Cake\Database\Log\QueryLogger;
@@ -135,8 +138,8 @@ public function configName() {
*
* @param string|\Cake\Database\Driver $driver The driver instance to use.
* @param array|null $config Either config for a new driver or null.
* @throws \Cake\Database\Error\MissingDriverException When a driver class is missing.
* @throws \Cake\Database\Error\MissingExtensionException When a driver's PHP extension is missing.
* @throws \Cake\Database\Exception\MissingDriverException When a driver class is missing.
* @throws \Cake\Database\Exception\MissingExtensionException When a driver's PHP extension is missing.
* @return \Cake\Database\Driver
*/
public function driver($driver = null, $config = null) {
@@ -145,28 +148,28 @@ public function driver($driver = null, $config = null) {
}
if (is_string($driver)) {
if (!class_exists($driver)) {
throw new Error\MissingDriverException(['driver' => $driver]);
throw new MissingDriverException(['driver' => $driver]);
}
$driver = new $driver($config);
}
if (!$driver->enabled()) {
throw new Error\MissingExtensionException(['driver' => get_class($driver)]);
throw new MissingExtensionException(['driver' => get_class($driver)]);
}
return $this->_driver = $driver;
}
/**
* Connects to the configured database.
*
* @throws \Cake\Database\Error\MissingConnectionException if credentials are invalid
* @throws \Cake\Database\Exception\MissingConnectionException if credentials are invalid
* @return bool true on success or false if already connected.
*/
public function connect() {
try {
$this->_driver->connect();
return true;
} catch(\Exception $e) {
throw new Error\MissingConnectionException(['reason' => $e->getMessage()]);
throw new MissingConnectionException(['reason' => $e->getMessage()]);
}
}
@@ -12,7 +12,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Database\Error;
namespace Cake\Database\Exception;
use Cake\Core\Exception\Exception;
@@ -12,7 +12,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Database\Error;
namespace Cake\Database\Exception;
use Cake\Core\Exception\Exception;
@@ -12,7 +12,7 @@
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Database\Error;
namespace Cake\Database\Exception;
use Cake\Core\Exception\Exception;
@@ -64,7 +64,7 @@ public function testConnect() {
/**
* Tests creating a connection using no driver throws an exception
*
* @expectedException \Cake\Database\Error\MissingDriverException
* @expectedException \Cake\Database\Exception\MissingDriverException
* @expectedExceptionMessage Database driver could not be found.
* @return void
*/
@@ -75,7 +75,7 @@ public function testNoDriver() {
/**
* Tests creating a connection using an invalid driver throws an exception
*
* @expectedException \Cake\Database\Error\MissingDriverException
* @expectedException \Cake\Database\Exception\MissingDriverException
* @expectedExceptionMessage Database driver could not be found.
* @return void
*/
@@ -86,7 +86,7 @@ public function testEmptyDriver() {
/**
* Tests creating a connection using an invalid driver throws an exception
*
* @expectedException \Cake\Database\Error\MissingDriverException
* @expectedException \Cake\Database\Exception\MissingDriverException
* @expectedExceptionMessage Database driver \Foo\InvalidDriver could not be found.
* @return void
*/
@@ -97,7 +97,7 @@ public function testMissingDriver() {
/**
* Tests trying to use a disabled driver throws an exception
*
* @expectedException \Cake\Database\Error\MissingExtensionException
* @expectedException \Cake\Database\Exception\MissingExtensionException
* @expectedExceptionMessage Database driver DriverMock cannot be used due to a missing PHP extension or unmet dependency
* @return void
*/
@@ -109,7 +109,7 @@ public function testDisabledDriver() {
/**
* Tests that connecting with invalid credentials or database name throws an exception
*
* @expectedException \Cake\Database\Error\MissingConnectionException
* @expectedException \Cake\Database\Exception\MissingConnectionException
* @return void
*/
public function testWrongCredentials() {

0 comments on commit 3f6ffe3

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