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 Dec 12, 2023
1 parent 3ae6665 commit 2819048
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
20 changes: 16 additions & 4 deletions src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ public function getCurrentUriComputed(): string {
// Keys for container items needed in this controller
////////////////////////////////////////////////////////
public const LAYOUT_RENDERER_CONTAINER_KEY = 'new_layout_renderer';
public const VIEW_RENDERER_CONTAINER_KEY = 'new_view_renderer';

// 'logger'
// 'vespula_auth'
// 'settings'



/**
Expand Down Expand Up @@ -206,8 +212,11 @@ public function __construct(
*/
$this->layout_renderer = $this->getContainerItem(static::LAYOUT_RENDERER_CONTAINER_KEY);

/** @psalm-suppress MixedAssignment */
$this->view_renderer = $this->getContainerItem('new_view_renderer');
/**
* @psalm-suppress MixedArgument
* @psalm-suppress MixedAssignment
*/
$this->view_renderer = $this->getContainerItem(static::VIEW_RENDERER_CONTAINER_KEY);

$uri_path = ($req->getUri() instanceof \Psr\Http\Message\UriInterface)
? $req->getUri()->getPath() : '';
Expand Down Expand Up @@ -489,8 +498,11 @@ public function renderView( string $file_name, array $data = [] ): string {
$parent_classes = [];
$parent_class = get_parent_class($this);

/** @psalm-suppress MixedAssignment */
$this->view_renderer = $this->getContainerItem('new_view_renderer'); // get new instance for each call to this method renderView
/**
* @psalm-suppress MixedArgument
* @psalm-suppress MixedAssignment
*/
$this->view_renderer = $this->getContainerItem(static::VIEW_RENDERER_CONTAINER_KEY); // get new instance for each call to this method renderView

while( $parent_class !== self::class && ($parent_class !== '' && $parent_class !== false) ) {

Expand Down
16 changes: 9 additions & 7 deletions tests/BaseControllerDependenciesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,17 @@ protected function getContainer(array $override_settings=[]): \Psr\Container\Con
});

//Object for rendering view files
$psr11Container['new_view_renderer'] = $psr11Container->factory(function () {
$psr11Container[\SlimMvcTools\Controllers\BaseController::VIEW_RENDERER_CONTAINER_KEY] =
$psr11Container->factory(function () {

//return a new instance on each access to $psr11Container['new_view_renderer']
$ds = DIRECTORY_SEPARATOR;
$path_2_view_files = __DIR__ . DIRECTORY_SEPARATOR . 'fake-smvc-app-root' ."{$ds}src{$ds}views{$ds}base";
$view_renderer = new \Rotexsoft\FileRenderer\Renderer('', [], [$path_2_view_files]);
// Return a new instance on each access to
// $psr11Container[\SlimMvcTools\Controllers\BaseController::VIEW_RENDERER_CONTAINER_KEY]
$ds = DIRECTORY_SEPARATOR;
$path_2_view_files = __DIR__ . DIRECTORY_SEPARATOR . 'fake-smvc-app-root' ."{$ds}src{$ds}views{$ds}base";
$view_renderer = new \Rotexsoft\FileRenderer\Renderer('', [], [$path_2_view_files]);

return $view_renderer;
});
return $view_renderer;
});
}

return $psr11Container;
Expand Down
2 changes: 1 addition & 1 deletion tests/BaseControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public function testThat_GetSetViewRenderer_WorksAsExpected() {
$psr11Container, '', '', $req, $resp
);

$new_renderer = $this->getContainer()['new_view_renderer'];
$new_renderer = $this->getContainer()[BaseController::VIEW_RENDERER_CONTAINER_KEY];
$controller->setViewRenderer($new_renderer);

self::assertSame($new_renderer, $controller->getViewRenderer());
Expand Down

0 comments on commit 2819048

Please sign in to comment.