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