File: ConnectionTest.php

package info (click to toggle)
php-doctrine-dbal 3.6.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,500 kB
  • sloc: php: 54,704; xml: 485; makefile: 42; sh: 24
file content (67 lines) | stat: -rw-r--r-- 2,058 bytes parent folder | download
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
<?php

namespace Doctrine\DBAL\Tests\Portability;

use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Portability\Connection;
use Doctrine\DBAL\Portability\Converter;
use LogicException;
use PHPUnit\Framework\TestCase;

class ConnectionTest extends TestCase
{
    public function testGetServerVersion(): void
    {
        $driverConnection = $this->createMock(ServerInfoAwareConnection::class);
        $driverConnection->expects(self::once())
            ->method('getServerVersion')
            ->willReturn('1.2.3');

        $connection = new Connection($driverConnection, new Converter(false, false, 0));

        self::assertSame('1.2.3', $connection->getServerVersion());
    }

    public function testGetServerVersionFailsWithLegacyConnection(): void
    {
        $connection = new Connection(
            $this->createMock(DriverConnection::class),
            new Converter(false, false, 0),
        );

        $this->expectException(LogicException::class);
        $connection->getServerVersion();
    }

    public function testGetNativeConnection(): void
    {
        $nativeConnection = new class () {
        };

        $driverConnection = $this->createMock(NativeDriverConnection::class);
        $driverConnection->method('getNativeConnection')
            ->willReturn($nativeConnection);

        $connection = new Connection($driverConnection, new Converter(false, false, 0));

        self::assertSame($nativeConnection, $connection->getNativeConnection());
    }

    public function testGetNativeConnectionFailsWithLegacyConnection(): void
    {
        $connection = new Connection(
            $this->createMock(DriverConnection::class),
            new Converter(false, false, 0),
        );

        $this->expectException(LogicException::class);
        $connection->getNativeConnection();
    }
}

interface NativeDriverConnection extends ServerInfoAwareConnection
{
    /** @return object|resource */
    public function getNativeConnection();
}