Skip to content

Commit d1dc127

Browse files
committed
Update Propel2 to latest tests
1 parent 2d153d5 commit d1dc127

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

inProgress/Propel2/Tests.php

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ class Tests extends \SOB\Test
66
{
77
private \Propel\Runtime\Connection\ConnectionManagerSingle $manager;
88

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+
920
public function closeConnection() : void
1021
{
1122
$this->manager->closeConnections();
@@ -35,27 +46,17 @@ public function delete(int $id) : bool
3546
* * open the database
3647
* * initialize the database schema
3748
*/
38-
public function init(\SOB\Configuration $config) : static
49+
public function init(\SOB\Configuration $config, array $lines, \SOB\BaseLine $runTimer) : static
3950
{
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-
5251
$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();
5352
$serviceContainer->checkVersion(2);
5453

5554
$serviceContainer->setAdapterClass('default', $config->getDriver());
5655

5756
$this->manager = new \Propel\Runtime\Connection\ConnectionManagerSingle('default');
5857

58+
$connection = $config->getPDOConnectionString();
59+
5960
$this->manager->setConfiguration([
6061
'dsn' => $connection,
6162
'user' => $config->getUser(),
@@ -127,27 +128,9 @@ public function init(\SOB\Configuration $config) : static
127128
],
128129
]);
129130

130-
$sql = '';
131+
$this->connection = \Propel\Runtime\Propel::getServiceContainer()->getWriteConnection('default');
131132

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);
151134

152135
return $this;
153136
}

0 commit comments

Comments
 (0)