1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Tests\Driver\Mysqli; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Driver\Mysqli\Exception\ConnectionError; |
8
|
|
|
use Doctrine\DBAL\Driver\Mysqli\HostRequired; |
9
|
|
|
use Doctrine\DBAL\Driver\Mysqli\MysqliConnection; |
10
|
|
|
use Doctrine\DBAL\Platforms\MySqlPlatform; |
11
|
|
|
use Doctrine\DBAL\Tests\FunctionalTestCase; |
12
|
|
|
use function extension_loaded; |
13
|
|
|
use function restore_error_handler; |
14
|
|
|
use function set_error_handler; |
15
|
|
|
|
16
|
|
|
class MysqliConnectionTest extends FunctionalTestCase |
17
|
|
|
{ |
18
|
|
|
protected function setUp() : void |
19
|
|
|
{ |
20
|
|
|
if (! extension_loaded('mysqli')) { |
21
|
|
|
self::markTestSkipped('mysqli is not installed.'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) { |
27
|
|
|
return; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
self::markTestSkipped('MySQL only test.'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testRestoresErrorHandlerOnException() : void |
34
|
|
|
{ |
35
|
|
|
$handler = static function () : bool { |
36
|
|
|
self::fail('Never expected this to be called'); |
|
|
|
|
37
|
|
|
}; |
38
|
|
|
set_error_handler($handler); |
39
|
|
|
|
40
|
|
|
try { |
41
|
|
|
new MysqliConnection(['host' => '255.255.255.255'], 'user', 'pass'); |
42
|
|
|
self::fail('An exception was supposed to be raised'); |
43
|
|
|
} catch (ConnectionError $e) { |
44
|
|
|
// Do nothing |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
self::assertSame($handler, set_error_handler($handler), 'Restoring error handler failed.'); |
48
|
|
|
restore_error_handler(); |
49
|
|
|
restore_error_handler(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testHostnameIsRequiredForPersistentConnection() : void |
53
|
|
|
{ |
54
|
|
|
$this->expectException(HostRequired::class); |
55
|
|
|
new MysqliConnection(['persistent' => 'true'], '', ''); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: