Skip to content

Commit

Permalink
Merge pull request #20 from svycka/feature-19/php8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
boesing committed Jan 1, 2021
2 parents 17c99de + 7dece98 commit 87ebc8b
Show file tree
Hide file tree
Showing 46 changed files with 158 additions and 130 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@
/laminas-mkdoc-theme/
/phpunit.xml
/vendor/
.phpunit.result.cache
27 changes: 10 additions & 17 deletions .travis.yml
Expand Up @@ -12,38 +12,31 @@ env:
matrix:
fast_finish: true
include:
- php: 5.6
- php: 7.3
env:
- DEPS=lowest
- REMOVE_DEV_DEPS="psr/http-factory"
- php: 5.6
- php: 7.3
env:
- DEPS=latest
- REMOVE_DEV_DEPS="psr/http-factory"
- php: 7
env:
- DEPS=lowest
- php: 7
env:
- DEPS=latest
- php: 7.1
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.4
env:
- DEPS=lowest
- php: 7.1
- php: 7.4
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
- php: 8.0
env:
- DEPS=lowest
- php: 7.2
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"
- php: 8.0
env:
- DEPS=latest
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- if [[ $REMOVE_DEV_DEPS != '' ]]; then travis_retry composer remove $COMPOSER_ARGS --dev --no-update $REMOVE_DEV_DEPS ; fi

install:
- travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file, in reverse

### Added

- Nothing.
- [#20](https://github.com/laminas/laminas-filter/pull/20) Adds PHP 8.0 support

### Changed

Expand Down
9 changes: 5 additions & 4 deletions composer.json
Expand Up @@ -25,17 +25,18 @@
}
},
"require": {
"php": "^5.6 || ^7.0",
"laminas/laminas-stdlib": "^2.7.7 || ^3.1",
"php": "^7.3 || ~8.0.0",
"laminas/laminas-stdlib": "^3.3",
"laminas/laminas-zendframework-bridge": "^1.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "~1.0.0",
"laminas/laminas-crypt": "^3.2.1",
"laminas/laminas-servicemanager": "^2.7.8 || ^3.3",
"laminas/laminas-servicemanager": "^3.3",
"laminas/laminas-uri": "^2.6",
"pear/archive_tar": "^1.4.3",
"phpunit/phpunit": "^5.7.23 || ^6.4.3",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3",
"psr/http-factory": "^1.0"
},
"conflict": {
Expand Down
31 changes: 23 additions & 8 deletions src/Encrypt/Openssl.php
Expand Up @@ -131,7 +131,7 @@ protected function _setKeys($keys)
throw new Exception\InvalidArgumentException("Public key '{$cert}' not valid");
}

openssl_free_key($test);
$this->freeKeyResources([$test]);
$this->keys['public'][$key] = $cert;
break;
case 'private':
Expand All @@ -140,7 +140,7 @@ protected function _setKeys($keys)
throw new Exception\InvalidArgumentException("Private key '{$cert}' not valid");
}

openssl_free_key($test);
$this->freeKeyResources([$test]);
$this->keys['private'][$key] = $cert;
break;
case 'envelope':
Expand Down Expand Up @@ -364,10 +364,9 @@ public function encrypt($value)
$value = $compress($value);
}

$crypt = openssl_seal($value, $encrypted, $encryptedkeys, $keys);
foreach ($keys as $key) {
openssl_free_key($key);
}
$crypt = openssl_seal($value, $encrypted, $encryptedkeys, $keys, 'RC4');

$this->freeKeyResources($keys);

if ($crypt === false) {
throw new Exception\RuntimeException('Openssl was not able to encrypt your content with the given options');
Expand Down Expand Up @@ -439,8 +438,9 @@ public function decrypt($value)
$value = substr($value, $length);
}

$crypt = openssl_open($value, $decrypted, $envelope, $keys);
openssl_free_key($keys);
$crypt = openssl_open($value, $decrypted, $envelope, $keys, 'RC4');

$this->freeKeyResources([$keys]);

