Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
10 / 12
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_dbal_connect_test
83.33% covered (warning)
83.33%
10 / 12
50.00% covered (danger)
50.00%
1 / 2
5.12
0.00% covered (danger)
0.00%
0 / 1
 getDataSet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_failing_connect
81.82% covered (warning)
81.82%
9 / 11
0.00% covered (danger)
0.00%
0 / 1
4.10
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_dbal_connect_test extends phpbb_database_test_case
15{
16    public function getDataSet()
17    {
18        return $this->createXMLDataSet(__DIR__ . '/../fixtures/empty.xml');
19    }
20
21    public function test_failing_connect()
22    {
23        global $phpbb_filesystem;
24
25        $phpbb_filesystem = new phpbb\filesystem\filesystem();
26
27        $config = $this->get_database_config();
28
29        $db = new $config['dbms']();
30
31        // Failure to connect results in a trigger_error call in dbal.
32        // phpunit converts triggered errors to exceptions.
33        // In particular there should be no fatals here.
34        if ($db->get_sql_layer() === 'mysqli')
35        {
36            $this->setExpectedTriggerError(E_WARNING);
37        }
38        else if ($db->get_sql_layer() !== 'sqlite3')
39        {
40            $this->setExpectedTriggerError(E_USER_ERROR);
41        }
42
43        // For SQLite3, connection will be successful anyway as phpBB driver uses SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE flags
44        $result = $db->sql_connect($config['dbhost'], 'phpbbogus', 'phpbbogus', 'phpbbogus', $config['dbport']);
45
46        if ($db->get_sql_layer() === 'sqlite3')
47        {
48            $this->assertTrue($result);
49        }
50    }
51}