Skip to content

Commit

Permalink
Testing in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Sep 8, 2023
1 parent c63d9ed commit 1ccf533
Show file tree
Hide file tree
Showing 10 changed files with 388 additions and 17 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ phpunit.xml
file-only-present-on-dev-pc-at-home.txt
index.php

# file below is generated when tests are run
tests/test-template-output/FooBar.php
tests/test-template-output/logs/*
!tests/test-template-output/logs/.gitkeep

# files below are generated when tests are run
tests/test-template-output/FooBar.php
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"rotexsoft/file-renderer": "^5.0.0",
"vespula/log": "^2.2.3",
"vespula/auth": "^2.1.1",
"sebastian/exporter": "^4.0",
"psr/container": "^2.0",
"pimple/pimple": "^3.5",
"nyholm/psr7": "^1.5",
Expand Down
41 changes: 27 additions & 14 deletions src/functions/framework-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
* The controller class must be \SlimMvcTools\Controllers\BaseController
* or one of its sub-classes
*
* @param \Psr\Container\ContainerInterface $container
* @param string $controller_name_from_url
* @param string $action_name_from_url
* @param \Psr\Http\Message\ServerRequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
*
* @throws \Slim\Exception\HttpBadRequestException
* @throws \Slim\Exception\HttpNotFoundException
*/
function sMVC_CreateController(
\Psr\Container\ContainerInterface $container,
$controller_name_from_url,
$action_name_from_url,
string $controller_name_from_url,
string $action_name_from_url,
\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Message\ResponseInterface $response
):\SlimMvcTools\Controllers\BaseController {
Expand Down Expand Up @@ -89,14 +83,33 @@ function sMVC_DumpAuthinfo(\Vespula\Auth\Auth $auth): string {
}

/**
* @param mixed $vals variables or expressions to dump
* @param mixed[] $vals variables or expressions to dump
*/
function sMVC_DumpVar(...$vals): void {

$var_to_string = function($var): string {

// Start capturing the output
ob_start();

/** @psalm-suppress ForbiddenCode */
var_dump($var);

// Get the captured output, close the buffer & return the captured output
$output = ob_get_clean();

return ($output === false) ? '' : $output;
};

foreach($vals as $val) {

$val = (!is_string($val)) ? (new \SebastianBergmann\Exporter\Exporter())->export($val) : $val;
echo "<pre>$val</pre><br><br>";
$line_breaker = (PHP_SAPI === 'cli') ? PHP_EOL : '<br>';
$pre_open = (PHP_SAPI === 'cli') ? '' : '<pre>';
$pre_close = (PHP_SAPI === 'cli') ? '' : '</pre>';

echo $pre_open . $var_to_string($val) . $pre_close
. $line_breaker
. $line_breaker;
}
}

Expand Down Expand Up @@ -222,7 +235,7 @@ function sMVC_GetSuperGlobal(string $global_name='', string $key='', $default_va
}
}

if( empty($global_name) ) {
if( $global_name === '' ) {

//return everything
return $super_globals;
Expand All @@ -236,7 +249,7 @@ function sMVC_GetSuperGlobal(string $global_name='', string $key='', $default_va
$global_name = substr($global_name, 2);
}

if( empty($key) ) {
if( $key === '' ) {

//return everything for the specified global
return array_key_exists($global_name, $super_globals)
Expand Down Expand Up @@ -355,7 +368,7 @@ function sMVC_DisplayAndLogFrameworkFileNotFoundError(
FILE_APPEND
); // log to log file

error_log ( $log_message , 4 ); // message is sent directly to the SAPI logging handler.
error_log ( PHP_EOL . PHP_EOL . $log_message . PHP_EOL , 4 ); // message is sent directly to the SAPI logging handler.
}

/**
Expand Down
Loading

0 comments on commit 1ccf533

Please sign in to comment.