Skip to content

Commit

Permalink
Fix tests failing on PHP 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vaurdan committed Jul 19, 2021
1 parent b1690a9 commit 02f0aa8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions includes/class-syndication-encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public static function get_encryptor() {
return self::$encryptor;
}

// If mcrypt is available ( PHP < 7.1 ), use it instead.
if ( defined( 'MCRYPT_RIJNDAEL_256' ) ) {
// On PHP 7.1 mcrypt is available, but will throw a deprecated error if its used. Therefore, checking for the
// PHP version, instead of checking for mcrypt is a better approach.
if ( version_compare( PHP_VERSION, '7.1', '<' ) ) {
self::$encryptor = new Syndication_Encryptor_MCrypt();
return self::$encryptor;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/test-encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ public function test_encryptor_openssl() {
* @requires extension mcrypt
*/
public function test_encryptor_mcrypt() {
$encryptor = new \Syndication_Encryptor_MCrypt();

// Disable deprecation warning for this test, as it will run on PHP 7.1. This test will only ensure functionality of the
// Syndication_Encryptor_MCrypt class.
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting
$error_reporting = error_reporting( error_reporting() & ~E_DEPRECATED );

$encryptor = new \Syndication_Encryptor_MCrypt();

// Test the cipher.
$expected_cipher = MCRYPT_RIJNDAEL_256; // phpcs:ignore PHPCompatibility.Constants.RemovedConstants.mcrypt_rijndael_256DeprecatedRemoved
Expand All @@ -136,6 +139,9 @@ public function test_encryptor_mcrypt() {

$decrypted = $encryptor->decrypt( $encrypted );
self::assertEquals( $this->simple_string, $decrypted );

// Restore original error reporting.
error_reporting( $error_reporting ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting
}


Expand Down

0 comments on commit 02f0aa8

Please sign in to comment.