1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Driver\Middleware;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use PHPUnit\Framework\TestCase;
final class AbstractConnectionMiddlewareTest extends TestCase
{
public function testPrepare(): void
{
$statement = $this->createMock(Statement::class);
$connection = $this->createMock(Connection::class);
$connection->expects(self::once())
->method('prepare')
->with('SELECT 1')
->willReturn($statement);
self::assertSame($statement, $this->createMiddleware($connection)->prepare('SELECT 1'));
}
public function testQuery(): void
{
$result = $this->createMock(Result::class);
$connection = $this->createMock(Connection::class);
$connection->expects(self::once())
->method('query')
->with('SELECT 1')
->willReturn($result);
self::assertSame($result, $this->createMiddleware($connection)->query('SELECT 1'));
}
public function testExec(): void
{
$connection = $this->createMock(Connection::class);
$connection->expects(self::once())
->method('exec')
->with('UPDATE foo SET bar=\'baz\' WHERE some_field > 0')
->willReturn(42);
self::assertSame(
42,
$this->createMiddleware($connection)->exec('UPDATE foo SET bar=\'baz\' WHERE some_field > 0'),
);
}
public function testGetServerVersion(): void
{
$connection = $this->createMock(Connection::class);
$connection->expects(self::once())
->method('getServerVersion')
->willReturn('1.2.3');
self::assertSame('1.2.3', $this->createMiddleware($connection)->getServerVersion());
}
public function testGetNativeConnection(): void
{
$nativeConnection = new class () {
};
$connection = $this->createMock(Connection::class);
$connection->method('getNativeConnection')
->willReturn($nativeConnection);
self::assertSame($nativeConnection, $this->createMiddleware($connection)->getNativeConnection());
}
private function createMiddleware(Connection $connection): AbstractConnectionMiddleware
{
return new class ($connection) extends AbstractConnectionMiddleware {
};
}
}
|