Skip to content

Commit

Permalink
Merge pull request #441 from AntonShevchuk/master
Browse files Browse the repository at this point in the history
Updated tests
  • Loading branch information
Anton authored Sep 27, 2017
2 parents 9a246b8 + 7f64de4 commit cd93415
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/Controller/Mapper/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ protected function prepareRequest()

if (count($params)) {
$primaryKeys = $this->crud->getPrimaryKey();
$primaryValues = explode('-', array_shift($params));

$primaryValues = explode('-', array_shift($params), count($primaryKeys));

$this->primary = array_combine($primaryKeys, $primaryValues);
}
Expand Down
75 changes: 54 additions & 21 deletions tests/src/BootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
namespace Bluz\Tests;

use Bluz\Application\Application;
use Bluz\Application\Exception\ForbiddenException;
use Bluz\Application\Exception\RedirectException;
use Bluz\Controller\Controller;
use Bluz\Proxy\Layout;
use Bluz\Proxy\Request;
use Bluz\Proxy\Response;

/**
* Bootstrap
Expand Down Expand Up @@ -60,27 +66,6 @@ public function getController()
return $this->dispatchController;
}

/**
* @param string $module
* @param string $controller
* @param array $params
*
* @return \Bluz\Controller\Controller
* @throws \Exception
*/
public function dispatch($module, $controller, array $params = [])
{
$this->dispatchModule = $module;
$this->dispatchController = $controller;

try {
return parent::dispatch($module, $controller, $params);
} catch (\Exception $e) {
$this->setException($e);
throw $e;
}
}

/**
* setException
*
Expand All @@ -91,6 +76,9 @@ public function dispatch($module, $controller, array $params = [])
public function setException($exception)
{
$this->exception = $exception;

codecept_debug(' ## '. $exception->getCode());
codecept_debug(' ## '. $exception->getMessage());
}

/**
Expand All @@ -102,4 +90,49 @@ public function getException()
{
return $this->exception;
}

/**
* @inheritdoc
*/
protected function doProcess()
{
$module = Request::getModule();
$controller = Request::getController();
$params = Request::getParams();

// try to dispatch controller
try {
codecept_debug('');
codecept_debug(' >> '. $module .'/'. $controller);

// dispatch controller
$result = $this->dispatch($module, $controller, $params);
} catch (ForbiddenException $e) {
$this->setException($e);
$result = $this->forbidden($e);
} catch (RedirectException $e) {
$this->setException($e);
// redirect to URL
$result = $this->redirect($e->getUrl());
} catch (\Exception $e) {
$this->setException($e);
$result = $this->error($e);
}

if ($result instanceof Controller) {
$this->dispatchModule = $result->getModule();
$this->dispatchController = $result->getController();
codecept_debug(' << '. $this->getModule() .'/'. $this->getController());
}

// setup layout, if needed
if ($this->useLayout()) {
// render view to layout
// needed for headScript and headStyle helpers
Layout::setContent($result->render());
Response::setBody(Layout::getInstance());
} else {
Response::setBody($result);
}
}
}

0 comments on commit cd93415

Please sign in to comment.