Tests: PHPUnit 10 updates

This commit is contained in:
terrafrost 2023-02-05 17:33:16 -06:00
parent fa9bf44ed6
commit 508eaa7197
7 changed files with 60 additions and 49 deletions

View File

@ -58,9 +58,12 @@ jobs:
php-version: ${{ matrix.php-version }}
- name: Composer Install
run: composer install --classmap-authoritative --no-interaction --no-cache
- name: Make Tests Compatiable With New PHPUnit Versions
- name: Make Tests Compatiable With PHPUnit 7+
if: matrix.php-version != '5.6' && matrix.php-version != '7.0'
run: php tests/make_compatible_with_new_phpunit_versions.php
run: php tests/make_compatible_with_phpunit7.php
- name: Make Tests Compatiable With PHPUnit 9+
if: matrix.php-version != '5.6' && matrix.php-version != '7.0' && matrix.php-version != '7.1' && matrix.php-version != '7.2'
run: php tests/make_compatible_with_phpunit9.php
- name: Setup Secure Shell Functional Tests
if: matrix.os == 'ubuntu-latest'
run: |
@ -84,7 +87,7 @@ jobs:
echo "PHPSECLIB_SSH_HOME=/home/phpseclib" >> $GITHUB_ENV
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV
- name: PHPUnit
run: vendor/bin/phpunit --verbose --configuration tests/phpunit.xml
run: vendor/bin/phpunit --configuration tests/phpunit.xml
strategy:
fail-fast: false
matrix:

View File

@ -108,6 +108,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase
/**
* @depends testPasswordLogin
* @group github280
* @requires PHPUnit < 10
*/
public function testExecWithMethodCallback(SSH2 $ssh)
{

View File

@ -105,66 +105,36 @@ abstract class PhpseclibTestCase extends TestCase
// assertIsArray was not introduced until PHPUnit 8
public static function assertIsArray($actual, $message = '')
{
if (method_exists(parent::class, 'assertIsArray')) {
parent::assertIsArray($actual, $message);
return;
}
parent::assertInternalType('array', $actual, $message);
}
// assertIsString was not introduced until PHPUnit 8
public static function assertIsString($actual, $message = '')
{
if (method_exists(parent::class, 'assertIsString')) {
parent::assertIsString($actual, $message);
return;
}
parent::assertInternalType('string', $actual, $message);
}
// assertIsResource was not introduced until PHPUnit 8
public static function assertIsResource($actual, $message = '')
{
if (method_exists(parent::class, 'assertIsResource')) {
parent::assertIsResource($actual, $message);
return;
}
parent::assertInternalType('resource', $actual, $message);
}
// assertIsObject was not introduced until PHPUnit 8
public static function assertIsObject($actual, $message = '')
{
if (method_exists(parent::class, 'assertIsObject')) {
parent::assertIsObject($actual, $message);
return;
}
parent::assertInternalType('object', $actual, $message);
}
// assertContains is deprecated for strings in PHPUnit 8
public static function assertStringContainsString($needle, $haystack, $message = '')
{
if (method_exists(parent::class, 'assertStringContainsString')) {
parent::assertStringContainsString($needle, $haystack, $message);
return;
}
parent::assertContains($needle, $haystack, $message);
}
// assertNotContains is deprecated for strings in PHPUnit 8
public static function assertStringNotContainsString($needle, $haystack, $message = '')
{
if (method_exists(parent::class, 'assertStringContainsString')) {
parent::assertStringNotContainsString($needle, $haystack, $message);
return;
}
parent::assertNotContains($needle, $haystack, $message);
}
@ -178,10 +148,6 @@ abstract class PhpseclibTestCase extends TestCase
*/
public static function assertMatchesRegularExpression($pattern, $string, $message = '')
{
if (method_exists(parent::class, 'assertMatchesRegularExpression')) {
parent::assertMatchesRegularExpression($pattern, $string, $message);
} else {
parent::assertRegExp($pattern, $string, $message);
}
parent::assertRegExp($pattern, $string, $message);
}
}

View File

