-
Notifications
You must be signed in to change notification settings - Fork 2
/
RecordsCountTest.php
48 lines (38 loc) · 1.54 KB
/
RecordsCountTest.php
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
<?php
namespace ocunit\catalog\cases\report;
use ocunit\library\DatabaseExecutor;
use PHPUnit\Framework\TestCase;
class RecordsCountTest extends TestCase
{
public function testRecordsCount()
{
$dbx = new DatabaseExecutor();
$records = $dbx->statistics();
$non_empty = [];
$empty = [];
foreach ($records as $info) {
if ((int)$info["Rows"] > 0) {
$non_empty[$info["Name"]] = $info["Rows"];
} else {
$empty[$info["Name"]] = $info["Rows"];
}
// @todo: split tests into tables that are always:
// zero
// fixed non-zero - eg: categories once setup
// and variable counts as the website operates, eg. session data.
}
$this->_logTableRecords("tables-data.txt", $non_empty);
$this->_logTableRecords("tables-no-data.txt", $empty);
global $configurations;
$this->assertCount((int)$configurations["statistics"]["non_empty"], $non_empty, "Non-Empty Tables count mismatch!");
$this->assertCount((int)$configurations["statistics"]["empty"], $empty, "Empty Tables count mismatch!");
}
private function _logTableRecords($filename = "", $data = [])
{
$file = fopen(__OCUNIT_ROOT__ . "/logs/" . basename($filename), "wb+");
foreach ($data as $table => $data_count) {
fwrite($file, sprintf("%-40s - %d\r\n", substr($table, 0, 40), $data_count));
}
fclose($file);
}
}