Skip to content

Commit

Permalink
Merged 5.x into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Mar 14, 2024
1 parent 880e936 commit 5746bb3
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 253 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ jobs:

strategy:
matrix:
php: [8.3, 8.2, 8.1, 8.0, 7.4]
php: [8.3, 8.2, 8.1]
# prefer-lowest is causing unit tests to fail when php 7.2 is run against PHPunit 7.x,
# PHPUnit 8.x is the latest stable release that supports PHP 7.2 and that runs fine
# dependency-version: [prefer-lowest, prefer-stable]
dependency-version: [prefer-stable]
os: [ubuntu-20.04, ubuntu-22.04]
include:
- os: ubuntu-20.04
php: 7.4
- os: ubuntu-20.04
php: 8.0
- os: ubuntu-20.04
php: 8.1
- os: ubuntu-20.04
Expand Down Expand Up @@ -71,7 +67,7 @@ jobs:
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md
- name: Run PHPUnit Test Suite
run: vendor/bin/phpunit
run: vendor/bin/phpunit --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings

- name: Upload coverage results to Coveralls
env:
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.4.0",
"php": ">=8.1.0",
"slim/slim": "^4.10",
"rotexsoft/file-renderer": "^5.0.0",
"rotexsoft/file-renderer": "^6.0.0",
"vespula/log": "^2.2.3",
"vespula/auth": "^2.1.1",
"psr/container": "^2.0",
Expand All @@ -28,10 +28,10 @@
"vespula/locale": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.20",
"phpunit/phpunit": "^10.0.0",
"php-coveralls/php-coveralls": "^2.5.2",
"vimeo/psalm": "^5.15",
"rector/rector": "^0.19.0",
"rector/rector": "^1.0.0",
"php-mock/php-mock": "^2.4"
},
"autoload": {
Expand Down
22 changes: 12 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>./src/templates/controller-class-template.php</file>
<file>./src/templates/index-view-template.php</file>
</exclude>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<testsuites>
<testsuite name="slim-skeleton-mvc-tools">
<directory>./tests</directory>
<!--
<directory>./tests</directory>
<!--
<file>./tests/BaseControllerTest.php</file>
<file>./tests/FrameworkHelpersTest.php</file>
<file>./tests/CreateControllerScriptTest.php</file>
Expand All @@ -29,4 +22,13 @@
<logging>
<junit outputFile="build/logs/junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>./src/templates/controller-class-template.php</file>
<file>./src/templates/index-view-template.php</file>
</exclude>
</source>
</phpunit>
3 changes: 1 addition & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
\Rector\CodeQuality\Rector\If_\ShortenElseIfRector::class,
// \Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector::class,
\Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector::class,
\Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector::class,
\Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector::class,
\Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector::class,
// \Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector::class,
// \Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector::class,
// //\Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector::class,
Expand Down
9 changes: 3 additions & 6 deletions src/HtmlErrorRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ class HtmlErrorRenderer extends \Slim\Error\Renderers\HtmlErrorRenderer {

use BaseErrorRendererTrait;

protected string $path_to_error_template_file = '';

/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function __construct(string $full_path_to_error_template_file) {

$this->path_to_error_template_file = $full_path_to_error_template_file;
public function __construct(protected string $path_to_error_template_file='')
{
}

public function __invoke(\Throwable $exception, bool $displayErrorDetails): string {
Expand Down Expand Up @@ -59,7 +56,7 @@ public function renderHtmlBody(string $title = '', string $html = ''): string {

private function renderExceptionFragment(\Throwable $exception): string {

$html = sprintf('<div><strong>Type:</strong> %s</div>', get_class($exception));
$html = sprintf('<div><strong>Type:</strong> %s</div>', $exception::class);
$code = $exception->getCode();
$html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
$html .= sprintf('<div><strong>Message:</strong> %s</div>', htmlentities($exception->getMessage()));
Expand Down
2 changes: 1 addition & 1 deletion src/LogErrorRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __invoke(\Throwable $exception, bool $displayErrorDetails): stri
private function formatExceptionFragment(\Throwable $exception): string {

$nl = PHP_EOL;
$text = sprintf("Type: %s{$nl}", get_class($exception));
$text = sprintf("Type: %s{$nl}", $exception::class);
$code = $exception->getCode();
$text .= sprintf("Code: %s{$nl}", $code);
$text .= sprintf("Message: %s{$nl}", htmlentities($exception->getMessage()));
Expand Down
24 changes: 7 additions & 17 deletions src/MvcRouteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,12 @@
*/
class MvcRouteHandler {

protected \Slim\App $app;
protected bool $auto_prepend_action_to_method_name = false;
protected string $default_controller_class;
protected string $default_controller_action;

public function __construct(
\Slim\App $app,
string $default_controller_class,
string $default_controller_action,
bool $auto_prepend_action_to_method_name
) {
$this->app = $app;
$this->auto_prepend_action_to_method_name = $auto_prepend_action_to_method_name;
$this->default_controller_class = $default_controller_class;
$this->default_controller_action = $default_controller_action;
}
protected \Slim\App $app,
protected string $default_controller_class,
protected string $default_controller_action,
protected bool $auto_prepend_action_to_method_name = false
) { }

public function __invoke(
\Psr\Http\Message\ServerRequestInterface $req,
Expand All @@ -43,7 +33,7 @@ public function __invoke(

// strip trailing forward slash
/** @psalm-suppress MixedArgument */
$params_str = isset($args['parameters'])? rtrim($args['parameters'], '/') : '';
$params_str = isset($args['parameters'])? rtrim((string) $args['parameters'], '/') : '';

// convert to array of parameters
$params = ($params_str === '') && mb_strlen($params_str, 'UTF-8') <= 0 ? [] : explode('/', $params_str);
Expand Down Expand Up @@ -137,7 +127,7 @@ protected function assertMethodExistsOnControllerObj(

if( !method_exists($controller_obj, $action_method) ) {

$controller_class_name = get_class($controller_obj);
$controller_class_name = $controller_obj::class;

// 404 Not Found: Action method does not exist in the controller object.
$err_message = "`".__FILE__."` on line ".__LINE__
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function getThrowableAsStr(Throwable $e, string $eol=PHP_EOL): str

do {
$message .= "Exception / Error Code: {$previous_throwable->getCode()}"
. $eol . "Exception / Error Class: " . \get_class($previous_throwable)
. $eol . "Exception / Error Class: " . $previous_throwable::class
. $eol . "File: {$previous_throwable->getFile()}"
. $eol . "Line: {$previous_throwable->getLine()}"
. $eol . "Message: {$previous_throwable->getMessage()}" . $eol
Expand Down
Loading

0 comments on commit 5746bb3

Please sign in to comment.