aboutsummaryrefslogtreecommitdiff
path: root/test/Controller/ControllerTest.php
diff options
context:
space:
mode:
authorKevin Hoerr <kjhoerr@protonmail.com>2017-09-13 00:50:17 -0400
committerGitHub <noreply@github.com>2017-09-13 00:50:17 -0400
commit70ef99429394e142905a3058efc4c83a42517b67 (patch)
tree585996beb1a7f4b6c1fd4cd7e24619dff146b816 /test/Controller/ControllerTest.php
parentcf5f5aee4831bb8476f2d593276b6ef17c3edc58 (diff)
downloadaugust-offensive-70ef99429394e142905a3058efc4c83a42517b67.tar.gz
august-offensive-70ef99429394e142905a3058efc4c83a42517b67.tar.bz2
august-offensive-70ef99429394e142905a3058efc4c83a42517b67.zip
2 - Tests (#3)
* Move autoload to separate script, add two unit tests * Add integration tests for Controller * Add unit test for Output * Fix Model\Result-as-a-method error * encode JSON output as utf-8, and retrieve as assoc array * Ignore utf-8 definitions
Diffstat (limited to 'test/Controller/ControllerTest.php')
-rw-r--r--test/Controller/ControllerTest.php96
1 files changed, 96 insertions, 0 deletions
diff --git a/test/Controller/ControllerTest.php b/test/Controller/ControllerTest.php
new file mode 100644
index 0000000..1517b64
--- /dev/null
+++ b/test/Controller/ControllerTest.php
@@ -0,0 +1,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()
+ );
+ }
+}