This repository was archived by the owner on May 16, 2020. It is now read-only.
forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectTest.php
More file actions
76 lines (57 loc) · 2.11 KB
/
Copy pathConnectTest.php
File metadata and controls
76 lines (57 loc) · 2.11 KB
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
<?php namespace CodeIgniter\Database\Live;
use CodeIgniter\Config\Config;
use CodeIgniter\Test\CIDatabaseTestCase;
use Config\Database;
/**
* @group DatabaseLive
*/
class ConnectTest extends CIDatabaseTestCase
{
protected $group1;
protected $group2;
protected function setUp()
{
parent::setUp();
$config = config('Database');
$this->group1 = $config->default;
$this->group2 = $config->default;
$this->group1['DBDriver'] = 'MySQLi';
$this->group2['DBDriver'] = 'Postgre';
}
public function testConnectWithMultipleCustomGroups()
{
// We should have our test database connection already.
$instances = $this->getPrivateProperty(Database::class, 'instances');
$this->assertEquals(1, count($instances));
$db1 = Database::connect($this->group1);
$db2 = Database::connect($this->group2);
$this->assertNotSame($db1, $db2);
$instances = $this->getPrivateProperty(Database::class, 'instances');
$this->assertEquals(3, count($instances));
}
public function testConnectReturnsProvidedConnection()
{
$config = config('Database');
// This will be the tests database
$db = Database::connect();
$this->assertEquals($config->tests['DBDriver'], $this->getPrivateProperty($db, 'DBDriver'));
// Get an instance of the system's default db so we have something to test with.
$db1 = Database::connect($this->group1);
$this->assertEquals('MySQLi', $this->getPrivateProperty($db1, 'DBDriver'));
// If a connection is passed into connect, it should simply be returned to us...
$db2 = Database::connect($db1);
$this->assertSame($db1, $db2);
}
public function testConnectWorksWithGroupName()
{
$config = config('Database');
$db = Database::connect('tests');
$this->assertEquals($config->tests['DBDriver'], $this->getPrivateProperty($db, 'DBDriver'));
$config = config('Database');
$config->default['DBDriver'] = 'MySQLi';
Config::injectMock('Database', $config);
$db1 = Database::connect('default');
$this->assertNotInstanceOf(\CodeIgniter\Database\SQLite3\Connection::class, $db1);
$this->assertEquals('MySQLi', $this->getPrivateProperty($db1, 'DBDriver'));
}
}