@@ -6,6 +6,17 @@ class Tests extends \SOB\Test
6
6
{
7
7
private \Propel \Runtime \Connection \ConnectionManagerSingle $ manager ;
8
8
9
+ private $ connection ;
10
+
11
+ public function runSQL (string $ sql ) : void
12
+ {
13
+ if ($ sql )
14
+ {
15
+ $ stmt = $ this ->connection ->prepare ($ sql );
16
+ $ res = $ stmt ->execute ();
17
+ }
18
+ }
19
+
9
20
public function closeConnection () : void
10
21
{
11
22
$ this ->manager ->closeConnections ();
@@ -35,27 +46,17 @@ public function delete(int $id) : bool
35
46
* * open the database
36
47
* * initialize the database schema
37
48
*/
38
- public function init (\SOB \Configuration $ config ) : static
49
+ public function init (\SOB \Configuration $ config, array $ lines , \ SOB \ BaseLine $ runTimer ) : static
39
50
{
40
- $ connection = $ config ->getPDOConnectionString ();
41
-
42
- if (\str_contains ($ connection , 'sqlite ' ))
43
- {
44
- $ lines = \file (__DIR__ . '/../../northwind/northwind-schema.sqlite ' );
45
- \fclose (\fopen ($ config ->getNamespace () . '.sqlite ' , 'w ' ));
46
- }
47
- else
48
- {
49
- $ lines = \file (__DIR__ . '/../../northwind/northwind-schema.sql ' );
50
- }
51
-
52
51
$ serviceContainer = \Propel \Runtime \Propel::getServiceContainer ();
53
52
$ serviceContainer ->checkVersion (2 );
54
53
55
54
$ serviceContainer ->setAdapterClass ('default ' , $ config ->getDriver ());
56
55
57
56
$ this ->manager = new \Propel \Runtime \Connection \ConnectionManagerSingle ('default ' );
58
57
58
+ $ connection = $ config ->getPDOConnectionString ();
59
+
59
60
$ this ->manager ->setConfiguration ([
60
61
'dsn ' => $ connection ,
61
62
'user ' => $ config ->getUser (),
@@ -127,27 +128,9 @@ public function init(\SOB\Configuration $config) : static
127
128
],
128
129
]);
129
130
130
- $ sql = '' ;
131
+ $ this -> connection = \ Propel \ Runtime \Propel:: getServiceContainer ()-> getWriteConnection ( ' default ' ) ;
131
132
132
- $ connection = \Propel \Runtime \Propel::getServiceContainer ()->getWriteConnection ('default ' );
133
-
134
- foreach ($ lines as $ line )
135
- {
136
- // Ignoring comments from the SQL script
137
- if (\str_starts_with ((string )$ line , '-- ' ) || '' == $ line )
138
- {
139
- continue ;
140
- }
141
-
142
- $ sql .= $ line ;
143
-
144
- if (\str_ends_with (\trim ((string )$ line ), '; ' ))
145
- {
146
- $ stmt = $ connection ->prepare ($ sql );
147
- $ res = $ stmt ->execute ();
148
- $ sql = '' ;
149
- }
150
- } // end foreach
133
+ $ this ->loadSchema ($ lines , [$ this , 'runSQL ' ], $ runTimer );
151
134
152
135
return $ this ;
153
136
}
0 commit comments