Skip to content

Commit 38a5fe3

Browse files
committed
Adding PHPFUIBatch
1 parent 8e6128f commit 38a5fe3

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

SOB/PHPFUIBatch/Tests.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace SOB\PHPFUIBatch;
4+
5+
class Tests extends \SOB\PHPFUI\Tests
6+
{
7+
/** @var array<int> $deletes */
8+
private array $deletes = [];
9+
10+
/** @var array<\SOB\PHPFUI\Record\Employee> $inserts */
11+
private array $inserts = [];
12+
/**
13+
* class must delete one record with id=$id
14+
*/
15+
public function delete(int $id) : bool
16+
{
17+
$this->deletes[] = $id;
18+
19+
return true;
20+
}
21+
22+
/**
23+
* override to flush buffers between tests if needed
24+
*/
25+
public function flush() : void
26+
{
27+
if ($this->deletes)
28+
{
29+
$table = new \SOB\PHPFUI\Table\Employee();
30+
$table->setWhere(new \PHPFUI\ORM\Condition('employee_id', $this->deletes, new \PHPFUI\ORM\Operator\In()));
31+
$table->delete();
32+
// echo $table->getLastSQL();
33+
// echo "\n";
34+
$this->deletes = [];
35+
}
36+
if ($this->inserts)
37+
{
38+
$table = new \SOB\PHPFUI\Table\Employee();
39+
$table->insert($this->inserts);
40+
$this->inserts = [];
41+
}
42+
}
43+
44+
/**
45+
* class must insert one record with id=$id
46+
*
47+
* @return int $id inserted
48+
*/
49+
public function insert(int $id) : int
50+
{
51+
$employee = new \SOB\PHPFUI\Record\Employee();
52+
$employee->employee_id = $id;
53+
$employee->company = "Company {$id}";
54+
$employee->last_name = "Last {$id}";
55+
$employee->first_name = "First {$id}";
56+
$this->inserts[] = $employee;
57+
58+
return count($this->inserts) + 1;
59+
}
60+
}

SOB/TestRunner.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,15 @@ private function test(\SOB\Test $tester, \SOB\Configuration $config) : bool
183183
for ($i = 1; $i <= $iterations; ++$i)
184184
{
185185
$tester->delete($i);
186-
186+
}
187+
$tester->flush();
188+
for ($i = 1; $i <= $iterations; ++$i)
189+
{
187190
if ($tester->read($i))
188191
{
189192
throw new \Exception('Failed to delete ' . $i);
190193
}
191194
}
192-
$tester->flush();
193195
$this->setResult('Delete', $timer);
194196

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

0 commit comments

Comments
 (0)