Skip to content

Commit

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

* adding back service config

* fixing workflow

* using apcu if available

* enabling tests for apcu

* missed a couple of apc functions/classes

* narrowing php versions
  • Loading branch information
jaydiablo authored Dec 4, 2021
1 parent 548561f commit e2fb0e0
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 82 deletions.
36 changes: 11 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ 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 }}
services:
memcached:
Expand All @@ -32,12 +25,12 @@ jobs:
options: --health-cmd "timeout 5 bash -c 'cat < /dev/null > /dev/udp/127.0.0.1/11211'" --health-interval 10s --health-timeout 5s --health-retries 5
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, apc, apcu, memcached, memcache
extensions: mbstring, apcu, memcached, memcache
coverage: pcov
tools: cs2pr
ini-values: apc.enabled=1, apc.enable_cli=1
Expand All @@ -47,7 +40,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') }}
Expand All @@ -58,21 +51,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 @@ -3,3 +3,4 @@
/clover.xml
.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
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -29,11 +29,11 @@
}
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"phpstan/phpstan": "0.12.82",
"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/"
Expand All @@ -46,7 +46,7 @@
"scripts": {
"test": "phpunit",
"test-with-coverage": "phpunit --coverage-clover=clover.xml",
"phpstan": "phpstan analyze -c phpstan.neon --no-progress --ansi",
"phpstan": "phpstan analyze -c phpstan.neon --no-progress --ansi --memory-limit=768M",
"style-check": "php-cs-fixer fix --dry-run -vv"
},
"suggest": {
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
phpunit:
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:
level: 5
paths:
- ./
excludes_analyse:
excludePaths:
- %rootDir%/../../../tests/*
- %rootDir%/../../../vendor/*
inferPrivatePropertyTypeFromConstructor: true
Expand Down
2 changes: 1 addition & 1 deletion phpunit-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
defined('TESTS_ZEND_CACHE_LIBMEMCACHED_ENABLED') || define('TESTS_ZEND_CACHE_LIBMEMCACHED_ENABLED', false);
}

if (extension_loaded('apc')) {
if (extension_loaded('apc') || extension_loaded('apcu')) {
defined('TESTS_ZEND_CACHE_APC_ENABLED') || define('TESTS_ZEND_CACHE_APC_ENABLED', true);
} else {
defined('TESTS_ZEND_CACHE_APC_ENABLED') || define('TESTS_ZEND_CACHE_APC_ENABLED', false);
Expand Down
31 changes: 12 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
<phpunit
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="true"
backupGlobals="true"
stderr="true"
colors="true"
bootstrap="./phpunit-bootstrap.php">
<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" bootstrap="./phpunit-bootstrap.php" 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>
1 change: 1 addition & 0 deletions require-checker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"accelerator_get_configuration", "accelerator_license_info",
"apc_clear_cache", "apc_delete", "apc_fetch", "APC_ITER_KEY", "apc_sma_info", "apc_store", "APCIterator",
"apcu_clear_cache", "apcu_delete", "apcu_fetch", "apcu_sma_info", "apcu_store", "APCUIterator",
"hash",
"Memcache", "MEMCACHE_COMPRESSED",
"Memcached",
Expand Down
56 changes: 43 additions & 13 deletions src/Zend/Cache/Backend/Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba
*/
public function __construct(array $options = array())
{
if (!extension_loaded('apc')) {
Zend_Cache::throwException('The apc extension must be loaded for using this backend !');
if (!extension_loaded('apc') && !extension_loaded('apcu')) {
Zend_Cache::throwException('The apc or apc extension must be loaded for using this backend !');
}
parent::__construct($options);
}
Expand All @@ -61,7 +61,11 @@ public function __construct(array $options = array())
*/
public function load($id, $doNotTestCacheValidity = false)
{
$tmp = apc_fetch($id);
if (function_exists('apcu_fetch')) {
$tmp = apcu_fetch($id);
} else {
$tmp = apc_fetch($id);
}
if (is_array($tmp)) {
return $tmp[0];
}
Expand All @@ -76,7 +80,11 @@ public function load($id, $doNotTestCacheValidity = false)
*/
public function test($id)
{
$tmp = apc_fetch($id);
if (function_exists('apcu_fetch')) {
$tmp = apcu_fetch($id);
} else {
$tmp = apc_fetch($id);
}
if (is_array($tmp)) {
return $tmp[1];
}
Expand All @@ -98,8 +106,14 @@ public function test($id)
public function save($data, $id, $tags = array(), $specificLifetime = false)
{
$lifetime = $this->getLifetime($specificLifetime);
/** @var bool $result Won't return an array if $id is a string */
$result = apc_store($id, array($data, time(), $lifetime), $lifetime);
if (function_exists('apcu_store')) {
/** @var bool $result Won't return an array if $id is a string */
$result = apcu_store($id, array($data, time(), $lifetime), $lifetime);
} else {
/** @var bool $result Won't return an array if $id is a string */
$result = apc_store($id, array($data, time(), $lifetime), $lifetime);
}

if (count($tags) > 0) {
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
}
Expand All @@ -114,7 +128,7 @@ public function save($data, $id, $tags = array(), $specificLifetime = false)
*/
public function remove($id)
{
return apc_delete($id);
return function_exists('apcu_delete') ? apcu_delete($id) : apc_delete($id);
}

/**
Expand All @@ -136,7 +150,7 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
switch ($mode) {
case Zend_Cache::CLEANING_MODE_ALL:
return apc_clear_cache('user');
return function_exists('apcu_clear_cache') ? apcu_clear_cache() : apc_clear_cache('user');
case Zend_Cache::CLEANING_MODE_OLD:
$this->_log('Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend');
break;
Expand Down Expand Up @@ -174,7 +188,7 @@ public function isAutomaticCleaningAvailable()
*/
public function getFillingPercentage()
{
$mem = apc_sma_info(true);
$mem = function_exists('apcu_sma_info') ? apcu_sma_info(true) : apc_sma_info(true);
$memSize = $mem['num_seg'] * $mem['seg_size'];
$memAvailable = $mem['avail_mem'];
$memUsed = $memSize - $memAvailable;
Expand Down Expand Up @@ -248,7 +262,11 @@ public function getIdsMatchingAnyTags($tags = array())
public function getIds()
{
$ids = array();
$iterator = new APCIterator('user', null, APC_ITER_KEY);
if (class_exists('APCUIterator', false)) {
$iterator = new APCUIterator(null, APC_ITER_KEY);
} else {
$iterator = new APCIterator('user', null, APC_ITER_KEY);
}
foreach ($iterator as $item) {
$ids[] = $item['key'];
}
Expand All @@ -269,7 +287,11 @@ public function getIds()
*/
public function getMetadatas($id)
{
$tmp = apc_fetch($id);
if (function_exists('apcu_fetch')) {
$tmp = apcu_fetch($id);
} else {
$tmp = apc_fetch($id);
}
if (is_array($tmp)) {
$data = $tmp[0];
$mtime = $tmp[1];
Expand Down Expand Up @@ -297,7 +319,11 @@ public function getMetadatas($id)
*/
public function touch($id, $extraLifetime)
{
$tmp = apc_fetch($id);
if (function_exists('apcu_fetch')) {
$tmp = apcu_fetch($id);
} else {
$tmp = apc_fetch($id);
}
if (is_array($tmp)) {
$data = $tmp[0];
$mtime = $tmp[1];
Expand All @@ -311,7 +337,11 @@ public function touch($id, $extraLifetime)
if ($newLifetime <= 0) {
return false;
}
apc_store($id, array($data, time(), $newLifetime), $newLifetime);
if (function_exists('apcu_store')) {
apcu_store($id, array($data, time(), $newLifetime), $newLifetime);
} else {
apc_store($id, array($data, time(), $newLifetime), $newLifetime);
}
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Zend/Cache/Backend/ZendPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(array $options = array())
'The cache copies directory \'' . ini_get('zend_accelerator.output_cache_dir') . '\' must be writable !'
);
}
parent:: __construct($options);
parent::__construct($options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/Cache/ApcBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function setUp($notag = true): void
constant('TESTS_ZEND_CACHE_APC_ENABLED') === false) {
$this->markTestSkipped('Tests are not enabled in TestConfiguration.php');
return;
} elseif (!extension_loaded('apc')) {
} elseif (!extension_loaded('apc') && !extension_loaded('apcu')) {
$this->markTestSkipped("Extension 'APC' is not loaded");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/Cache/FileBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,6 @@ public function testShouldDeleteOldMetadataFiles()

$this->assertFileExists($fn);
$this->assertTrue($this->_instance->clean(Zend_Cache::CLEANING_MODE_ALL));
$this->assertFileNotExists($fn);
$this->assertFileDoesNotExist($fn);
}
}
Loading

0 comments on commit e2fb0e0

Please sign in to comment.