|
| 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 | + } |
0 commit comments