-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCountersTest.php
More file actions
54 lines (42 loc) · 1.51 KB
/
CountersTest.php
File metadata and controls
54 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace cases\database;
use ocunit\library\MySQLPDO;
use PHPUnit\Framework\TestCase;
class CountersTest extends TestCase
{
private array $tables_counters;
public function setUp(): void
{
global $configurations;
// @todo: Deprecated mechanism, see individual truncate
$this->tables_counters = [];
foreach ($configurations["tables_counters"] as $table => $counter) {
$this->tables_counters[str_replace("oc_", DB_PREFIX, $table)] = (int)$counter;
}
}
public function testCountTruncatedTables()
{
$truncated = 0;
$pdo = new MySQLPDO();
if (__OCUNIT_EXECUTE_EXPENSIVE__) {
foreach ($this->tables_counters as $table => $total) {
if ($total === 0) {
$pdo->query("TRUNCATE `{$table}`;");
++$truncated;
}
}
$this->assertEquals(15, $truncated, "Mismatched truncated count.");
} else {
$this->assertFalse(__OCUNIT_EXECUTE_EXPENSIVE__, "Tables were truncated.");
}
}
public function testTotalRecordCounter()
{
$pdo = new MySQLPDO();
foreach ($this->tables_counters as $table => $total) {
$sql = "SELECT COUNT(*) total FROM `{$table}`;";
$total_db = $pdo->query($sql)[0]["total"];
$this->assertEquals($total, $total_db, "Data counter mismatch in table: `{$table}`.");
}
}
}