Skip to content

Commit

Permalink
testing php 8.1 (diablomedia#124)
Browse files Browse the repository at this point in the history
* testing php 8.1

* removing unnecessary stubs

* narrowing php versions
  • Loading branch information
jaydiablo authored Dec 4, 2021
1 parent 45fdc7b commit fa5333a
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 223 deletions.
34 changes: 10 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,7 +32,7 @@ jobs:
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/[email protected].4
uses: actions/[email protected].7
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: php${{ matrix.php-versions }}-composer-${{ matrix.composer-args }}-${{ hashFiles('**/composer.json') }}
Expand All @@ -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
32 changes: 32 additions & 0 deletions .github/workflows/merge-me.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/tests/Zend/Filter/_files/Volumes
.php_cs.cache
.phpunit.result.cache
.php-cs-fixer.cache
9 changes: 4 additions & 5 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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/"
Expand Down
2 changes: 1 addition & 1 deletion grumphp.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 0 additions & 43 deletions phpstan-bootstrap.php

This file was deleted.

4 changes: 1 addition & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ parameters:
level: 2
paths:
- ./
excludes_analyse:
excludePaths:
- %rootDir%/../../../tests/*
- %rootDir%/../../../vendor/*
bootstrapFiles:
- %rootDir%/../../../phpstan-bootstrap.php
ignoreErrors:
# Unusual argument definition where param can either be Zend_Config|array or ...$args (if first param isn't Zend_Config|array)
- '#PHPDoc tag @param references unknown parameter: \$charSet#'
Expand Down
30 changes: 12 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
<phpunit
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="true"
backupGlobals="true"
stderr="true"
colors="true">
<testsuites>
<testsuite name="default">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" beStrictAboutTestsThatDoNotTestAnything="true" backupGlobals="true" stderr="true" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="default">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 3 additions & 5 deletions src/Zend/Filter/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
17 changes: 0 additions & 17 deletions src/Zend/Filter/Compress/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
25 changes: 7 additions & 18 deletions src/Zend/Filter/Encrypt/Mcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Zend/Filter/Encrypt/Openssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 0 additions & 22 deletions tests/Zend/Filter/Compress/ZipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
15 changes: 0 additions & 15 deletions tests/Zend/Filter/DecryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Loading

0 comments on commit fa5333a

Please sign in to comment.