summaryrefslogtreecommitdiff
path: root/test/ApiTest.php
blob: 158c9dc53f12407dbd342d9d37586020dfe42439 (plain)
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
<?php

use PHPUnit\Framework\TestCase;

class ApiTest extends TestCase {

    /**
     * @dataProvider generatedDataProvider
     */
    public function testRandomResults($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 testBoardCounts($input, $expected) {
        $input['boards'] = strval($input['over39_boards'] ? rand(40, 60) : rand(1, 39));
        unset($input['over39_boards']);
        $this->testRandomResults($input, $expected);
    }

    public function generatedDataProvider() {
        $contents = file(dirname(__FILE__) . '/tests.txt');
        $count = count($contents) / 2;
        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)];
        }
    }

}

?>