Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php8.1 #95

Merged
merged 13 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,19 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2']
php-version: ['8.1', '8.2', '8.3']
prefer-lowest: ['']
thumber-driver: ['imagick', 'gd']
include:
- php-version: '7.4'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '8.0'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '8.1'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '8.2'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'
- php-version: '7.4'
thumber-driver: 'gd'
- php-version: '8.3'
prefer-lowest: 'prefer-lowest'
thumber-driver: 'imagick'

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -70,13 +65,13 @@ jobs:
if [[ ${{ matrix.thumber-driver }} == 'gd' ]] || ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
vendor/bin/phpunit --exclude-group imageEquals
elif [[ ${{ matrix.php-version }} == '8.0' ]]; then
export XDEBUG_MODE=coverage && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
export XDEBUG_MODE=coverage && vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi

- name: Submit code coverage
if: matrix.php-version == '8.1'
if: matrix.php-version == '8.2'
uses: codecov/codecov-action@v3

cs-stan:
Expand All @@ -89,7 +84,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: cs2pr

Expand All @@ -108,7 +103,7 @@ jobs:

- name: Run psalm
if: success() || failure()
run: vendor/bin/psalm --output-format=github --php-version=8.1
run: vendor/bin/psalm --output-format=github --php-version=8.2

- name: Run phpstan
if: success() || failure()
Expand All @@ -117,11 +112,11 @@ jobs:

testsuite-windows:
runs-on: windows-2019
name: Windows - PHP 7.4
name: Windows - PHP 8.2

env:
EXTENSIONS: mbstring, intl, gd
PHP_VERSION: '7.4'
PHP_VERSION: '8.2'

steps:
- uses: actions/checkout@v3
Expand All @@ -147,4 +142,4 @@ jobs:
run: composer update

- name: Run PHPUnit
run: vendor/bin/phpunit --verbose --exclude-group imageEquals
run: vendor/bin/phpunit --exclude-group imageEquals
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# 1.x branch
## 1.12 branch
### 1.12.0
* requires at least PHP 8.1, CakePHP 5.0 and PHPUnit 10;
* added tests for PHP 8.3.

