22namespace PhpOrm \Tests ;
33
44use PHPUnit \Framework \TestCase ;
5- use PhpOrm \Connection ;
65use PhpOrm \Configuration ;
6+ use PhpOrm \Connection ;
77
88class ConnectionTest extends TestCase
99{
10+ public static function getConfiguration ()
11+ {
12+ return new Configuration (
13+ 'root ' ,
14+ 'secret ' ,
15+ 'test ' ,
16+ 'localhost ' ,
17+ 3306 ,
18+ 'mysql ' ,
19+ 'utf8mb4 ' ,
20+ 'utf8mb4_general_ci '
21+ );
22+ }
23+
1024 public function testAttributes ()
1125 {
1226 $ attributes = array (
@@ -20,18 +34,47 @@ public function testAttributes()
2034
2135 public function testDependencyInjection ()
2236 {
23- $ configuration = new Configuration (
24- 'root ' ,
25- 'secret ' ,
26- 'test ' ,
27- 'localhost ' ,
28- 3306 ,
29- 'mysql ' ,
30- 'utf8mb4 ' ,
31- 'utf8mb4_general_ci '
32- );
37+ $ configuration = self ::getConfiguration ();
3338 $ connection = new Connection ($ configuration );
3439
3540 $ this ->assertSame ('mysql:host=localhost;port=3306;dbname=test;charset=utf8mb4 ' , $ connection ->getDsn ());
3641 }
42+
43+ public function testConnectFailed ()
44+ {
45+ $ configuration = self ::getConfiguration ();
46+ $ connection = new Connection ($ configuration );
47+
48+ $ this ->expectException (\Exception::class);
49+
50+ $ connection ->connect ();
51+ }
52+
53+ public function testDisconnect ()
54+ {
55+ $ configuration = self ::getConfiguration ();
56+ $ connection = new Connection ($ configuration );
57+
58+ $ connection ->disconnect ();
59+
60+ $ this ->assertNull ($ connection ->getDbh ());
61+ }
62+
63+ public function testReconnectFailed ()
64+ {
65+ $ configuration = self ::getConfiguration ();
66+ $ connection = new Connection ($ configuration );
67+
68+ $ this ->expectException (\Exception::class);
69+
70+ $ connection ->reconnect ();
71+ }
72+
73+ public function testDbhFailed ()
74+ {
75+ $ configuration = self ::getConfiguration ();
76+ $ connection = new Connection ($ configuration );
77+
78+ $ this ->assertNull ($ connection ->getDbh ());
79+ }
3780}
0 commit comments