summaryrefslogtreecommitdiff
path: root/test/ApiTest.php
diff options
context:
space:
mode:
authorMichaƂ Klichowicz <emkael@tlen.pl>2020-05-16 19:26:44 +0200
committerGitHub <noreply@github.com>2020-05-16 19:26:44 +0200
commite34beab42e1c64965e7567e9e37fc3390fe79710 (patch)
tree6f3418eaac05ca451eb2c522fb2b4ac21729571d /test/ApiTest.php
parentb70009db358e73b374b48a9bad3d981da37040ef (diff)
parent00d867eb3e83a23157f593593063c6dfffb49aa6 (diff)
Merge pull request #5 from PZBS/local-b-net
BridgeNET Lokalny
Diffstat (limited to 'test/ApiTest.php')
-rw-r--r--test/ApiTest.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/ApiTest.php b/test/ApiTest.php
new file mode 100644
index 0000000..0a8290c
--- /dev/null
+++ b/test/ApiTest.php
@@ -0,0 +1,61 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+class ApiTest extends TestCase {
+
+ private function _doTest($input, $expected) {
+ require_once(dirname(__FILE__) . '/../http/api-inc.php');
+ if (is_string($expected)) {
+ $this->expectException(ParametersException::class);
+ run($input);
+ } else {
+ $output = run($input);
+ $this->assertEquals($expected, $output);
+ }
+ }
+
+ /**
+ * @dataProvider generatedDataProvider
+ */
+ public function testRandomResults($input, $expected) {
+ $this->_doTest($input, $expected);
+ }
+
+ /**
+ * @dataProvider generatedDataProvider
+ */
+ public function testBoardCounts($input, $expected) {
+ $input['boards'] = strval($input['over39_boards'] ? rand(40, 60) : rand(1, 39));
+ unset($input['over39_boards']);
+ $this->_doTest($input, $expected);
+ }
+
+ /**
+ * @dataProvider bridgenetDataProvider
+ */
+ public function testBridgenet($input, $expected) {
+ $this->_doTest($input, $expected);
+ }
+
+ private function _fileDataProvider($file) {
+ $contents = file(dirname(__FILE__) . '/' . $file);
+ $count = count($contents);
+ for ($i = 0; $i < $count; $i += 2) {
+ $input = [];
+ parse_str(http_build_query(json_decode($contents[$i], TRUE)), $input);
+ yield [$input, json_decode($contents[$i+1], TRUE)];
+ }
+ }
+
+ public function generatedDataProvider() {
+ yield from $this->_fileDataProvider('tests.txt');
+ }
+
+ public function bridgenetDataProvider() {
+ yield from $this->_fileDataProvider('bridgenet.txt');
+ }
+
+}
+
+?>