From 9d5dab249c41c109a7b7d5d8f58242e2e72b16bf Mon Sep 17 00:00:00 2001 From: "J. King" Date: Mon, 27 Mar 2017 23:19:05 -0400 Subject: [PATCH] Helper methods for testing Database class May not actually work yet --- tests/Db/TestDatabase.php | 10 ++++++++++ tests/lib/Db/Tools.php | 30 ++++++++++++++++++++++++++++++ tests/phpunit.xml | 4 ++++ 3 files changed, 44 insertions(+) create mode 100644 tests/Db/TestDatabase.php create mode 100644 tests/lib/Db/Tools.php diff --git a/tests/Db/TestDatabase.php b/tests/Db/TestDatabase.php new file mode 100644 index 0000000..e0b0d3d --- /dev/null +++ b/tests/Db/TestDatabase.php @@ -0,0 +1,10 @@ +begin(); + foreach($data as $table => $info) { + $cols = implode(",", array_keys($info['columns'])); + $bindings = array_values($info['columns']); + $params = implode(",", array_fill(0, sizeof($info['columns']), "?")); + $s = $drv->prepareArray("INSERT INTO $table($cols) values($params)", $bindings); + foreach($info['rows'] as $row) { + $this->assertEquals(1, $s->runArray($row)->changes()); + } + } + $drv->commit(); + return true; + } + + function compare(\JKingWeb\NewsSync\Db\Driver $drv, array $expected): bool { + foreach($expected as $table => $info) { + $cols = implode(",", array_keys($info['columns'])); + foreach($drv->prepare("SELECT $cols from $table")->run() as $num => $row) { + $row = array_values($row); + $assertSame($expected[$table]['rows']['$num'], $row, "Row $num of table $table does not match expectation."); + } + } + } +} \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index d1721da..6809e32 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -35,6 +35,10 @@ Db/SQLite3/TestDbUpdateSQLite3.php + + Db/TestDatabase.php + + REST/NextCloudNews/TestNCNVersionDiscovery.php