From fa5333a0f798806e6e5269016903696d752353bb Mon Sep 17 00:00:00 2001 From: Jay Klehr Date: Sat, 4 Dec 2021 09:03:24 -0700 Subject: [PATCH] testing php 8.1 (#124) * testing php 8.1 * removing unnecessary stubs * 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 | 13 ++++--- grumphp.yml.dist | 2 +- phpstan-bootstrap.php | 43 ------------------------ phpstan.neon | 4 +-- phpunit.xml.dist | 30 +++++++---------- src/Zend/Filter/Boolean.php | 8 ++--- src/Zend/Filter/Compress/Zip.php | 17 ---------- src/Zend/Filter/Encrypt/Mcrypt.php | 25 ++++---------- src/Zend/Filter/Encrypt/Openssl.php | 2 +- tests/Zend/Filter/Compress/ZipTest.php | 22 ------------ tests/Zend/Filter/DecryptTest.php | 15 --------- tests/Zend/Filter/Encrypt/McryptTest.php | 13 ------- tests/Zend/Filter/EncryptTest.php | 15 --------- tests/Zend/Filter/File/DecryptTest.php | 8 ----- tests/Zend/Filter/File/EncryptTest.php | 8 ----- 19 files changed, 78 insertions(+), 223 deletions(-) create mode 100644 .github/workflows/merge-me.yml rename .php_cs => .php-cs-fixer.php (64%) delete mode 100644 phpstan-bootstrap.php 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 d8756cf..c646771 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /tests/Zend/Filter/_files/Volumes .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 170840f..6e1b10a 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "license": "BSD-3-Clause", "prefer-stable": true, "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", @@ -39,13 +39,12 @@ } ], "require-dev": { - "phpunit/phpunit": "^8.0", - "phpstan/phpstan": "0.12.83", - "jetbrains/phpstorm-stubs": "dev-phpstan", + "phpunit/phpunit": "^9.5.10", + "phpstan/phpstan": "1.2.0", "pear/archive_tar": "^1.4.6", - "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" + "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 8a221bb..0ddc213 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 memory_limit: 768M diff --git a/phpstan-bootstrap.php b/phpstan-bootstrap.php deleted file mode 100644 index 90155a5..0000000 --- a/phpstan-bootstrap.php +++ /dev/null @@ -1,43 +0,0 @@ - - - - ./tests - - - - - ./src - - + + + + + ./src + + + + + ./tests + + diff --git a/src/Zend/Filter/Boolean.php b/src/Zend/Filter/Boolean.php index 0db9e60..f3b6e6e 100644 --- a/src/Zend/Filter/Boolean.php +++ b/src/Zend/Filter/Boolean.php @@ -354,11 +354,9 @@ protected function _getLocalizedQuestion($value, $yes, $locale) } $str = Zend_Locale::getTranslation($question, 'question', $locale); $str = explode(':', $str); - if (!empty($str)) { - foreach ($str as $no) { - if (($no == $value) || (strtolower($no) == strtolower($value))) { - return $return; - } + foreach ($str as $no) { + if (($no == $value) || (strtolower($no) == strtolower($value))) { + return $return; } } diff --git a/src/Zend/Filter/Compress/Zip.php b/src/Zend/Filter/Compress/Zip.php index 9a14653..1b51482 100644 --- a/src/Zend/Filter/Compress/Zip.php +++ b/src/Zend/Filter/Compress/Zip.php @@ -219,23 +219,6 @@ public function decompress($content) throw new Zend_Filter_Exception($this->_errorString($res)); } - if (version_compare(PHP_VERSION, '5.2.8', '<')) { - for ($i = 0; $i < $zip->numFiles; $i++) { - $statIndex = $zip->statIndex($i); - $currName = $statIndex['name']; - if (($currName[0] == '/') || - (substr($currName, 0, 2) == '..') || - (substr($currName, 0, 4) == './..') - ) { - throw new Zend_Filter_Exception( - 'Upward directory traversal was detected inside ' . $archive - . ' please use PHP 5.2.8 or greater to take advantage of path resolution features of ' - . 'the zip extension in this decompress() method.' - ); - } - } - } - $res = @$zip->extractTo($target); if ($res !== true) { throw new Zend_Filter_Exception($this->_errorString($res)); diff --git a/src/Zend/Filter/Encrypt/Mcrypt.php b/src/Zend/Filter/Encrypt/Mcrypt.php index c9633c5..4770393 100644 --- a/src/Zend/Filter/Encrypt/Mcrypt.php +++ b/src/Zend/Filter/Encrypt/Mcrypt.php @@ -157,17 +157,12 @@ public function setVector($vector = null) $cipher = $this->_openCipher(); $size = mcrypt_enc_get_iv_size($cipher); if (empty($vector)) { - $this->_srand(); - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && version_compare(PHP_VERSION, '5.3.0', '<')) { - $method = MCRYPT_RAND; + if (file_exists('/dev/urandom') || (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) { + $method = MCRYPT_DEV_URANDOM; + } elseif (file_exists('/dev/random')) { + $method = MCRYPT_DEV_RANDOM; } else { - if (file_exists('/dev/urandom') || (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) { - $method = MCRYPT_DEV_URANDOM; - } elseif (file_exists('/dev/random')) { - $method = MCRYPT_DEV_RANDOM; - } else { - $method = MCRYPT_RAND; - } + $method = MCRYPT_RAND; } $vector = mcrypt_create_iv($size, $method); } elseif (strlen($vector) != $size) { @@ -314,7 +309,6 @@ protected function _initCipher($cipher) $keysizes = mcrypt_enc_get_supported_key_sizes($cipher); if (empty($keysizes) || ($this->_encryption['salt'] == true)) { - $this->_srand(); $keysize = mcrypt_enc_get_key_size($cipher); $key = substr(md5($key), 0, $keysize); } elseif (!in_array(strlen($key), $keysizes)) { @@ -333,15 +327,10 @@ protected function _initCipher($cipher) * _srand() interception * * @see ZF-8742 + * @return void */ protected function _srand() { - if (version_compare(PHP_VERSION, '5.3.0', '>=')) { - return; - } - if (!self::$_srandCalled) { - srand(Zend_Crypt_Math::randInteger(0, PHP_INT_MAX)); - self::$_srandCalled = true; - } + return; } } diff --git a/src/Zend/Filter/Encrypt/Openssl.php b/src/Zend/Filter/Encrypt/Openssl.php index 31ea882..6e108f5 100644 --- a/src/Zend/Filter/Encrypt/Openssl.php +++ b/src/Zend/Filter/Encrypt/Openssl.php @@ -121,7 +121,7 @@ protected function _setKeys($keys) } foreach ($keys as $type => $key) { - if (ctype_print($key) && is_file(realpath($key)) && is_readable($key)) { + if (ctype_print((string) $key) && is_file(realpath($key)) && is_readable($key)) { $file = fopen($key, 'r'); $cert = fread($file, 8192); fclose($file); diff --git a/tests/Zend/Filter/Compress/ZipTest.php b/tests/Zend/Filter/Compress/ZipTest.php index c5c354f..aa2c118 100644 --- a/tests/Zend/Filter/Compress/ZipTest.php +++ b/tests/Zend/Filter/Compress/ZipTest.php @@ -306,26 +306,4 @@ public function testDecompressWillThrowExceptionWhenDecompressingWithNoTarget() $content = file_get_contents(dirname(__FILE__) . '/../_files/zip.tmp'); $this->assertEquals('compress me', $content); } - - /** - * @group RS - */ - public function testDecompressWillThrowExceptionWhenDetectingUpwardDirectoryTraversal() - { - $this->expectException(\Zend_Filter_Exception::class); - - if (version_compare(PHP_VERSION, '5.2.8', '>=')) { - $this->markTestSkipped('This test is to run on PHP less than 5.2.8'); - return; - } - - $filter = new Zend_Filter_Compress_Zip( - array( - 'archive' => dirname(__FILE__) . '/../_files/compressed.zip', - 'target' => dirname(__FILE__) . '/../_files/evil.zip' - ) - ); - - $filter->decompress(dirname(__FILE__) . '/../_files/evil.zip'); - } } diff --git a/tests/Zend/Filter/DecryptTest.php b/tests/Zend/Filter/DecryptTest.php index a1aee53..7ba2421 100644 --- a/tests/Zend/Filter/DecryptTest.php +++ b/tests/Zend/Filter/DecryptTest.php @@ -35,26 +35,11 @@ class Zend_Filter_DecryptTest extends PHPUnit\Framework\TestCase public function setUp(): void { - // mcrypt is deprecated in PHP 7.1 (but still installed by default on Travis) - // hiding deprecated errors so tests pass. - if (substr(PHP_VERSION, 0, 3) === '7.1') { - $this->errorReporting = error_reporting(E_ALL & ~E_DEPRECATED); - } - if (!extension_loaded('mcrypt') and !extension_loaded('openssl')) { $this->markTestSkipped('This filter needs the mcrypt or openssl extension'); } } - public function tearDown(): void - { - // mcrypt is deprecated in PHP 7.1 (but still installed by default on Travis) - // hiding deprecated errors so tests pass. - if (substr(PHP_VERSION, 0, 3) === '7.1') { - error_reporting($this->errorReporting); - } - } - /** * Ensures that the filter follows expected behavior * diff --git a/tests/Zend/Filter/Encrypt/McryptTest.php b/tests/Zend/Filter/Encrypt/McryptTest.php index b0c773e..568b463 100644 --- a/tests/Zend/Filter/Encrypt/McryptTest.php +++ b/tests/Zend/Filter/Encrypt/McryptTest.php @@ -35,24 +35,11 @@ class Zend_Filter_Encrypt_McryptTest extends PHPUnit\Framework\TestCase public function setUp(): void { - // mcrypt is deprecated in PHP 7.1 (but still installed by default on Travis) - // hiding deprecated errors so tests pass. - if (substr(PHP_VERSION, 0, 3) === '7.1') { - $this->errorReporting = error_reporting(E_ALL & ~E_DEPRECATED); - } - if (!extension_loaded('mcrypt')) { $this->markTestSkipped('This adapter needs the mcrypt extension'); } } - public function tearDown(): void - { - if (substr(PHP_VERSION, 0, 3) === '7.1') { - error_reporting($this->errorReporting); - } - } - /** * Ensures that the filter follows expected behavior * diff --git a/tests/Zend/Filter/EncryptTest.php b/tests/Zend/Filter/EncryptTest.php index c592397..91ebf80 100644 --- a/tests/Zend/Filter/EncryptTest.php +++ b/tests/Zend/Filter/EncryptTest.php @@ -35,26 +35,11 @@ class Zend_Filter_EncryptTest extends PHPUnit\Framework\TestCase public function setUp(): void { - // mcrypt is deprecated in PHP 7.1 (but still installed by default on Travis) - // hiding deprecated errors so tests pass. - if (substr(PHP_VERSION, 0, 3) === '7.1') { - $this->errorReporting = error_reporting(E_ALL & ~E_DEPRECATED); - } - if (!extension_loaded('mcrypt') and !extension_loaded('openssl')) { $this->markTestSkipped('This filter needs the mcrypt or openssl extension'); } } - public function tearDown(): void - { - // mcrypt is deprecated in PHP 7.1 (but still installed by default on Travis) - // hiding deprecated errors so tests pass. - if (substr(PHP_VERSION, 0, 3) === '7.1') { - error_reporting($this->errorReporting); - } - } - /** * Ensures that the filter follows expected behavior * diff --git a/tests/Zend/Filter/File/DecryptTest.php b/tests/Zend/Filter/File/DecryptTest.php index 34475b5..ec5ad01 100644 --- a/tests/Zend/Filter/File/DecryptTest.php +++ b/tests/Zend/Filter/File/DecryptTest.php @@ -35,10 +35,6 @@ class Zend_Filter_File_DecryptTest extends PHPUnit\Framework\TestCase public function setUp(): void { - if (substr(PHP_VERSION, 0, 3) === '7.1') { - $this->errorReporting = error_reporting(E_ALL & ~E_DEPRECATED); - } - if (!extension_loaded('mcrypt')) { $this->markTestSkipped('This filter needs the mcrypt extension'); } @@ -54,10 +50,6 @@ public function setUp(): void public function tearDown(): void { - if (substr(PHP_VERSION, 0, 3) === '7.1') { - error_reporting($this->errorReporting); - } - if (file_exists(dirname(__FILE__) . '/../_files/newencryption.txt')) { unlink(dirname(__FILE__) . '/../_files/newencryption.txt'); } diff --git a/tests/Zend/Filter/File/EncryptTest.php b/tests/Zend/Filter/File/EncryptTest.php index 97d8541..6f2aeee 100644 --- a/tests/Zend/Filter/File/EncryptTest.php +++ b/tests/Zend/Filter/File/EncryptTest.php @@ -35,10 +35,6 @@ class Zend_Filter_File_EncryptTest extends PHPUnit\Framework\TestCase public function setUp(): void { - if (substr(PHP_VERSION, 0, 3) === '7.1') { - $this->errorReporting = error_reporting(E_ALL & ~E_DEPRECATED); - } - if (!extension_loaded('mcrypt')) { $this->markTestSkipped('This filter needs the mcrypt extension'); } @@ -50,10 +46,6 @@ public function setUp(): void public function tearDown(): void { - if (substr(PHP_VERSION, 0, 3) === '7.1') { - error_reporting($this->errorReporting); - } - if (file_exists(dirname(__FILE__) . '/../_files/newencryption.txt')) { unlink(dirname(__FILE__) . '/../_files/newencryption.txt'); }