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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
<?php
declare(strict_types=1);
namespace AugustOffensive\Controller;
use PHPUnit\Framework\TestCase;
use AugustOffensive\Model;
/**
* Integration test: requires DB connection. Expect side effects (use test db if possible).
*
* @covers Controller
*/
final class ControllerTest extends \PHPUnit\Framework\TestCase
{
public function testDBConnection()
{
try {
$this->assertInstanceOf(
Model\Connection::class,
Controller::initiateConnection()
);
} catch (\PDOException $err) {
$this->fail("Database not initialized correctly: " . $err->getMessage());
}
}
public function testCreateQuery()
{
$path = array("api", "create", "query");
$request = "DELETE";
$content = array("c" => "cherry", "d" => "dike");
$query = Controller::createQuery($path, $request, $content);
$this->assertInstanceOf(
Model\Query::class,
$query
);
$this->assertEquals(
$path,
$query->getPath()
);
$this->assertEquals(
$request,
$query->getRequest()
);
$this->assertEquals(
$content,
$query->getContent()
);
}
public function testCreateResult()
{
$resultType = "TYPE";
$result = array("no", "values");
$resultObject = Controller::createResult($resultType, $result);
$this->assertInstanceOf(
Model\Result::class,
$resultObject
);
$this->assertEquals(
$resultType,
$resultObject->getResultType()
);
$this->assertEquals(
$result,
$resultObject->getResult()
);
}
public function testErrorResult()
{
$message = "Oh no! Oops!";
$errorResult = Controller::errorResult(new \Exception($message));
$this->assertInstanceOf(
Model\Result::class,
$errorResult
);
$this->assertEquals(
"ERROR",
$errorResult->getResultType()
);
$this->assertEquals(
array("error" => $message),
$errorResult->getResult()
);
}
}
|