Unverified Commit c9694b73 authored by Kim Hemsø Rasmussen's avatar Kim Hemsø Rasmussen Committed by Marco Pivetta

Changed DBALException::invalidPlatformSpecified() exception to be more...

Changed DBALException::invalidPlatformSpecified() exception to be more detailed about what was given.
parent 8a21c170
...@@ -213,7 +213,7 @@ class Connection implements DriverConnection ...@@ -213,7 +213,7 @@ class Connection implements DriverConnection
if (isset($params["platform"])) { if (isset($params["platform"])) {
if ( ! $params['platform'] instanceof Platforms\AbstractPlatform) { if ( ! $params['platform'] instanceof Platforms\AbstractPlatform) {
throw DBALException::invalidPlatformSpecified(); throw DBALException::invalidPlatformSpecified($params['platform']);
} }
$this->platform = $params["platform"]; $this->platform = $params["platform"];
......
...@@ -22,6 +22,7 @@ namespace Doctrine\DBAL; ...@@ -22,6 +22,7 @@ namespace Doctrine\DBAL;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\ExceptionConverterDriver; use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class DBALException extends \Exception class DBALException extends \Exception
{ {
...@@ -36,13 +37,19 @@ class DBALException extends \Exception ...@@ -36,13 +37,19 @@ class DBALException extends \Exception
} }
/** /**
* @return \Doctrine\DBAL\DBALException * @param $invalidPlatform
* @return DBALException
*/ */
public static function invalidPlatformSpecified() public static function invalidPlatformSpecified($invalidPlatform): self
{ {
return new self( return new self(
"Invalid 'platform' option specified, need to give an instance of ". sprintf(
"\Doctrine\DBAL\Platforms\AbstractPlatform."); "Given 'platform' option '%s' must be a subtype of '%s'",
get_class($invalidPlatform),
AbstractPlatform::class
)
);
} }
/** /**
......
...@@ -7,6 +7,7 @@ use Doctrine\Common\EventManager; ...@@ -7,6 +7,7 @@ use Doctrine\Common\EventManager;
use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
...@@ -818,6 +819,25 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase ...@@ -818,6 +819,25 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
(new Connection($connectionParams, $driver))->executeCacheQuery($query, [], [], $queryCacheProfileMock); (new Connection($connectionParams, $driver))->executeCacheQuery($query, [], [], $queryCacheProfileMock);
} }
/**
* @group DBAL-2821
*/
public function testThrowsExceptionWhenInValidPlatformSpecified(): void
{
self::expectException(DBALException::class);
self::expectExceptionMessage(
"Given 'platform' option 'stdClass' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform'"
);
$connectionParams = $this->params;
$connectionParams['platform'] = new \stdClass();
/* @var $driver Driver */
$driver = $this->createMock(Driver::class);
new Connection($connectionParams, $driver);
}
/** /**
* @group DBAL-990 * @group DBAL-990
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment