Skip to content

Commit

Permalink
PHPUnit - mcrypt deprecated since php >= 7.1 so skip test (Shardj#272)
Browse files Browse the repository at this point in the history
* phpunit - Skip test use method mcrypt_* on php >= 7.1

mcrypt_* function has been DEPRECATED as of PHP 7.1.0 and REMOVED as of PHP 7.2.0. Relying on this function is highly discouraged.

* phpunit - skip run Openssl test on php >= 8.0

since php 8.0 will raise something like that 'ArgumentCountError: openssl_seal() expects at least 5 arguments, 4 given'

* phpunit - ignore temp file make by test

* phpunit - comment out Zend_CurrencyTest suite

* phpunit - comment out Zend_Crypt_MathTest Suite

* php 8.1 - fix deprecated message

TypeError: count(): Argument #1 () must be of type Countable|array, null given

PHP Deprecated:  DOMDocument::__construct(): Passing null to parameter #2 () of type string is deprecated

* phpunit - correctly Zend_Feed_* test suite and turn on Zend_Feed_AllTests suite

* phpunit - back compatibility exception message for php < 8.0

* git - ignore temp file make by unittest

* phpunit - back compatibility exception message for php < 8.0 for Zend_ProgressBar_Adapter_ConsoleTest

* php <= 7.4 - fix warning 'A non well formed numeric value encountered'

* github action - add step run phpunit on php 7.4

* github action - run phpunit on php 8.1, 8.0, 8.4 parallel
  • Loading branch information
hungtrinh authored Nov 12, 2022
1 parent 673290a commit 0d4c5dc
Show file tree
Hide file tree
Showing 24 changed files with 158 additions and 78 deletions.
32 changes: 27 additions & 5 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
name: run PHPUnit-9
name: PHPUnit-9

on: [push, pull_request]

jobs:
phpunit:
phpunit-php81:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Prevent entrypoint issue on load docker image jakzal/phpqa:php8.0-alpine
- name: Prevent entrypoint issue on load docker image jakzal/phpqa:php
run: mv composer.json composer.json.bk
- name: PHPUnit 9 on php 8.1
uses: docker://jakzal/phpqa:php8.1-alpine
with:
args: /tools/phpunit --bootstrap tests/TestHelper.php tests/Zend/AllTests.php
phpunit-php80:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Prevent entrypoint issue on load docker image jakzal/phpqa:php
run: mv composer.json composer.json.bk
- name: PHPUnit 9 on php 8.0
uses: docker://jakzal/phpqa:php8.0-alpine
with:
args: /tools/phpunit --bootstrap tests/TestHelper.php tests/Zend/AllTests.php
- name: PHPUnit 9 on php 8.1
uses: docker://jakzal/phpqa:php8.1-alpine
phpunit-php74:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Prevent entrypoint issue on load docker image jakzal/phpqa:php
run: mv composer.json composer.json.bk
- name: PHPUnit 9 on php 7.4
uses: docker://jakzal/phpqa:php7.4-alpine
with:
args: /tools/phpunit --bootstrap tests/TestHelper.php tests/Zend/AllTests.php

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ tests/Zend/OpenId/_files/*
tests/Zend/Translate/Adapter/_files/zend_cache---internal-metadatas---testid
tests/Zend/Translate/Adapter/_files/zend_cache---testid
tests/TestConfiguration.php
tests/Zend/Cache/zend_cache_tmp_dir*
tests/Zend/Filter/_files/traversed.*
tests/Zend/Filter/_files/app/tests/Zend/Filter/_files/zipextracted.txt
tests/Zend/Mail/_files/test.tmp/INBOX
vendor/*
composer.lock
bin/dbunit
Expand All @@ -17,3 +21,4 @@ bin/parallel-lint
.php_cs.cache
.idea
.vscode

4 changes: 2 additions & 2 deletions library/Zend/Feed/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ protected function ensureAppended()
public function saveXml()
{
// Return a complete document including XML prologue.
$doc = new DOMDocument($this->_element->ownerDocument->version,
$this->_element->ownerDocument->actualEncoding);
$doc = new DOMDocument((string) $this->_element->ownerDocument->version,
(string) $this->_element->ownerDocument->actualEncoding);
$doc->appendChild($doc->importNode($this->_element, true));
return $doc->saveXML();
}
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Feed/Pubsubhubbub/Model/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function hasSubscription($key)
.' of "' . $key . '" must be a non-empty string');
}
$result = $this->_db->find($key);
if (count($result)) {
if (count($result ?? [])) {
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions library/Zend/Feed/Reader/Entry/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ public function getAuthors()
}
}

if (count($authors) === 0) {
if (count($authors ?? []) === 0) {
$authors = $this->getExtension('Atom')->getAuthors();
} else {
$authors = new Zend_Feed_Reader_Collection_Author(
Zend_Feed_Reader::arrayUnique($authors)
);
}

if (count($authors) === 0) {
if (count($authors ?? []) === 0) {
$authors = null;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Feed/Reader/Extension/Atom/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function getContent()
$content = $this->getDescription();
}

$this->_data['content'] = trim($content);
$this->_data['content'] = trim((string) $content);

return $this->_data['content'];
}
Expand Down
4 changes: 2 additions & 2 deletions library/Zend/Feed/Reader/Feed/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ public function getAuthors()
}
}

if (count($authors) === 0) {
if (count($authors ?? []) === 0) {
$authors = $this->getExtension('Atom')->getAuthors();
} else {
$authors = new Zend_Feed_Reader_Collection_Author(
Zend_Feed_Reader::arrayUnique($authors)
);
}

if (count($authors) === 0) {
if (count($authors ?? []) === 0) {
$authors = null;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Validate/File/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ protected function _fromByteString($size)
if (!is_numeric($value)) {
$value = substr($value, 0, -1);
}

$value = trim((string) $value);
switch (strtoupper($type)) {
case 'Y':
$value *= (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024);
Expand Down
10 changes: 5 additions & 5 deletions tests/Zend/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
require_once 'Zend/Console/GetoptTest.php';
require_once 'Zend/Controller/AllTests.php';
require_once 'Zend/CurrencyTest.php';
// require_once 'Zend/Crypt/AllTests.php';
require_once 'Zend/Crypt/AllTests.php';
require_once 'Zend/DateTest.php';
require_once 'Zend/Date/AllTests.php';
require_once 'Zend/DebugTest.php';
require_once 'Zend/EventManager/AllTests.php';
require_once 'Zend/ExceptionTest.php';
// require_once 'Zend/Feed/AllTests.php';
require_once 'Zend/Feed/AllTests.php';
require_once 'Zend/File/AllTests.php';
require_once 'Zend/FilterTest.php';
require_once 'Zend/Filter/AllTests.php';
Expand Down Expand Up @@ -191,16 +191,16 @@ public static function suite()
$suite->addTest(Zend_Config_AllTests::suite());
$suite->addTestSuite('Zend_Console_GetoptTest');
$suite->addTest(Zend_Controller_AllTests::suite());
// $suite->addTestSuite('Zend_CurrencyTest');
// $suite->addTest(Zend_Crypt_AllTests::suite());
$suite->addTestSuite('Zend_CurrencyTest');
$suite->addTest(Zend_Crypt_AllTests::suite());
$suite->addTestSuite('Zend_DateTest');
$suite->addTest(Zend_Date_AllTests::suite());
$suite->addTest(Zend_Db_AllTests::suite());
$suite->addTestSuite('Zend_DebugTest');
$suite->addTest(Zend_Dom_AllTests::suite());
$suite->addTest(Zend_EventManager_AllTests::suite());
$suite->addTestSuite('Zend_ExceptionTest');
// $suite->addTest(Zend_Feed_AllTests::suite());
$suite->addTest(Zend_Feed_AllTests::suite());
$suite->addTest(Zend_File_AllTests::suite());
$suite->addTestSuite('Zend_FilterTest');
$suite->addTest(Zend_Filter_AllTests::suite());
Expand Down
28 changes: 22 additions & 6 deletions tests/Zend/Controller/FrontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,12 @@ public function testDispatcherHandlesTypeError()

$body = $this->_controller->getResponse()->getBody();
$this->assertStringNotContainsString('Type error action called', $body);
$this->assertEquals("EXCEPTION_OTHER\nIndexController::produceTypeError(): Return value must be of type IndexController, stdClass returned", $body);
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
$this->assertEquals("EXCEPTION_OTHER\nReturn value of IndexController::produceTypeError() must be an instance of IndexController, instance of stdClass returned", $body);
} else {
$this->assertEquals("EXCEPTION_OTHER\nIndexController::produceTypeError(): Return value must be of type IndexController, stdClass returned", $body);
}

$this->assertSame(500, $this->_controller->getResponse()->getHttpResponseCode());
}

Expand Down Expand Up @@ -778,10 +783,17 @@ public function testDispatcherPassesTypeErrorThroughWhenThrowExceptions()
$this->_controller->dispatch($request, $response);
$this->fail('Should have thrown');
} catch (Throwable $e) {
$this->assertSame(
'IndexController::produceTypeError(): Return value must be of type IndexController, stdClass returned',
$e->getMessage()
);
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
$this->assertSame(
'Return value of IndexController::produceTypeError() must be an instance of IndexController, instance of stdClass returned',
$e->getMessage()
);
} else {
$this->assertSame(
'IndexController::produceTypeError(): Return value must be of type IndexController, stdClass returned',
$e->getMessage()
);
}
}
}

Expand All @@ -798,7 +810,11 @@ public function testDispatcherCatchesTypeExceptionFromPlugin()
$this->_controller->dispatch($request, $response);

$body = $this->_controller->getResponse()->getBody();
$this->assertEquals("EXCEPTION_OTHER\nMyApp\Controller\Plugin\ThrowingPlugin::produceTypeError(): Return value must be of type MyApp\Controller\Plugin\ThrowingPlugin, stdClass returned", $body);
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
$this->assertEquals("EXCEPTION_OTHER\nReturn value of MyApp\Controller\Plugin\ThrowingPlugin::produceTypeError() must be an instance of MyApp\Controller\Plugin\ThrowingPlugin, instance of stdClass returned", $body);
} else {
$this->assertEquals("EXCEPTION_OTHER\nMyApp\Controller\Plugin\ThrowingPlugin::produceTypeError(): Return value must be of type MyApp\Controller\Plugin\ThrowingPlugin, stdClass returned", $body);
}
$this->assertSame(500, $this->_controller->getResponse()->getHttpResponseCode());
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Zend/Crypt/MathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
*/
class Zend_Crypt_MathTest extends TestCase
{
/**
* on php > 7 will raise "ValueError: bccomp(): Argument #1 ($num1) is not well-formed"
* @requires PHP <= 7
*/
public function testRand()
{
if (!extension_loaded('bcmath')) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5026,7 +5026,7 @@ public function testLoose()

/**
* Temporary skip this test on php < 8.0 because raise issue 'A non-numeric value encountered'
* @requires PHP < 8
* @requires PHP < 7
*/
public function testTimesync()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Zend/Feed/Pubsubhubbub/Subscriber/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function testCanSetStorageImplementation()

public function testValidatesValidHttpGetData()
{
$mockReturnValue = $this->createMock('Result');
$mockReturnValue = $this->createMock('Zend_Db_Table_Row');
$mockReturnValue->expects($this->any())->method('toArray')->will($this->returnValue([
'verify_token' => hash('sha256', 'cba')
]));
Expand Down Expand Up @@ -195,7 +195,7 @@ public function testReturnsFalseIfVerifyTokenMissingFromHttpGetData()

public function testReturnsTrueIfModeSetAsUnsubscribeFromHttpGetData()
{
$mockReturnValue = $this->createMock('Result');
$mockReturnValue = $this->createMock('Zend_Db_Table_Row');
$mockReturnValue->expects($this->any())->method('toArray')->will($this->returnValue([
'verify_token' => hash('sha256', 'cba')
]));
Expand Down
10 changes: 8 additions & 2 deletions tests/Zend/Feed/Writer/Renderer/Entry/RssTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ protected function tearDown(): void
$this->_validEntry = null;
}

/**
* @doesNotPerformAssertions
*/
public function testRenderMethodRunsMinimalWriterContainerProperlyBeforeICheckAtomCompliance()
{
$this->expectException(Zend_Feed_Exception::class);
$renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
$renderer->render();
try {
$renderer->render();
} catch (Zend_Feed_Exception $e) {
$this->fail('Valid Writer object caused an exception when building which should never happen');
}
}

public function testEntryEncodingHasBeenSet()
Expand Down
10 changes: 8 additions & 2 deletions tests/Zend/Feed/Writer/Renderer/Feed/RssTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ public function testSetsWriterInConstructor()
$this->assertTrue($feed->getDataContainer() instanceof Zend_Feed_Writer_Feed);
}

/**
* @doesNotPerformAssertions
*/
public function testBuildMethodRunsMinimalWriterContainerProperlyBeforeICheckRssCompliance()
{
$this->expectException(Zend_Feed_Exception::class);
$feed = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
$feed->render();
try {
$feed->render();
} catch (Zend_Feed_Exception $e) {
$this->fail('Valid Writer object caused an exception when building which should never happen');
}
}

public function testFeedEncodingHasBeenSet()
Expand Down
56 changes: 28 additions & 28 deletions tests/Zend/Filter/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,36 +145,36 @@ public static function suite()
$suite->addTestSuite('Zend_Filter_StripNewlinesTest');
$suite->addTestSuite('Zend_Filter_StripTagsTest');

/*
$suite->addTestSuite('Zend_Filter_Compress_Bz2Test');
$suite->addTestSuite('Zend_Filter_Compress_GzTest');
$suite->addTestSuite('Zend_Filter_Compress_LzfTest');
$suite->addTestSuite('Zend_Filter_Compress_RarTest');
$suite->addTestSuite('Zend_Filter_Compress_TarTest');
$suite->addTestSuite('Zend_Filter_Compress_ZipTest');
$suite->addTestSuite('Zend_Filter_Encrypt_McryptTest');
$suite->addTestSuite('Zend_Filter_Encrypt_OpensslTest');
$suite->addTestSuite('Zend_Filter_File_DecryptTest');
$suite->addTestSuite('Zend_Filter_File_EncryptTest');
$suite->addTestSuite('Zend_Filter_File_LowerCaseTest');
$suite->addTestSuite('Zend_Filter_File_RenameTest');
$suite->addTestSuite('Zend_Filter_File_UpperCaseTest');
$suite->addTestSuite('Zend_Filter_Word_CamelCaseToDashTest');
$suite->addTestSuite('Zend_Filter_Word_CamelCaseToSeparatorTest');
$suite->addTestSuite('Zend_Filter_Word_CamelCaseToUnderscoreTest');
$suite->addTestSuite('Zend_Filter_Word_DashToCamelCaseTest');
$suite->addTestSuite('Zend_Filter_Word_DashToSeparatorTest');
$suite->addTestSuite('Zend_Filter_Word_DashToUnderscoreTest');
$suite->addTestSuite('Zend_Filter_Word_SeparatorToCamelCaseTest');
$suite->addTestSuite('Zend_Filter_Word_SeparatorToDashTest');
$suite->addTestSuite('Zend_Filter_Word_SeparatorToSeparatorTest');
$suite->addTestSuite('Zend_Filter_Word_UnderscoreToCamelCaseTest');
$suite->addTestSuite('Zend_Filter_Word_UnderscoreToDashTest');
$suite->addTestSuite('Zend_Filter_Word_UnderscoreToSeparatorTest');
*/
/*
$suite->addTestSuite('Zend_Filter_Compress_Bz2Test');
$suite->addTestSuite('Zend_Filter_Compress_GzTest');
$suite->addTestSuite('Zend_Filter_Compress_LzfTest');
$suite->addTestSuite('Zend_Filter_Compress_RarTest');
$suite->addTestSuite('Zend_Filter_Compress_TarTest');
$suite->addTestSuite('Zend_Filter_Compress_ZipTest');
$suite->addTestSuite('Zend_Filter_Encrypt_McryptTest');
$suite->addTestSuite('Zend_Filter_Encrypt_OpensslTest');
$suite->addTestSuite('Zend_Filter_File_DecryptTest');
$suite->addTestSuite('Zend_Filter_File_EncryptTest');
$suite->addTestSuite('Zend_Filter_File_LowerCaseTest');
$suite->addTestSuite('Zend_Filter_File_RenameTest');
$suite->addTestSuite('Zend_Filter_File_UpperCaseTest');
$suite->addTestSuite('Zend_Filter_Word_CamelCaseToDashTest');
$suite->addTestSuite('Zend_Filter_Word_CamelCaseToSeparatorTest');
$suite->addTestSuite('Zend_Filter_Word_CamelCaseToUnderscoreTest');
$suite->addTestSuite('Zend_Filter_Word_DashToCamelCaseTest');
$suite->addTestSuite('Zend_Filter_Word_DashToSeparatorTest');
$suite->addTestSuite('Zend_Filter_Word_DashToUnderscoreTest');
$suite->addTestSuite('Zend_Filter_Word_SeparatorToCamelCaseTest');
$suite->addTestSuite('Zend_Filter_Word_SeparatorToDashTest');
$suite->addTestSuite('Zend_Filter_Word_SeparatorToSeparatorTest');
$suite->addTestSuite('Zend_Filter_Word_UnderscoreToCamelCaseTest');
$suite->addTestSuite('Zend_Filter_Word_UnderscoreToDashTest');
$suite->addTestSuite('Zend_Filter_Word_UnderscoreToSeparatorTest');
*/

$suite->addTest(Zend_Filter_Compress_AllTests::suite());
// $suite->addTest(Zend_Filter_Encrypt_AllTests::suite());
$suite->addTest(Zend_Filter_Encrypt_AllTests::suite());
$suite->addTest(Zend_Filter_File_AllTests::suite());
$suite->addTest(Zend_Filter_Word_AllTests::suite());

Expand Down
5 changes: 4 additions & 1 deletion tests/Zend/Filter/DecryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ protected function setUp(): void
if (!extension_loaded('mcrypt') && !extension_loaded('openssl')) {
$this->markTestSkipped('This filter needs the mcrypt or openssl extension');
}
if (extension_loaded('mcrypt') && version_compare(PHP_VERSION, '7.1.0', '>=')) {
$this->markTestSkipped('mcrypt_* function has been DEPRECATED as of PHP 7.1.0 and REMOVED as of PHP 7.2.0. Relying on this function is highly discouraged.');
}
}

/**
Expand Down Expand Up @@ -215,7 +218,7 @@ public function testEncryptionWithDecryptionMcrypt()

/**
* Ensures that the filter allows de/encryption
*
* @requires PHP < 8.0
* @return void
*/
public function testEncryptionWithDecryptionOpenssl()
Expand Down
3 changes: 3 additions & 0 deletions tests/Zend/Filter/Encrypt/McryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ protected function setUp(): void
if (!extension_loaded('mcrypt')) {
$this->markTestSkipped('This adapter needs the mcrypt extension');
}
if (extension_loaded('mcrypt') && version_compare(PHP_VERSION, '7.1.0', '>=')) {
$this->markTestSkipped('mcrypt_* function has been DEPRECATED as of PHP 7.1.0 and REMOVED as of PHP 7.2.0. Relying on this function is highly discouraged.');
}
}

/**
Expand Down
Loading

0 comments on commit 0d4c5dc

Please sign in to comment.