if ($crypt === false) {
throw new Exception\RuntimeException('Openssl was not able to decrypt you content with the given options');
Expand All @@ -464,4 +464,19 @@ public function toString()
{
return 'Openssl';
}

/**
* Free key resource if necessary.
* PHP 8 automatically frees the key instance and deprecates the function
*
* @param array<int,resource> $keys
*/
private function freeKeyResources(array $keys): void
{
if (PHP_VERSION_ID < 80000) {
foreach ($keys as $key) {
openssl_free_key($key);
}
}
}
}
4 changes: 2 additions & 2 deletions test/Compress/Bz2Test.php
Expand Up @@ -16,7 +16,7 @@ class Bz2Test extends TestCase
{
public $target;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('bz2')) {
$this->markTestSkipped('This adapter needs the bz2 extension');
Expand All @@ -25,7 +25,7 @@ public function setUp()
$this->target = sprintf('%s/%s.bz2', sys_get_temp_dir(), uniqid('laminasilter'));
}

public function tearDown()
public function tearDown(): void
{
if (file_exists($this->target)) {
unlink($this->target);
Expand Down
4 changes: 2 additions & 2 deletions test/Compress/GzTest.php
Expand Up @@ -16,7 +16,7 @@ class GzTest extends TestCase
{
public $target;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('zlib')) {
$this->markTestSkipped('This adapter needs the zlib extension');
Expand All @@ -25,7 +25,7 @@ public function setUp()
$this->target = sprintf('%s/%s.gz', sys_get_temp_dir(), uniqid('laminasilter'));
}

public function tearDown()
public function tearDown(): void
{
if (file_exists($this->target)) {
unlink($this->target);
Expand Down
2 changes: 1 addition & 1 deletion test/Compress/LzfTest.php
Expand Up @@ -13,7 +13,7 @@

class LlaminasTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('llaminas')) {
$this->markTestSkipped('This adapter needs the llaminas extension');
Expand Down
4 changes: 2 additions & 2 deletions test/Compress/RarTest.php
Expand Up @@ -16,7 +16,7 @@ class RarTest extends TestCase
{
public $tmp;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('rar')) {
$this->markTestSkipped('This adapter needs the rar extension');
Expand Down Expand Up @@ -48,7 +48,7 @@ public function setUp()
}
}

public function tearDown()
public function tearDown(): void
{
$files = [
$this->tmp . '/zipextracted.txt',
Expand Down
2 changes: 1 addition & 1 deletion test/Compress/SnappyTest.php
Expand Up @@ -14,7 +14,7 @@

class SnappyTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('snappy')) {
$this->markTestSkipped('This adapter needs the snappy extension');
Expand Down
4 changes: 2 additions & 2 deletions test/Compress/TarTest.php
Expand Up @@ -16,13 +16,13 @@ class TarTest extends TestCase
{
public $tmp;

public function setUp()
public function setUp(): void
{
$this->tmp = sprintf('%s/%s', sys_get_temp_dir(), uniqid('laminasilter'));
mkdir($this->tmp, 0775, true);
}

public function tearDown()
public function tearDown(): void
{
$files = [
$this->tmp . '/zipextracted.txt',
Expand Down
4 changes: 2 additions & 2 deletions test/Compress/ZipTest.php
Expand Up @@ -14,7 +14,7 @@

class ZipTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('zip')) {
$this->markTestSkipped('This adapter needs the zip extension');
Expand Down Expand Up @@ -54,7 +54,7 @@ public function setUp()
}
}

public function tearDown()
public function tearDown(): void
{
$files = [
$this->tmp . '/compressed.zip',
Expand Down
4 changes: 2 additions & 2 deletions test/CompressTest.php
Expand Up @@ -16,7 +16,7 @@ class CompressTest extends TestCase
{
public $tmpDir;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('bz2')) {
$this->markTestSkipped('This filter is tested with the bz2 extension');
Expand All @@ -26,7 +26,7 @@ public function setUp()
mkdir($this->tmpDir, 0775, true);
}

public function tearDown()
public function tearDown(): void
{
if (is_dir($this->tmpDir)) {
if (file_exists($this->tmpDir . '/compressed.bz2')) {
Expand Down
4 changes: 1 addition & 3 deletions test/DateSelectTest.php
Expand Up @@ -37,11 +37,9 @@ public function provideFilter()
];
}

/**
* @expectedException \Laminas\Filter\Exception\RuntimeException
*/
public function testInvalidInput()
{
$this->expectException(\Laminas\Filter\Exception\RuntimeException::class);
$sut = new DateSelectFilter();
$sut->filter(['year' => '2120', 'month' => '07']);
}
Expand Down
4 changes: 2 additions & 2 deletions test/DateTimeFormatterTest.php
Expand Up @@ -17,12 +17,12 @@ class DateTimeFormatterTest extends TestCase
{
protected $defaultTimezone;

public function setUp()
public function setUp(): void
{
$this->defaultTimezone = date_default_timezone_get();
}

public function tearDown()
public function tearDown(): void
{
date_default_timezone_set($this->defaultTimezone);
}
Expand Down
4 changes: 1 addition & 3 deletions test/DateTimeSelectTest.php
Expand Up @@ -57,11 +57,9 @@ public function provideFilter()
];
}

/**
* @expectedException \Laminas\Filter\Exception\RuntimeException
*/
public function testInvalidInput()
{
$this->expectException(\Laminas\Filter\Exception\RuntimeException::class);
$sut = new DateTimeSelectFilter();
$sut->filter(['year' => '2120', 'month' => '10', 'day' => '26', 'hour' => '12']);
}
Expand Down
4 changes: 2 additions & 2 deletions test/DecompressTest.php
Expand Up @@ -15,7 +15,7 @@ class DecompressTest extends TestCase
{
public $tmpDir;

public function setUp()
public function setUp(): void
{
if (! extension_loaded('bz2')) {
$this->markTestSkipped('This filter is tested with the bz2 extension');
Expand All @@ -25,7 +25,7 @@ public function setUp()
mkdir($this->tmpDir, 0775, true);
}

public function tearDown()
public function tearDown(): void
{
if (is_dir($this->tmpDir)) {
if (file_exists($this->tmpDir . '/compressed.bz2')) {
Expand Down
2 changes: 1 addition & 1 deletion test/DecryptTest.php
Expand Up @@ -14,7 +14,7 @@

class DecryptTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('mcrypt') && ! extension_loaded('openssl')) {
$this->markTestSkipped('This filter needs the mcrypt or openssl extension');
Expand Down
2 changes: 1 addition & 1 deletion test/DigitsTest.php
Expand Up @@ -27,7 +27,7 @@ class DigitsTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
if (null === static::$_unicodeEnabled) {
static::$_unicodeEnabled = (bool) @preg_match('/\pL/u', 'a');
Expand Down
8 changes: 4 additions & 4 deletions test/Encrypt/BlockCipherTest.php
Expand Up @@ -14,7 +14,7 @@

class BlockCipherTest extends TestCase
{
public function setUp()
public function setUp(): void
{
if (! extension_loaded('mcrypt') && ! extension_loaded('openssl')) {
$this->markTestSkipped('This filter needs the mcrypt or openssl extension');
Expand Down Expand Up @@ -163,20 +163,20 @@ public function testSettingEncryptionOptions()
$filter->setEncryption(1234);
$filter->fail();
} catch (\Laminas\Filter\Exception\InvalidArgumentException $e) {
$this->assertContains('Invalid options argument', $e->getMessage());
$this->assertStringContainsString('Invalid options argument', $e->getMessage());
}

try {
$filter->setEncryption(['algorithm' => 'unknown']);
$filter->fail();
} catch (\Laminas\Filter\Exception\InvalidArgumentException $e) {
$this->assertContains('The algorithm', $e->getMessage());
$this->assertStringContainsString('The algorithm', $e->getMessage());
}

try {
$filter->setEncryption(['mode' => 'unknown']);
} catch (\Laminas\Filter\Exception\InvalidArgumentException $e) {
$this->assertContains('The mode', $e->getMessage());
$this->assertStringContainsString('The mode', $e->getMessage());
}
}

Expand Down

0 comments on commit 87ebc8b

Please sign in to comment.