## 1.11 branch
### 1.11.3
* removed some exception classes already deprecated or scheduled for deprecation.
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.1",
"ext-fileinfo": "*",
"cakephp/cakephp": "^4.4",
"cakephp/cakephp": "^5.0",
"intervention/image": "^2.4",
"mirko-pagliai/php-thumber": "~1.5.3"
"mirko-pagliai/php-tools": "~1.9.3",
"mirko-pagliai/php-thumber": "~1.6.1"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^4.0",
"phpunit/phpunit": "^9.1|^9.5",
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^10.1.0 <=10.5.3",
"phpstan/phpstan": "^1.10.38",
"vimeo/psalm": "^5.15.0"
},
Expand Down Expand Up @@ -47,8 +48,8 @@
"cs-fix": "phpcbf --standard=phpcs.xml.dist",
"test": "rm -f -r /tmp/cake* && phpunit",
"coverage": "XDEBUG_MODE=coverage phpunit --coverage-html=coverage",
"phpstan": "phpstan.phar analyse",
"psalm": "psalm.phar --php-version=8.0",
"phpstan": "phpstan analyse",
"psalm": "psalm --php-version=8.0",
"stan": [
"@phpstan",
"@psalm"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Thumber\Cake\Middleware\ThumbnailMiddleware;

/** @var \Cake\Routing\RouteBuilder $routes */
$routes->plugin('Thumber', ['path' => '/thumb'], function (RouteBuilder $routes) {
$routes->plugin('Thumber', ['path' => '/thumb'], function (RouteBuilder $routes): void {
$routes->registerMiddleware('thumbnail', new ThumbnailMiddleware());

if (!$routes->nameExists('thumb')) {
Expand Down
8 changes: 5 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
>
<coverage>
<coverage/>

<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
</source>

<testsuites>
<testsuite name="cakephp-thumber Test Cases">
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ClearAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Cake\Console\ConsoleOptionParser;
use Exception;
use Thumber\Cake\Utility\ThumbManager;
use function Cake\I18n\__d;

/**
* Clears all thumbnails
Expand Down Expand Up @@ -56,7 +57,7 @@ public function execute(Arguments $args, ConsoleIo $io): void
{
try {
$count = $this->getThumbManager()->clearAll();
} catch (Exception $e) {
} catch (Exception) {
$io->err(__d('thumber', 'Error deleting thumbnails'));
$this->abort();
}
Expand Down
3 changes: 2 additions & 1 deletion src/Command/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Cake\Console\ConsoleOptionParser;
use Exception;
use Thumber\Cake\Utility\ThumbManager;
use function Cake\I18n\__d;

/**
* Clears all thumbnails that have been generated from an image path
Expand Down Expand Up @@ -60,7 +61,7 @@ public function execute(Arguments $args, ConsoleIo $io): void
{
try {
$count = $this->getThumbManager()->clear((string)$args->getArgument('path'));
} catch (Exception $e) {
} catch (Exception) {
$io->err(__d('thumber', 'Error deleting thumbnails'));
$this->abort();
}
Expand Down
11 changes: 6 additions & 5 deletions src/Middleware/ThumbnailMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Psr\Http\Server\RequestHandlerInterface;
use Thumber\Cake\Http\Exception\ThumbNotFoundException;
use Tools\Filesystem;
use function Cake\I18n\__d;

/**
* Handles serving thumbnails
Expand All @@ -43,12 +44,12 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
throw new ThumbNotFoundException(__d('thumber', "File `{0}` doesn't exist", $file));
}

$response = new Response();
$response = $response->withModified(filemtime($file) ?: 0);
if ($response->isNotModified($request)) {
return $response->withNotModified();
$Response = new Response();
$Response = $Response->withModified(filemtime($file) ?: 0);
if ($Response->isNotModified($request)) {
return $Response->withNotModified();
}

return $response->withFile($file)->withType(mime_content_type($file) ?: '');
return $Response->withFile($file)->withType(mime_content_type($file) ?: '');
}
}
1 change: 1 addition & 0 deletions src/Utility/ThumbCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Cake\Routing\Router;
use LogicException;
use Thumber\ThumbCreator as BaseThumbCreator;
use function Cake\I18n\__d;

/**
* Utility to create a thumb.
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/ThumbManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Cake\Core\Plugin;
use Thumber\ThumbManager as BaseThumbManager;
use Tools\Filesystem;
use function Cake\Core\pluginSplit;

/**
* A utility to manage thumbnails
Expand Down Expand Up @@ -51,7 +52,6 @@ public static function resolveFilePath(string $path): string
* @param string $path Path of the original image
* @param bool $sort Whether results should be sorted
* @return array<string, string>
* @throws \Tools\Exception\NotReadableException
*/
public function get(string $path, bool $sort = false): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/ThumbHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Cake\View\Helper;
use LogicException;
use Thumber\Cake\Utility\ThumbCreator;
use function Cake\I18n\__d;

/**
* Thumb Helper.
Expand All @@ -40,7 +41,7 @@ class ThumbHelper extends Helper
* Helpers
* @var array
*/
public $helpers = ['Html'];
public array $helpers = ['Html'];

/**
* Magic method. It dynamically calls all other methods.
Expand All @@ -53,7 +54,6 @@ class ThumbHelper extends Helper
* @param array $params Array of params for the method
* @return string
* @throws \LogicException
* @throws \Tools\Exception\MethodNotExistsException
* @see https://github.com/mirko-pagliai/cakephp-thumber/wiki/How-to-use-the-helper
* @since 1.4.0
*/
Expand Down
4 changes: 0 additions & 4 deletions tests/TestCase/Command/ClearAllCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);

/**
Expand Down Expand Up @@ -40,8 +39,6 @@ class ClearAllCommandTest extends TestCase
*/
public function testExecute(): void
{
$this->useCommandRunner();

$command = 'thumber.clear_all -v';

$this->createSomeThumbs();
Expand All @@ -56,7 +53,6 @@ public function testExecute(): void
}

/**
* Test for `execute()` method, on failure
* @test
* @uses \Thumber\Cake\Command\ClearAllCommand::execute()
*/
Expand Down
4 changes: 0 additions & 4 deletions tests/TestCase/Command/ClearCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);

/**
Expand Down Expand Up @@ -40,8 +39,6 @@ class ClearCommandTest extends TestCase
*/
public function testExecute(): void
{
$this->useCommandRunner();

$command = 'thumber.clear -v';

$this->createSomeThumbs();
Expand All @@ -67,7 +64,6 @@ public function testExecute(): void
}

/**
* Test for `execute()` method, on failure
* @test
* @uses \Thumber\Cake\Command\ClearCommand::execute()
*/
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase/Middleware/ThumbnailMiddlewareTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
/** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);

/**
Expand Down Expand Up @@ -56,6 +55,9 @@ public function testThumb(): void
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
];
if (version_compare(PHP_VERSION, '8.3', '>=')) {
$extensions['bmp'] = 'image/bmp';
}
}

$ThumbHelper = new ThumbHelper(new View());
Expand Down Expand Up @@ -84,7 +86,7 @@ public function testThumb(): void
$this->assertResponseCode(304);

//Deletes the last thumbnail file. Now the `Last-Modified` header is different
@unlink($thumb);
unlink($thumb);
sleep(1);
(new ThumbCreator($file))->resize(200)->save();
$this->get($url);
Expand Down
12 changes: 6 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
define('CACHE', TMP . 'cache' . DS);
define('LOGS', TMP . 'logs' . DS);
define('SESSIONS', TMP . 'sessions' . DS);
@mkdir(TMP);
@mkdir(LOGS);
@mkdir(SESSIONS);
@mkdir(CACHE);
@mkdir(CACHE . 'views');
@mkdir(CACHE . 'models');

foreach ([TMP, LOGS, SESSIONS, CACHE . 'views', CACHE . 'models'] as $dir) {
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
}

require dirname(__DIR__) . '/vendor/autoload.php';
require CORE_PATH . 'config' . DS . 'bootstrap.php';
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.3
1.12.0