Skip to content

Commit

Permalink
#2821 reverting BC break - moved static exception constructor to a ne…
Browse files Browse the repository at this point in the history
…w method to avoid API changes
  • Loading branch information
Ocramius committed Aug 28, 2017
1 parent 2d57c68 commit 1119a3d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function __construct(array $params, Driver $driver, Configuration $config

if (isset($params["platform"])) {
if ( ! $params['platform'] instanceof Platforms\AbstractPlatform) {
throw DBALException::invalidPlatformSpecified($params['platform']);
throw DBALException::invalidPlatformType($params['platform']);
}

$this->platform = $params["platform"];
Expand Down
21 changes: 12 additions & 9 deletions lib/Doctrine/DBAL/DBALException.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,24 @@ public static function notSupported($method)
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)
)
);
}
Expand All @@ -59,7 +62,7 @@ public static function invalidPlatformSpecified($invalidPlatform): self
sprintf(
"Option 'platform' must be an object and subtype of '%s'. Got '%s'",
AbstractPlatform::class,
gettype($invalidPlatform)
\gettype($invalidPlatform)
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public function testDriverRequiredWithUrl()
/**
* @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",
Expand All @@ -75,9 +75,9 @@ public function testInvalidPlatformSpecifiedObject(): void
/**
* @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'",
Expand Down

0 comments on commit 1119a3d

Please sign in to comment.