Failed Conditions
Push — master ( ea968d...edfbda )
by Luís
18s
created

MysqliConnectionTest::testThrowsExceptionWhenMissingMandatorySecureParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Driver\Mysqli;
4
5
use Doctrine\DBAL\Driver\Mysqli\MysqliConnection;
6
use Doctrine\DBAL\Driver\Mysqli\MysqliException;
7
use Doctrine\Tests\DbalTestCase;
8
9
class MysqliConnectionTest extends DbalTestCase
10
{
11
    /**
12
     * The mysqli driver connection mock under test.
13
     *
14
     * @var \Doctrine\DBAL\Driver\Mysqli\MysqliConnection|\PHPUnit_Framework_MockObject_MockObject
15
     */
16
    private $connectionMock;
17
18
    protected function setUp()
19
    {
20
        if ( ! extension_loaded('mysqli')) {
21
            $this->markTestSkipped('mysqli is not installed.');
22
        }
23
24
        parent::setUp();
25
26
        $this->connectionMock = $this->getMockBuilder(MysqliConnection::class)
27
            ->disableOriginalConstructor()
28
            ->getMockForAbstractClass();
29
    }
30
31
    public function testDoesNotRequireQueryForServerVersion()
32
    {
33
        self::assertFalse($this->connectionMock->requiresQueryForServerVersion());
34
    }
35
36
    public function testRestoresErrorHandlerOnException()
37
    {
38
        $handler = function () { self::fail('Never expected this to be called'); };
39
        $default_handler = set_error_handler($handler);
40
41
        try {
42
            new MysqliConnection(['host' => '255.255.255.255'], 'user', 'pass');
43
            self::fail('An exception was supposed to be raised');
44
        } catch (MysqliException $e) {
45
            self::assertSame('Network is unreachable', $e->getMessage());
46
        }
47
48
        self::assertSame($handler, set_error_handler($default_handler), 'Restoring error handler failed.');
49
        restore_error_handler();
50
        restore_error_handler();
51
    }
52
53
}
54
55