Commit cc9dcc3e authored by Kim Hemsø Rasmussen's avatar Kim Hemsø Rasmussen

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

Changed DBALException::invalidPlatformSpecified() exception to be more detailed about what was given.
parent 776d2e89
......@@ -213,7 +213,7 @@ class Connection implements DriverConnection
if (isset($params["platform"])) {
if ( ! $params['platform'] instanceof Platforms\AbstractPlatform) {
throw DBALException::invalidPlatformSpecified();
throw DBALException::invalidPlatformSpecified($params['platform']);
}
$this->platform = $params["platform"];
......
......@@ -22,6 +22,7 @@ namespace Doctrine\DBAL;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
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(
"Invalid 'platform' option specified, need to give an instance of ".
"\Doctrine\DBAL\Platforms\AbstractPlatform.");
sprintf(
"Given 'platform' option '%s' must be a subtype of '%s'",
get_class($invalidPlatform),
AbstractPlatform::class
)
);
}
/**
......
......@@ -7,6 +7,7 @@ use Doctrine\Common\EventManager;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Platforms\AbstractPlatform;
......@@ -818,6 +819,25 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
(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
*/
......
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