From 283170ecbb59bb59b947f01a993ff2fe8f7b8fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20San?= Date: Thu, 3 Aug 2023 12:04:18 +0200 Subject: [PATCH] test(phpunit): add phpunit10 support --- composer.json | 4 ++-- phpunit.xml.dist | 13 +++++------- .../FilesystemAdapterTestCase.php | 2 +- src/AsyncAwsS3/AsyncAwsS3AdapterTest.php | 2 +- src/AwsS3V3/AwsS3V3AdapterTest.php | 4 ++-- src/FileAttributesTest.php | 2 +- src/FilesystemTest.php | 4 ++-- src/Ftp/FtpAdapter.php | 2 +- src/Ftp/FtpAdapterTestCase.php | 6 +++--- src/Local/LocalFilesystemAdapterTest.php | 20 ------------------- src/MountManagerTest.php | 2 +- src/PathPrefixerTest.php | 2 +- .../ReadOnlyFilesystemAdapterTest.php | 2 +- src/WhitespacePathNormalizerTest.php | 6 +++--- .../NoRootPrefixZipArchiveAdapterTest.php | 2 +- .../PrefixedRootZipArchiveAdapterTest.php | 2 +- ...Test.php => ZipArchiveAdapterTestCase.php} | 8 ++++---- 17 files changed, 30 insertions(+), 53 deletions(-) rename src/ZipArchive/{ZipArchiveAdapterTest.php => ZipArchiveAdapterTestCase.php} (96%) diff --git a/composer.json b/composer.json index a33d35b86..f79962ed3 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "ext-fileinfo": "*", "ext-ftp": "*", "microsoft/azure-storage-blob": "^1.1", - "phpunit/phpunit": "^9.5.11", + "phpunit/phpunit": "^9.5.11|^10.0", "phpstan/phpstan": "^0.12.26", "phpseclib/phpseclib": "^3.0.14", "aws/aws-sdk-php": "^3.220.0", @@ -40,7 +40,7 @@ "conflict": { "async-aws/core": "<1.19.0", "async-aws/s3": "<1.14.0", - "symfony/http-client": "<6.3.1", + "symfony/http-client": "<5.2", "guzzlehttp/ringphp": "<1.1.1", "guzzlehttp/guzzle": "<7.0", "aws/aws-sdk-php": "3.209.31 || 3.210.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1b0996a2a..65347bfa2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,17 +8,14 @@ - - - src/ - - src/ - - - legacy + + + src + + diff --git a/src/AdapterTestUtilities/FilesystemAdapterTestCase.php b/src/AdapterTestUtilities/FilesystemAdapterTestCase.php index 1cf6ab417..4047d4ae7 100644 --- a/src/AdapterTestUtilities/FilesystemAdapterTestCase.php +++ b/src/AdapterTestUtilities/FilesystemAdapterTestCase.php @@ -179,7 +179,7 @@ public function writing_and_reading_files_with_special_path(string $path): void }); } - public function filenameProvider(): Generator + public static function filenameProvider(): Generator { yield "a path with square brackets in filename 1" => ["some/file[name].txt"]; yield "a path with square brackets in filename 2" => ["some/file[0].txt"]; diff --git a/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php b/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php index 3290db2c0..d7e980e1d 100644 --- a/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php +++ b/src/AsyncAwsS3/AsyncAwsS3AdapterTest.php @@ -232,7 +232,7 @@ public function failing_to_retrieve_metadata(Exception $exception, string $gette $adapter->{$getterName}('filename.txt'); } - public function dpFailingMetadataGetters(): iterable + public static function dpFailingMetadataGetters(): iterable { yield "mimeType" => [UnableToRetrieveMetadata::mimeType('filename.txt'), 'mimeType']; yield "lastModified" => [UnableToRetrieveMetadata::lastModified('filename.txt'), 'lastModified']; diff --git a/src/AwsS3V3/AwsS3V3AdapterTest.php b/src/AwsS3V3/AwsS3V3AdapterTest.php index 23ef4e342..ae8db3ce2 100644 --- a/src/AwsS3V3/AwsS3V3AdapterTest.php +++ b/src/AwsS3V3/AwsS3V3AdapterTest.php @@ -241,7 +241,7 @@ public function failing_to_retrieve_metadata(Exception $exception, string $gette $adapter->{$getterName}('filename.txt'); } - public function dpFailingMetadataGetters(): iterable + public static function dpFailingMetadataGetters(): iterable { yield "mimeType" => [UnableToRetrieveMetadata::mimeType('filename.txt'), 'mimeType']; yield "lastModified" => [UnableToRetrieveMetadata::lastModified('filename.txt'), 'lastModified']; @@ -282,7 +282,7 @@ public function streaming_reads_are_not_seekable_and_non_streaming_are(bool $str $this->assertEquals($seekable, $metadata['seekable']); } - public function casesWhereHttpStreamingInfluencesSeekability(): Generator + public static function casesWhereHttpStreamingInfluencesSeekability(): Generator { yield "not streaming reads have seekable stream" => [false, true]; yield "streaming reads have non-seekable stream" => [true, false]; diff --git a/src/FileAttributesTest.php b/src/FileAttributesTest.php index e2b3b9efe..5744f257a 100644 --- a/src/FileAttributesTest.php +++ b/src/FileAttributesTest.php @@ -94,7 +94,7 @@ public function json_transformations(FileAttributes $attributes): void $this->assertEquals($attributes, $newAttributes); } - public function data_provider_for_json_transformation(): Generator + public static function data_provider_for_json_transformation(): Generator { yield [new FileAttributes('path.txt', 1234, Visibility::PRIVATE, $now = time(), 'plain/text', ['key' => 'value'])]; yield [new FileAttributes('another.txt')]; diff --git a/src/FilesystemTest.php b/src/FilesystemTest.php index 580b8a377..e7ae891ed 100644 --- a/src/FilesystemTest.php +++ b/src/FilesystemTest.php @@ -71,7 +71,7 @@ public function trying_to_write_with_an_invalid_stream_arguments($input): void $this->filesystem->writeStream('path.txt', $input); } - public function invalidStreamInput(): Generator + public static function invalidStreamInput(): Generator { $handle = tmpfile(); fclose($handle); @@ -308,7 +308,7 @@ public function protecting_against_path_traversals(callable $scenario): void $scenario($this->filesystem); } - public function scenariosCausingPathTraversal(): Generator + public static function scenariosCausingPathTraversal(): Generator { yield [function (FilesystemOperator $filesystem) { $filesystem->delete('../path.txt'); diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index bdabfc781..0127df357 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -260,7 +260,7 @@ public function setVisibility(string $path, string $visibility): void $mode = $this->visibilityConverter->forFile($visibility); if ( ! @ftp_chmod($this->connection(), $mode, $location)) { - $message = error_get_last()['message']; + $message = error_get_last()['message'] ?? ''; throw UnableToSetVisibility::atLocation($path, $message); } } diff --git a/src/Ftp/FtpAdapterTestCase.php b/src/Ftp/FtpAdapterTestCase.php index e0a14c2f9..2675a40f6 100644 --- a/src/Ftp/FtpAdapterTestCase.php +++ b/src/Ftp/FtpAdapterTestCase.php @@ -118,7 +118,7 @@ public function failing_to_write_a_file(callable $scenario): void }); } - public function scenariosCausingWriteFailure(): Generator + public static function scenariosCausingWriteFailure(): Generator { yield "Not being able to create the parent directory" => [function () { mock_function('ftp_mkdir', false); @@ -153,7 +153,7 @@ public function scenarios_causing_directory_deletion_to_fail(callable $scenario) }); } - public function scenariosCausingDirectoryDeleteFailure(): Generator + public static function scenariosCausingDirectoryDeleteFailure(): Generator { yield "ftp_delete failure" => [function () { mock_function('ftp_delete', false); @@ -195,7 +195,7 @@ public function failing_to_move_because_creating_the_directory_fails(): void }); } - public function scenariosCausingCopyFailure(): Generator + public static function scenariosCausingCopyFailure(): Generator { yield "failing to read" => [function () { mock_function('ftp_fget', false); diff --git a/src/Local/LocalFilesystemAdapterTest.php b/src/Local/LocalFilesystemAdapterTest.php index 0b7cac2ef..8cb26ac92 100644 --- a/src/Local/LocalFilesystemAdapterTest.php +++ b/src/Local/LocalFilesystemAdapterTest.php @@ -724,16 +724,6 @@ protected static function createFilesystemAdapter(): FilesystemAdapter return new LocalFilesystemAdapter(static::ROOT); } - public static function assertFileDoesNotExist(string $filename, string $message = ''): void - { - if (is_callable('parent::assertFileDoesNotExist')) { - // PHPUnit 9+ - parent::assertFileDoesNotExist($filename, $message); - } else { - self::assertFileNotExists($filename, $message); - } - } - /** * @test */ @@ -747,14 +737,4 @@ public function get_checksum_with_specified_algo(): void $this->assertSame('0d5f5c7f', $checksum); } - - public static function assertDirectoryDoesNotExist(string $directory, string $message = ''): void - { - if (is_callable('parent::assertDirectoryDoesNotExist')) { - // PHPUnit 9+ - parent::assertDirectoryDoesNotExist($directory, $message); - } else { - self::assertDirectoryNotExists($directory, $message); - } - } } diff --git a/src/MountManagerTest.php b/src/MountManagerTest.php index fdc73cea9..cde9ebd0c 100644 --- a/src/MountManagerTest.php +++ b/src/MountManagerTest.php @@ -124,7 +124,7 @@ public function failing_a_one_param_method(string $method, FilesystemOperationFa $this->mountManager->{$method}('first://location.txt'); } - public function dpMetadataRetrieverMethods(): iterable + public static function dpMetadataRetrieverMethods(): iterable { yield 'mimeType' => ['mimeType', UnableToRetrieveMetadata::mimeType('location.txt')]; yield 'fileSize' => ['fileSize', UnableToRetrieveMetadata::fileSize('location.txt')]; diff --git a/src/PathPrefixerTest.php b/src/PathPrefixerTest.php index 8ca8401aa..f1bc1b68e 100644 --- a/src/PathPrefixerTest.php +++ b/src/PathPrefixerTest.php @@ -39,7 +39,7 @@ public function an_absolute_root_path_is_supported(string $rootPath, string $sep $this->assertEquals($expectedPath, $prefixedPath); } - public function dpRootPaths(): iterable + public static function dpRootPaths(): iterable { yield "unix-style root path" => ['/', '/', 'path.txt', '/path.txt']; yield "windows-style root path" => ['\\', '\\', 'path.txt', '\\path.txt']; diff --git a/src/ReadOnly/ReadOnlyFilesystemAdapterTest.php b/src/ReadOnly/ReadOnlyFilesystemAdapterTest.php index 8546f61d4..192a1f06a 100644 --- a/src/ReadOnly/ReadOnlyFilesystemAdapterTest.php +++ b/src/ReadOnly/ReadOnlyFilesystemAdapterTest.php @@ -38,7 +38,7 @@ public function can_perform_read_operations(): void $this->assertInstanceOf(FileAttributes::class, $adapter->mimeType('foo/bar.txt')); $this->assertInstanceOf(FileAttributes::class, $adapter->lastModified('foo/bar.txt')); $this->assertInstanceOf(FileAttributes::class, $adapter->fileSize('foo/bar.txt')); - $this->assertCount(1, $adapter->listContents('foo', true)); + $this->assertCount(1, iterator_to_array($adapter->listContents('foo', true))); } /** diff --git a/src/WhitespacePathNormalizerTest.php b/src/WhitespacePathNormalizerTest.php index a0288f795..04e9d77c3 100644 --- a/src/WhitespacePathNormalizerTest.php +++ b/src/WhitespacePathNormalizerTest.php @@ -33,7 +33,7 @@ public function path_normalizing(string $input, string $expected): void /** * @return array> */ - public function pathProvider(): array + public static function pathProvider(): array { return [ ['.', ''], @@ -78,7 +78,7 @@ public function rejecting_funky_whitespace(string $path): void $this->normalizer->normalizePath($path); } - public function dpFunkyWhitespacePaths(): iterable + public static function dpFunkyWhitespacePaths(): iterable { return [["some\0/path.txt"], ["s\x09i.php"]]; } @@ -86,7 +86,7 @@ public function dpFunkyWhitespacePaths(): iterable /** * @return array> */ - public function invalidPathProvider(): array + public static function invalidPathProvider(): array { return [ ['something/../../../hehe'], diff --git a/src/ZipArchive/NoRootPrefixZipArchiveAdapterTest.php b/src/ZipArchive/NoRootPrefixZipArchiveAdapterTest.php index 60acd008b..38fb66b9d 100644 --- a/src/ZipArchive/NoRootPrefixZipArchiveAdapterTest.php +++ b/src/ZipArchive/NoRootPrefixZipArchiveAdapterTest.php @@ -7,7 +7,7 @@ /** * @group zip */ -final class NoRootPrefixZipArchiveAdapterTest extends ZipArchiveAdapterTest +final class NoRootPrefixZipArchiveAdapterTest extends ZipArchiveAdapterTestCase { protected static function getRoot(): string { diff --git a/src/ZipArchive/PrefixedRootZipArchiveAdapterTest.php b/src/ZipArchive/PrefixedRootZipArchiveAdapterTest.php index ec738cc2b..9a9def76f 100644 --- a/src/ZipArchive/PrefixedRootZipArchiveAdapterTest.php +++ b/src/ZipArchive/PrefixedRootZipArchiveAdapterTest.php @@ -7,7 +7,7 @@ /** * @group zip */ -final class PrefixedRootZipArchiveAdapterTest extends ZipArchiveAdapterTest +final class PrefixedRootZipArchiveAdapterTest extends ZipArchiveAdapterTestCase { protected static function getRoot(): string { diff --git a/src/ZipArchive/ZipArchiveAdapterTest.php b/src/ZipArchive/ZipArchiveAdapterTestCase.php similarity index 96% rename from src/ZipArchive/ZipArchiveAdapterTest.php rename to src/ZipArchive/ZipArchiveAdapterTestCase.php index 0663fc2e0..3d9c46a82 100644 --- a/src/ZipArchive/ZipArchiveAdapterTest.php +++ b/src/ZipArchive/ZipArchiveAdapterTestCase.php @@ -22,7 +22,7 @@ /** * @group zip */ -abstract class ZipArchiveAdapterTest extends FilesystemAdapterTestCase +abstract class ZipArchiveAdapterTestCase extends FilesystemAdapterTestCase { private const ARCHIVE = __DIR__ . '/test.zip'; @@ -97,7 +97,7 @@ public function scenarios_that_cause_writing_a_file_to_fail(callable $scenario): }); } - public function scenariosThatCauseWritesToFail(): Generator + public static function scenariosThatCauseWritesToFail(): Generator { yield "writing a file fails when writing" => [function () { static::$archiveProvider->stubbedZipArchive()->failNextWrite(); @@ -172,8 +172,8 @@ public function list_root_directory(): void $this->givenWeHaveAnExistingFile('one/b.txt'); $this->givenWeHaveAnExistingFile('two/a.txt'); - $this->assertCount(6, $this->adapter()->listContents('', true)); - $this->assertCount(3, $this->adapter()->listContents('', false)); + $this->assertCount(6, iterator_to_array($this->adapter()->listContents('', true))); + $this->assertCount(3, iterator_to_array($this->adapter()->listContents('', false))); } /**