Skip to content

Commit

Permalink
Testing & refactoring in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Nov 18, 2023
1 parent d03c167 commit 6ea2305
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions tests/BaseControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,13 @@ public function testThat_getActionNameFromUri_WorksAsExpected() {
$controller2 = new BaseController(
$psr11Container, 'base-controller', 'da-action', $req, $resp
);
self::assertEquals('da-action', $controller2->getActionNameFromUri());
self::assertEquals('da-action', $controller2->getActionNameFromUri());

$req2 = $this->newRequest('http://google.com/controller/da-action/');
$controller3 = new BaseController(
$psr11Container, '', '', $req2, $resp
);
self::assertEquals('da-action', $controller3->getActionNameFromUri());
}

public function testThat_getControllerNameFromUri_WorksAsExpected() {
Expand All @@ -225,7 +231,13 @@ public function testThat_getControllerNameFromUri_WorksAsExpected() {
$controller2 = new BaseController(
$psr11Container, 'base-controller', 'da-action', $req, $resp
);
self::assertEquals('base-controller', $controller2->getControllerNameFromUri());
self::assertEquals('base-controller', $controller2->getControllerNameFromUri());

$req2 = $this->newRequest('http://google.com/da-controller/da-action/');
$controller3 = new BaseController(
$psr11Container, '', '', $req2, $resp
);
self::assertEquals('da-controller', $controller3->getControllerNameFromUri());
}

public function testThat_getCurrentUri_WorksAsExpected() {
Expand Down Expand Up @@ -284,7 +296,6 @@ public function testThat_getCurrentUriComputed_WorksAsExpected() {
$controller2->getCurrentUriComputed()
);


////////////////////////////////////////////////////////////////////////
// Tests with base path with leading slash
////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -366,6 +377,7 @@ public function testThat_GetSetVespulaAuthObject_WorksAsExpected() {
$controller = new BaseController(
$psr11Container, '', '', $req, $resp
);
self::assertSame($psr11Container->get('vespula_auth'), $controller->getVespulaAuthObject());

$new_auth = $this->newVespulaAuth();
$controller->setVespulaAuthObject($new_auth);
Expand Down Expand Up @@ -414,10 +426,10 @@ public function testThat_GetSetRequest_WorksAsExpected() {
$controller = new BaseController(
$psr11Container, '', '', $req, $resp
);
self::assertSame($req, $controller->getRequest());

$new_req = $this->newRequest();
$controller->setRequest($new_req);

self::assertSame($new_req, $controller->getRequest());
}

Expand All @@ -430,10 +442,10 @@ public function testThat_GetSetResponse_WorksAsExpected() {
$controller = new BaseController(
$psr11Container, '', '', $req, $resp
);
self::assertSame($resp, $controller->getResponse());

$new_resp = $this->newResponse();
$controller->setResponse($new_resp);

self::assertSame($new_resp, $controller->getResponse());
}

Expand Down Expand Up @@ -621,6 +633,32 @@ public function testThat_actionRoutes_WorksAsExpected2() {
);
}


public function testThat_preAction_WorksAsExpected() {

$req = $this->newRequest('http://google.com/');
$resp = $this->newResponse();
$psr11Container = $this->getContainer();

$controller = new BaseController(
$psr11Container, '', '', $req, $resp
);
self::assertSame($resp, $controller->preAction());
}

public function testThat_postAction_WorksAsExpected() {

$req = $this->newRequest('http://google.com/');
$resp = $this->newResponse();
$resp2 = $this->newResponse();
$psr11Container = $this->getContainer();

$controller = new BaseController(
$psr11Container, '', '', $req, $resp
);
self::assertSame($resp2, $controller->postAction($resp2));
}

public function testThat_getContainerItem_WorksAsExpected() {

$req = $this->newRequest('http://google.com/');
Expand Down

0 comments on commit 6ea2305

Please sign in to comment.