#2821 reverting BC break - moved static exception constructor to a new method to avoid API changes

parent f01b7823
......@@ -213,7 +213,7 @@ class Connection implements DriverConnection
if (isset($params["platform"])) {
if ( ! $params['platform'] instanceof Platforms\AbstractPlatform) {
throw DBALException::invalidPlatformSpecified($params['platform']);
throw DBALException::invalidPlatformType($params['platform']);
}
$this->platform = $params["platform"];
......
......@@ -36,21 +36,24 @@ class DBALException extends \Exception
return new self("Operation '$method' is not supported by platform.");
}
public static function invalidPlatformSpecified() : self
{
return new self(
"Invalid 'platform' option specified, need to give an instance of ".
"\Doctrine\DBAL\Platforms\AbstractPlatform.");
}
/**
* Returns a new instance for an invalid platform specified.
*
* @param mixed $invalidPlatform The invalid platform given.
*
* @return DBALException
* @param mixed $invalidPlatform
*/
public static function invalidPlatformSpecified($invalidPlatform): self
public static function invalidPlatformType($invalidPlatform) : self
{
if (is_object($invalidPlatform)) {
if (\is_object($invalidPlatform)) {
return new self(
sprintf(
"Option 'platform' must be a subtype of '%s', instance of '%s' given",
AbstractPlatform::class,
get_class($invalidPlatform)
\get_class($invalidPlatform)
)
);
}
......@@ -59,7 +62,7 @@ class DBALException extends \Exception
sprintf(
"Option 'platform' must be an object and subtype of '%s'. Got '%s'",
AbstractPlatform::class,
gettype($invalidPlatform)
\gettype($invalidPlatform)
)
);
}
......
......@@ -62,9 +62,9 @@ class DBALExceptionTest extends DbalTestCase
/**
* @group DBAL-2821
*/
public function testInvalidPlatformSpecifiedObject(): void
public function testInvalidPlatformTypeObject(): void
{
$exception = DBALException::invalidPlatformSpecified(new \stdClass());
$exception = DBALException::invalidPlatformType(new \stdClass());
self::assertSame(
"Option 'platform' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform', instance of 'stdClass' given",
......@@ -75,9 +75,9 @@ class DBALExceptionTest extends DbalTestCase
/**
* @group DBAL-2821
*/
public function testInvalidPlatformSpecifiedScalar(): void
public function testInvalidPlatformTypeScalar(): void
{
$exception = DBALException::invalidPlatformSpecified("some string");
$exception = DBALException::invalidPlatformType('some string');
self::assertSame(
"Option 'platform' must be an object and subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform'. Got 'string'",
......
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