Skip to content

Commit 8f189ed

Browse files
committed
Adding flush for Doctrine
1 parent 5187c16 commit 8f189ed

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

SOB/Doctrine/Tests.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public function init(\SOB\Configuration $config) : static
106106
return $this;
107107
}
108108

109+
public function flush() : void
110+
{
111+
$this->entityManager->flush();
112+
}
113+
109114
/**
110115
* class must insert one record with id=$id
111116
*

SOB/Test.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ final public function __construct()
1414
{
1515
}
1616

17+
/**
18+
* override to flush buffers between tests if needed
19+
*/
20+
public function flush() : void
21+
{
22+
}
23+
1724
/**
1825
* Close the database connection
1926
*/

SOB/TestRunner.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function runTests() : bool
6161
$this->test($tester, $config);
6262
$this->addResults($this->currentResults);
6363
$tester->closeConnection();
64+
$tester = null;
6465
}
6566

6667
return true;
@@ -98,10 +99,17 @@ private function test(\SOB\Test $tester, \SOB\Configuration $config) : bool
9899

99100
echo "Executing insert test\n";
100101

102+
$id = 0;
101103
for ($i = 1; $i <= $iterations; ++$i)
102104
{
103-
$tester->insert($i);
105+
$newId = $tester->insert($i);
106+
if ($newId <= $id)
107+
{
108+
throw new \Exception('Failed to insert ' . $newId);
109+
}
110+
$id = $newId;
104111
}
112+
$tester->flush();
105113
$this->setResult('Insert', $timer);
106114

107115
$timer = new \SOB\BaseLine();
@@ -112,6 +120,7 @@ private function test(\SOB\Test $tester, \SOB\Configuration $config) : bool
112120
{
113121
$tester->testUpdate($tester->read($i), "Last {$i}");
114122
}
123+
$tester->flush();
115124
$this->setResult('Read', $timer);
116125

117126
$timer = new \SOB\BaseLine();
@@ -120,6 +129,7 @@ private function test(\SOB\Test $tester, \SOB\Configuration $config) : bool
120129
{
121130
$tester->update($i, $i + $this->updateOffset);
122131
}
132+
$tester->flush();
123133
$this->setResult('Update', $timer);
124134

125135
$timer = new \SOB\BaseLine();
@@ -155,6 +165,7 @@ private function test(\SOB\Test $tester, \SOB\Configuration $config) : bool
155165
throw new \Exception('Failed to delete ' . $i);
156166
}
157167
}
168+
$tester->flush();
158169
$this->setResult('Delete', $timer);
159170

160171
$this->setResult('Total Runtime', $runTime);

0 commit comments

Comments
 (0)