Skip to content

Commit

Permalink
Merge pull request #3566 from morozov/phpunit-816
Browse files Browse the repository at this point in the history
Upgraded to PHPUnit 8.1.6 and reworked the remaining driver exception mock
  • Loading branch information
morozov committed May 28, 2019
2 parents 5b64cbd + a7acb47 commit a2450fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -41,7 +41,7 @@
"doctrine/coding-standard": "^6.0",
"jetbrains/phpstorm-stubs": "^2018.1.2",
"phpstan/phpstan": "^0.11.3",
"phpunit/phpunit": "^8.1.5",
"phpunit/phpunit": "^8.1.6",
"symfony/console": "^2.0.5|^3.0|^4.0|^5.0",
"symfony/phpunit-bridge": "^3.4.5|^4.0.5|^5.0"
},
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 9 additions & 35 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php
Expand Up @@ -28,7 +28,7 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\Tests\DbalTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionProperty;
use function array_merge;
use function get_class;
Expand Down Expand Up @@ -77,40 +77,14 @@ public function testConvertsException($errorCode, $sqlState, $message, string $e
$this->markTestSkipped('This test is only intended for exception converter drivers.');
}

$driverException = new class ($errorCode, $sqlState, $message)
extends Exception
implements DriverExceptionInterface
{
/** @var mixed */
private $errorCode;

/** @var mixed */
private $sqlState;

public function __construct($errorCode, $sqlState, $message)
{
parent::__construct($message);

$this->errorCode = $errorCode;
$this->sqlState = $sqlState;
}

/**
* {@inheritDoc}
*/
public function getErrorCode()
{
return $this->errorCode;
}

/**
* {@inheritDoc}
*/
public function getSQLState()
{
return $this->sqlState;
}
};
/** @var DriverExceptionInterface|MockObject $driverException */
$driverException = $this->getMockBuilder(DriverExceptionInterface::class)
->setConstructorArgs([$message])
->getMock();
$driverException->method('getErrorCode')
->willReturn($errorCode);
$driverException->method('getSQLState')
->willReturn($sqlState);

$dbalMessage = 'DBAL exception message';
$dbalException = $this->driver->convertException($dbalMessage, $driverException);
Expand Down

0 comments on commit a2450fb

Please sign in to comment.