From 5670fdf8b1e6a4bbfc5ab68dbcb64c14be674154 Mon Sep 17 00:00:00 2001 From: Jay Klehr Date: Fri, 3 Dec 2021 22:07:52 -0700 Subject: [PATCH] testing php 8.1 (#115) * testing php 8.1 * php 8.1 deprecation fixes * fixing implicit cast notice * narrowing php versions --- .github/workflows/build.yml | 34 ++++++++----------------- .github/workflows/merge-me.yml | 32 +++++++++++++++++++++++ .gitignore | 1 + .php_cs => .php-cs-fixer.php | 9 +++---- composer.json | 12 ++++----- grumphp.yml.dist | 2 +- phpstan.neon | 5 +--- phpunit.xml.dist | 30 +++++++++------------- src/Zend/Captcha/Image.php | 4 +-- src/Zend/Captcha/Word.php | 2 ++ src/Zend/Form/Element/Captcha.php | 3 ++- tests/Zend/Captcha/FigletTest.php | 6 ++--- tests/Zend/Captcha/ImageTest.php | 18 ++++++------- tests/Zend/Form/Element/CaptchaTest.php | 8 ------ 14 files changed, 85 insertions(+), 81 deletions(-) create mode 100644 .github/workflows/merge-me.yml rename .php_cs => .php-cs-fixer.php (64%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b65d22..3aeb474 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,21 +13,14 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['7.2', '7.3', '7.4'] + php-versions: ['7.4', '8.0', '8.1'] composer-args: ['', '--prefer-lowest'] - include: - - operating-system: ubuntu-latest - php-versions: '8.0' - composer-args: '--ignore-platform-reqs --no-scripts' - - operating-system: ubuntu-latest - php-versions: '8.0' - composer-args: '--prefer-lowest --ignore-platform-reqs --no-scripts' runs-on: ${{ matrix.operating-system }} steps: - name: Checkout - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.4.0 - name: Setup PHP - uses: shivammathur/setup-php@2.10.0 + uses: shivammathur/setup-php@2.16.0 with: php-version: ${{ matrix.php-versions }} extensions: mbstring @@ -39,7 +32,7 @@ jobs: id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v2.1.4 + uses: actions/cache@v2.1.7 with: path: ${{ steps.composer-cache.outputs.dir }} key: php${{ matrix.php-versions }}-composer-${{ matrix.composer-args }}-${{ hashFiles('**/composer.json') }} @@ -50,21 +43,14 @@ jobs: - name: PHPStan run: composer phpstan - name: Code Style Check + env: + PHP_CS_FIXER_IGNORE_ENV: true run: composer style-check -- --format=checkstyle | cs2pr - name: Test run: composer test-with-coverage - name: Upload Coverage - run: bash <(curl -s https://codecov.io/bash) -f ./clover.xml - merge-me: - name: Merge me! - needs: - - build - runs-on: ubuntu-latest - steps: - - name: Merge me! - uses: ridedott/merge-me-action@master + uses: codecov/codecov-action@v2 with: - # This must be used as GitHub Actions token does not support - # pushing to protected branches. - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_LOGIN: 'dependabot[bot]' + files: ./clover.xml + fail_ci_if_error: true + verbose: true diff --git a/.github/workflows/merge-me.yml b/.github/workflows/merge-me.yml new file mode 100644 index 0000000..c7559ae --- /dev/null +++ b/.github/workflows/merge-me.yml @@ -0,0 +1,32 @@ +name: Merge me! + +on: + workflow_run: + types: + - completed + workflows: + - 'Build' + +jobs: + merge-me: + name: Merge me! + runs-on: ubuntu-latest + steps: + - # It is often a desired behavior to merge only when a workflow execution + # succeeds. This can be changed as needed. + if: ${{ github.event.workflow_run.conclusion == 'success' }} + name: Merge me! + uses: ridedott/merge-me-action@v2 + with: + # Depending on branch protection rules, a manually populated + # `GITHUB_TOKEN_WORKAROUND` secret with permissions to push to + # a protected branch must be used. This secret can have an arbitrary + # name, as an example, this repository uses `DOTTBOTT_TOKEN`. + # + # When using a custom token, it is recommended to leave the following + # comment for other developers to be aware of the reasoning behind it: + # + # This must be used as GitHub Actions token does not support pushing + # to protected branches. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ENABLE_GITHUB_API_PREVIEW: true diff --git a/.gitignore b/.gitignore index fffc06b..e5b8007 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /clover.xml .php_cs.cache .phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php_cs b/.php-cs-fixer.php similarity index 64% rename from .php_cs rename to .php-cs-fixer.php index e14f877..2ec4112 100644 --- a/.php_cs +++ b/.php-cs-fixer.php @@ -6,17 +6,16 @@ ->in(__DIR__) ; -return PhpCsFixer\Config::create() - ->setRiskyAllowed(true) +$config = new PhpCsFixer\Config(); +return $config->setRiskyAllowed(true) ->setRules(array( '@PSR2' => true, '@PHPUnit60Migration:risky' => true, - '@PHPUnit84Migration:risky' => true, - 'binary_operator_spaces' => array('align_double_arrow' => true, 'align_equals' => true), + 'binary_operator_spaces' => array('operators' => array('=' => 'align', '=>' => 'align')), 'single_quote' => true, 'array_syntax' => array('syntax' => 'long'), 'concat_space' => array('spacing' => 'one'), - 'psr0' => false + 'psr_autoloading' => array('dir' => 'src'), )) ->setUsingCache(true) ->setFinder($finder); diff --git a/composer.json b/composer.json index e6c2579..a4cf244 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "homepage": "http://framework.zend.com/", "license": "BSD-3-Clause", "require": { - "php": "^7.0 || ^8.0", + "php": "^7.4 || ~8.0.0 || ~8.1.0", "diablomedia/zendframework1-exception": "^1.0.0", "diablomedia/zendframework1-config": "^1.0.0 || ^2.0.0", "diablomedia/zendframework1-loader": "^1.0.0", @@ -34,11 +34,11 @@ } }, "require-dev": { - "phpunit/phpunit": "^8.0", - "phpstan/phpstan": "0.12.83", - "friendsofphp/php-cs-fixer": "2.18.4", - "maglnet/composer-require-checker": "^1.1.0 || ^2.0.0", - "phpro/grumphp-shim": "^0.22.0 || ^1.1" + "phpunit/phpunit": "^9.5.10", + "phpstan/phpstan": "1.2.0", + "friendsofphp/php-cs-fixer": "3.3.2", + "maglnet/composer-require-checker": "^3.0.0", + "phpro/grumphp-shim": "^1.5.0" }, "include-path": [ "src/" diff --git a/grumphp.yml.dist b/grumphp.yml.dist index 6e05858..70ff16c 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -7,7 +7,7 @@ grumphp: config_file: require-checker-config.json phpcsfixer2: allow_risky: true - config: .php_cs + config: .php-cs-fixer.php phpstan: configuration: phpstan.neon phpunit: diff --git a/phpstan.neon b/phpstan.neon index f494f92..3419fac 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,7 @@ parameters: level: 7 paths: - ./ - excludes_analyse: + excludePaths: - %rootDir%/../../../vendor/* - %rootDir%/../../../tests/* ignoreErrors: @@ -17,6 +17,3 @@ parameters: - message: '#If condition is always true\.#' path: './src/Zend/Captcha/Word.php' - - - message: '#Parameter \#1 \$(argument|objectOrClass) of class ReflectionClass constructor expects class-string\|T of object, string given\.#' - path: './src/Zend/Form/Element/Captcha.php' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2204d13..d55ddf3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,19 +1,13 @@ - - - - ./tests - - - - - ./src - - + + + + + ./src + + + + + ./tests + + diff --git a/src/Zend/Captcha/Image.php b/src/Zend/Captcha/Image.php index 9e90494..a4085c9 100644 --- a/src/Zend/Captcha/Image.php +++ b/src/Zend/Captcha/Image.php @@ -503,8 +503,8 @@ protected function _generateImage($id, $word) if ($textbox === false) { throw new Zend_Captcha_Exception('Can not get bounding box size'); } - $x = (int) ($w - ($textbox[2] - $textbox[0])) / 2; - $y = (int) ($h - ($textbox[7] - $textbox[1])) / 2; + $x = (int) (($w - ($textbox[2] - $textbox[0])) / 2); + $y = (int) (($h - ($textbox[7] - $textbox[1])) / 2); imagefttext($img, $fsize, 0, $x, $y, $text_color, $font, $word); // generate noise diff --git a/src/Zend/Captcha/Word.php b/src/Zend/Captcha/Word.php index b9a2dd9..c0503f8 100644 --- a/src/Zend/Captcha/Word.php +++ b/src/Zend/Captcha/Word.php @@ -80,6 +80,7 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base * Class name for sessions * * @var string + * @phpstan-var class-string */ protected $_sessionClass = Zend_Session_Namespace::class; @@ -150,6 +151,7 @@ public function getSessionClass() * Set session class for persistence * * @param string $_sessionClass + * @phpstan-param class-string $_sessionClass * @return $this */ public function setSessionClass($_sessionClass) diff --git a/src/Zend/Form/Element/Captcha.php b/src/Zend/Form/Element/Captcha.php index 13a324e..e64ba52 100644 --- a/src/Zend/Form/Element/Captcha.php +++ b/src/Zend/Form/Element/Captcha.php @@ -83,6 +83,7 @@ public function setCaptcha($captcha, $options = array()) $name = $captcha; } + /** @phpstan-var class-string $name */ $name = $this->getPluginLoader(self::CAPTCHA)->load($name); if (empty($options)) { $instance = new $name; @@ -223,7 +224,7 @@ public function getPluginLoader($type) */ public function addPrefixPath($prefix, $path, $type = null) { - $type = strtoupper($type); + $type = strtoupper($type ?? ''); switch ($type) { case null: $loader = $this->getPluginLoader(self::CAPTCHA); diff --git a/tests/Zend/Captcha/FigletTest.php b/tests/Zend/Captcha/FigletTest.php index 868d313..4f32d99 100644 --- a/tests/Zend/Captcha/FigletTest.php +++ b/tests/Zend/Captcha/FigletTest.php @@ -87,9 +87,9 @@ public function testCaptchaHasIdAndInput() { $html = $this->element->render($this->getView()); $expect = sprintf('type="hidden" name="%s\[id\]" value="%s"', $this->element->getName(), $this->captcha->getId()); - $this->assertRegExp("/]*?$expect/", $html, $html); + $this->assertMatchesRegularExpression("/]*?$expect/", $html, $html); $expect = sprintf('type="text" name="%s\[input\]"', $this->element->getName()); - $this->assertRegExp("/]*?$expect/", $html, $html); + $this->assertMatchesRegularExpression("/]*?$expect/", $html, $html); } /* @@ -103,7 +103,7 @@ public function testLabelIdIsCorrect() $form->addElement($this->element); $html = $form->render($this->getView()); $expect = sprintf('for="comment-%s-input"', $this->element->getName()); - $this->assertRegExp("/