diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5306abb..c478c89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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: @@ -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 @@ -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() @@ -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 @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6149295..a2ce42c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 9817e84..ebdd798 100644 --- a/README.md +++ b/README.md @@ -30,16 +30,17 @@ even a coffee is enough! Thank you. *** - * [Requirements and supported formats](#requirements-and-supported-formats) - * [Installation](#installation) +* [Requirements and supported formats](#requirements-and-supported-formats) +* [Installation](#installation) + [Installation on older CakePHP and PHP versions](#installation-on-older-cakephp-and-php-versions) - - [For PHP 7.2 or later](#for-php-72-or-later) - - [For PHP 5.6 and CakePHP 3 or later](#for-php-56-and-cakephp-3-or-later) - * [Configuration](#configuration) + - [For PHP 8.0 and CakePHP 4 or later](#for-php-80-and-cakephp-4-or-later) + - [For PHP 7.2 or later](#for-php-72-or-later) + - [For PHP 5.6 and CakePHP 3 or later](#for-php-56-and-cakephp-3-or-later) +* [Configuration](#configuration) + [Configuration values](#configuration-values) - * [How to use](#how-to-use) - * [Testing](#testing) - * [Versioning](#versioning) +* [How to use](#how-to-use) +* [Testing](#testing) +* [Versioning](#versioning) ## Requirements and supported formats *cakephp-thumber* requires GD Library (>=2.0) **or** Imagick PHP extension @@ -82,12 +83,25 @@ $ mkdir tmp/thumbs && chmod 775 tmp/thumbs If you want to use a different directory, read the [Configuration](#configuration) section. ### Installation on older CakePHP and PHP versions -Recent packages and the master branch require at least CakePHP 4.0 and PHP 7.4 +Recent packages and the master branch require at least CakePHP 5.0 and PHP 8.1 and the current development of the code is based on these and later versions of CakePHP and PHP. However, there are still some branches compatible with previous versions of CakePHP and PHP. +#### For PHP 8.0 and CakePHP 4 or later +The [cakephp4](//github.com/mirko-pagliai/cakephp-thumber/tree/cakephp4) branch +requires at least PHP `>=7.4` and CakePHP `^4.4`. + +In this case, you can install the package as well: +```bash +$ composer require --prefer-dist mirko-pagliai/cakephp-thumber:dev-cakephp4 +``` + +Note that the `cakephp4` branch will no longer be updated as of January 5, 2024, +except for security patches, and it matches the +[1.11.3](//github.com/mirko-pagliai/cakephp-thumber/releases/tag/1.11.3) version. + #### For PHP 7.2 or later The [php7.2](//github.com/mirko-pagliai/cakephp-thumber/tree/php7.2) branch requires at least PHP 7.2. diff --git a/composer.json b/composer.json index df5700b..5e10ba4 100644 --- a/composer.json +++ b/composer.json @@ -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" }, @@ -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" diff --git a/config/routes.php b/config/routes.php index 850354b..468f564 100644 --- a/config/routes.php +++ b/config/routes.php @@ -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')) { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bd3360d..6ff8940 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -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" > - + + + ./src/ - + diff --git a/src/Command/ClearAllCommand.php b/src/Command/ClearAllCommand.php index 2b879a3..10c9663 100644 --- a/src/Command/ClearAllCommand.php +++ b/src/Command/ClearAllCommand.php @@ -21,6 +21,7 @@ use Cake\Console\ConsoleOptionParser; use Exception; use Thumber\Cake\Utility\ThumbManager; +use function Cake\I18n\__d; /** * Clears all thumbnails @@ -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(); } diff --git a/src/Command/ClearCommand.php b/src/Command/ClearCommand.php index a7dfc90..1f5efab 100644 --- a/src/Command/ClearCommand.php +++ b/src/Command/ClearCommand.php @@ -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 @@ -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(); } diff --git a/src/Middleware/ThumbnailMiddleware.php b/src/Middleware/ThumbnailMiddleware.php index 3471110..779b2a5 100644 --- a/src/Middleware/ThumbnailMiddleware.php +++ b/src/Middleware/ThumbnailMiddleware.php @@ -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 @@ -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) ?: ''); } } diff --git a/src/Utility/ThumbCreator.php b/src/Utility/ThumbCreator.php index 4d24350..b7a3864 100644 --- a/src/Utility/ThumbCreator.php +++ b/src/Utility/ThumbCreator.php @@ -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. diff --git a/src/Utility/ThumbManager.php b/src/Utility/ThumbManager.php index e7b0624..c8ed869 100644 --- a/src/Utility/ThumbManager.php +++ b/src/Utility/ThumbManager.php @@ -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 @@ -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 - * @throws \Tools\Exception\NotReadableException */ public function get(string $path, bool $sort = false): array { diff --git a/src/View/Helper/ThumbHelper.php b/src/View/Helper/ThumbHelper.php index 2b8ff1a..c6d0444 100644 --- a/src/View/Helper/ThumbHelper.php +++ b/src/View/Helper/ThumbHelper.php @@ -19,6 +19,7 @@ use Cake\View\Helper; use LogicException; use Thumber\Cake\Utility\ThumbCreator; +use function Cake\I18n\__d; /** * Thumb Helper. @@ -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. @@ -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 */ diff --git a/tests/TestCase/Command/ClearAllCommandTest.php b/tests/TestCase/Command/ClearAllCommandTest.php index 2e41093..c9deff3 100644 --- a/tests/TestCase/Command/ClearAllCommandTest.php +++ b/tests/TestCase/Command/ClearAllCommandTest.php @@ -1,5 +1,4 @@ useCommandRunner(); - $command = 'thumber.clear_all -v'; $this->createSomeThumbs(); @@ -56,7 +53,6 @@ public function testExecute(): void } /** - * Test for `execute()` method, on failure * @test * @uses \Thumber\Cake\Command\ClearAllCommand::execute() */ diff --git a/tests/TestCase/Command/ClearCommandTest.php b/tests/TestCase/Command/ClearCommandTest.php index 8ece0b0..e38e306 100644 --- a/tests/TestCase/Command/ClearCommandTest.php +++ b/tests/TestCase/Command/ClearCommandTest.php @@ -1,5 +1,4 @@ useCommandRunner(); - $command = 'thumber.clear -v'; $this->createSomeThumbs(); @@ -67,7 +64,6 @@ public function testExecute(): void } /** - * Test for `execute()` method, on failure * @test * @uses \Thumber\Cake\Command\ClearCommand::execute() */ diff --git a/tests/TestCase/Middleware/ThumbnailMiddlewareTest.php b/tests/TestCase/Middleware/ThumbnailMiddlewareTest.php index f5fe47f..8bdcb9b 100644 --- a/tests/TestCase/Middleware/ThumbnailMiddlewareTest.php +++ b/tests/TestCase/Middleware/ThumbnailMiddlewareTest.php @@ -1,5 +1,4 @@ 'image/tiff', 'tiff' => 'image/tiff', ]; + if (version_compare(PHP_VERSION, '8.3', '>=')) { + $extensions['bmp'] = 'image/bmp'; + } } $ThumbHelper = new ThumbHelper(new View()); @@ -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); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b54d929..6d9326a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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'; diff --git a/version b/version index 0a5af26..0eed1a2 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.11.3 +1.12.0