@ -169,7 +169,7 @@ class HashTest extends PhpseclibTestCase
}
/**
* @dataProvider hmacData()
* @dataProvider hmacData
*/
public function testHMAC($hash, $key, $message, $result)
{
@ -177,7 +177,7 @@ class HashTest extends PhpseclibTestCase
}
/**
* @dataProvider hmacData()
* @dataProvider hmacData
*/
public function testHMAC96($hash, $key, $message, $result)
{
@ -370,7 +370,7 @@ class HashTest extends PhpseclibTestCase
}
/**
* @dataProvider hashData()
* @dataProvider hashData
*/
public function testHash($hash, $message, $result)
{
@ -378,7 +378,7 @@ class HashTest extends PhpseclibTestCase
}
/**
* @dataProvider hashData()
* @dataProvider hashData
*/
public function testHash96($hash, $message, $result)
{

View File

@ -31,6 +31,7 @@ class SSH2UnitTest extends PhpseclibTestCase
/**
* @dataProvider formatLogDataProvider
* @requires PHPUnit < 10
*/
public function testFormatLog(array $message_log, array $message_number_log, $expected)
{
@ -40,6 +41,9 @@ class SSH2UnitTest extends PhpseclibTestCase
$this->assertEquals($expected, $result);
}
/**
* @requires PHPUnit < 10
*/
public function testGenerateIdentifier()
{
$identifier = self::callFunc($this->createSSHMock(), 'generate_identifier');
@ -72,6 +76,9 @@ class SSH2UnitTest extends PhpseclibTestCase
}
}
/**
* @requires PHPUnit < 10
*/
public function testGetExitStatusIfNotConnected()
{
$ssh = $this->createSSHMock();
@ -79,12 +86,18 @@ class SSH2UnitTest extends PhpseclibTestCase
$this->assertFalse($ssh->getExitStatus());
}
/**
* @requires PHPUnit < 10
*/
public function testPTYIDefaultValue()
{
$ssh = $this->createSSHMock();
$this->assertFalse($ssh->isPTYEnabled());
}
/**
* @requires PHPUnit < 10
*/
public function testEnablePTY()
{
$ssh = $this->createSSHMock();
@ -96,6 +109,9 @@ class SSH2UnitTest extends PhpseclibTestCase
$this->assertFalse($ssh->isPTYEnabled());
}
/**
* @requires PHPUnit < 10
*/
public function testQuietModeDefaultValue()
{
$ssh = $this->createSSHMock();
@ -103,6 +119,9 @@ class SSH2UnitTest extends PhpseclibTestCase
$this->assertFalse($ssh->isQuietModeEnabled());
}
/**
* @requires PHPUnit < 10
*/
public function testEnableQuietMode()
{
$ssh = $this->createSSHMock();

View File

@ -12,13 +12,12 @@ foreach ($files as $file) {
'~ function setUpBeforeClass\(\)~' => ' function setUpBeforeClass(): void',
'~ function setUp\(\)~' => ' function setUp(): void',
'~ function tearDown\(\)~' => ' function tearDown(): void',
'~ function assertIsArray\(\$actual, \$message = \'\'\)~' => ' function assertIsArray($actual, string $message = \'\'): void',
'~ function assertIsResource\(\$actual, \$message = \'\'\)~' => ' function assertIsResource($actual, string $message = \'\'): void',
'~ function assertIsObject\(\$actual, \$message = \'\'\)~' => ' function assertIsObject($actual, string $message = \'\'): void',
'~ function assertIsString\(\$actual, \$message = \'\'\)~' => ' function assertIsString($actual, string $message = \'\'): void',
'~ function assertStringContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function assertStringContainsString(string $needle, string $haystack, string $message = \'\'): void',
'~ function assertStringNotContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function assertStringNotContainsString(string $needle, string $haystack, string $message = \'\'): void',
'~ function assertMatchesRegularExpression\(\$pattern, \$string, \$message = \'\'\)~' => ' function assertMatchesRegularExpression(string $pattern, string $string, string $message = \'\'): void',
'~ function assertIsArray\(\$actual, \$message = \'\'\)~' => ' function _assertIsArray($actual, string $message = \'\')',
'~ function assertIsResource\(\$actual, \$message = \'\'\)~' => ' function _assertIsResource($actual, string $message = \'\')',
'~ function assertIsObject\(\$actual, \$message = \'\'\)~' => ' function _assertIsObject($actual, string $message = \'\')',
'~ function assertIsString\(\$actual, \$message = \'\'\)~' => ' function _assertIsString($actual, string $message = \'\')',
'~ function assertStringContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function _assertStringContainsString(string $needle, string $haystack, string $message = \'\')',
'~ function assertStringNotContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function _assertStringNotContainsString(string $needle, string $haystack, string $message = \'\')'
];
$updatedFileContents = preg_replace(
array_keys($patternToReplacementMap),

View File

@ -0,0 +1,23 @@
<?php
/** @var iterable<SplFileInfo> $files */
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__));
foreach ($files as $file) {
if ($file->getExtension() === 'php' && $file->getPathname() !== __FILE__) {
$fileContents = file_get_contents($file->getPathname());
if ($fileContents === false) {
throw new \RuntimeException('file_get_contents() failed: ' . $file->getPathname());
}
$patternToReplacementMap = [
'~ function assertMatchesRegularExpression\(\$pattern, \$string, \$message = \'\'\)~' => ' function _assertMatchesRegularExpression(string $pattern, string $string, string $message = \'\')',
];
$updatedFileContents = preg_replace(
array_keys($patternToReplacementMap),
array_values($patternToReplacementMap),
$fileContents
);
if (file_put_contents($file->getPathname(), $updatedFileContents) === false) {
throw new \RuntimeException('file_put_contents() failed: ' . $file->getPathname());
}
}
}