-
Notifications
You must be signed in to change notification settings - Fork 6
/
ConnectionTest.php
169 lines (129 loc) · 4.17 KB
/
ConnectionTest.php
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
namespace TestTools\Tests\Doctrine\DBAL;
use TestTools\Fixture\Exception\OfflineException;
use TestTools\TestCase\UnitTestCase;
/**
* @author Michael Mayer <michael@lastzero.net>
* @package TestTools
* @license MIT
*/
class ConnectionTest extends UnitTestCase
{
/**
* @var \TestTools\Doctrine\DBAL\Connection
*/
protected $db;
public function setUp()
{
$this->db = $this->get('dbal.connection');
}
public function testUsesFixtures()
{
$this->assertTrue($this->db->usesFixtures());
}
public function testFixtureOfflineMode()
{
$this->assertFalse($this->db->fixtureOfflineModeEnabled());
$this->db->enableFixtureOfflineMode();
$this->assertTrue($this->db->fixtureOfflineModeEnabled());
try {
$this->db->fetchAll('SELECT * FROM example');
$this->fail('OfflineException was not thrown');
} catch (OfflineException $e) {
// OK
}
$this->db->disableFixtureOfflineMode();
$this->assertFalse($this->db->fixtureOfflineModeEnabled());
}
public function testFetchAll()
{
$expected = array(
array('id' => 1, 'username' => 'Foo', 'email' => 'foo@bar.com'),
array('id' => 2, 'username' => 'Michael', 'email' => 'michael@bar.com'),
array('id' => 3, 'username' => 'Alex', 'email' => 'alex@foo.com'),
array('id' => 4, 'username' => 'Bender', 'email' => 'bender@ilovebender.com'),
array('id' => 5, 'username' => 'Bill', 'email' => 'bill@bar.com')
);
$result = $this->db->fetchAll('SELECT * FROM users');
$this->assertEquals($expected, $result);
}
public function testFetchAssoc()
{
$expected = array('id' => 2, 'username' => 'Michael', 'email' => 'michael@bar.com');
$result = $this->db->fetchAssoc('SELECT * FROM users WHERE id = 2');
$this->assertEquals($expected, $result);
}
public function testFetchArray()
{
$expected = array(2, 'Michael', 'michael@bar.com');
$result = $this->db->fetchArray('SELECT * FROM users WHERE id = 2');
$this->assertEquals($expected, $result);
}
public function testFetchColumn()
{
$expected = 'Michael';
$result = $this->db->fetchColumn('SELECT username FROM users WHERE id = 2');
$this->assertEquals($expected, $result);
}
public function testInsert()
{
$expected = 1;
$row = array('username' => 'Jens', 'email' => 'jens@testtools.com');
$result = $this->db->insert('users', $row);
$this->assertEquals($expected, $result);
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testInsertException()
{
$row = array('username' => 'Baz', 'foo' => 'bar', 'email' => 'baz@example.com');
$this->db->insert('users', $row);
}
/**
* @depends testInsert
*/
public function testLastInsertId()
{
$expected = 7;
$row = array('username' => 'New', 'email' => 'new@example.com');
$this->db->insert('users', $row);
$result = $this->db->lastInsertId();
$this->assertEquals($expected, $result);
}
/**
* @depends testInsert
*/
public function testUpdate()
{
$expected = 1;
$result = $this->db->update('users', array('username' => 'Changed'), array('id' => 3));
$this->assertEquals($expected, $result);
}
/**
* @depends testInsert
*/
public function testDelete()
{
$expected = 1;
$result = $this->db->delete('users', array('id' => 3));
$this->assertEquals($expected, $result);
}
public function testCommit()
{
$this->db->beginTransaction();
$this->db->commit();
$this->assertTrue(true);
}
public function testRollBack()
{
$this->db->beginTransaction();
$this->db->rollBack();
$this->assertTrue(true);
}
public function testGetDatabasePlatform()
{
$result = $this->db->getDatabasePlatform();
$this->assertInstanceOf('\Doctrine\DBAL\Platforms\MySqlPlatform', $result);
}
}