From a4a4e4ca07ba71bf17a76631e2c26986c6c0c72c Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 27 Aug 2024 10:09:36 +0200 Subject: [PATCH] Upgrade tests to run on newer phpunit --- .github/workflows/runTests.yml | 3 +- composer.json | 4 +- phpunit.xml.dist | 3 +- src/test/bootstrap.php | 79 +++++++++---------- src/test/patches/php8-return-types.diff | 21 ----- .../bovigo/vfs/DirectoryIterationTestCase.php | 4 +- .../php/org/bovigo/vfs/FilenameTestCase.php | 6 +- .../org/bovigo/vfs/PermissionsTestCase.php | 9 ++- src/test/php/org/bovigo/vfs/QuotaTestCase.php | 2 +- .../vfs/content/LargeFileContentTestCase.php | 2 +- .../StringBasedFileContentTestCase.php | 2 +- .../org/bovigo/vfs/vfsStreamBlockTestCase.php | 4 +- .../vfsStreamContainerIteratorTestCase.php | 4 +- .../vfsStreamDirectoryIssue134TestCase.php | 2 +- .../vfs/vfsStreamDirectoryIssue18TestCase.php | 2 +- .../bovigo/vfs/vfsStreamDirectoryTestCase.php | 6 +- .../bovigo/vfs/vfsStreamExLockTestCase.php | 2 +- .../org/bovigo/vfs/vfsStreamFileTestCase.php | 4 +- .../vfsStreamResolveIncludePathTestCase.php | 4 +- .../php/org/bovigo/vfs/vfsStreamTestCase.php | 8 +- .../org/bovigo/vfs/vfsStreamUmaskTestCase.php | 4 +- ...StreamWrapperAlreadyRegisteredTestCase.php | 6 +- .../vfs/vfsStreamWrapperBaseTestCase.php | 2 +- .../vfsStreamWrapperDirSeparatorTestCase.php | 2 +- .../vfs/vfsStreamWrapperDirTestCase.php | 11 ++- .../vfs/vfsStreamWrapperFileTimesTestCase.php | 2 +- .../vfs/vfsStreamWrapperFlockTestCase.php | 2 +- .../vfs/vfsStreamWrapperLargeFileTestCase.php | 2 +- .../vfs/vfsStreamWrapperQuotaTestCase.php | 2 +- .../vfs/vfsStreamWrapperSetOptionTestCase.php | 2 +- .../bovigo/vfs/vfsStreamWrapperTestCase.php | 22 +++--- .../vfsStreamWrapperUnregisterTestCase.php | 4 +- .../vfsStreamWrapperWithoutRootTestCase.php | 2 +- .../org/bovigo/vfs/vfsStreamZipTestCase.php | 2 +- .../vfsStreamAbstractVisitorTestCase.php | 4 +- .../visitor/vfsStreamPrintVisitorTestCase.php | 4 +- 36 files changed, 113 insertions(+), 131 deletions(-) delete mode 100644 src/test/patches/php8-return-types.diff diff --git a/.github/workflows/runTests.yml b/.github/workflows/runTests.yml index 25a72129..0dc51ccb 100644 --- a/.github/workflows/runTests.yml +++ b/.github/workflows/runTests.yml @@ -65,8 +65,7 @@ jobs: - name: Install PHPUnit 8 for PHP 8 if: matrix.php-versions == '8.0' || matrix.php-versions == '8.1' || matrix.php-versions == '8.2' || matrix.php-versions == '8.3' || matrix.php-versions == '8.4' run: | - composer require --dev phpunit/phpunit:8.5.17 --ignore-platform-reqs - git apply --reject --whitespace=fix src/test/patches/php8-return-types.diff + composer install --prefer-dist --no-progress - name: Run test suite run: composer run-script test -- --coverage-text diff --git a/composer.json b/composer.json index 932148c8..f729a8d3 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ "php": ">=7.1.0" }, "require-dev": { - "phpunit/phpunit": "^7.5||^8.5||^9.6||^10.5||^11.3", - "yoast/phpunit-polyfills": "^1.1" + "phpunit/phpunit": "^7.5||^8.5||^9.6", + "yoast/phpunit-polyfills": "^2.0" }, "autoload": { "psr-0": { "org\\bovigo\\vfs\\": "src/main/php" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e48588e4..56057d76 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" forceCoversAnnotation="false" mapTestClassNameToCoveredClassName="false" - printerClass="PHPUnit_TextUI_ResultPrinter" processIsolation="false" stopOnError="false" stopOnFailure="false" @@ -41,4 +40,4 @@ - \ No newline at end of file + diff --git a/src/test/bootstrap.php b/src/test/bootstrap.php index 8b1f8899..36745918 100644 --- a/src/test/bootstrap.php +++ b/src/test/bootstrap.php @@ -12,34 +12,31 @@ class_alias('\PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'); class_alias('PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error'); } -if (!class_exists("PHPUnit_Util_ErrorHandler")) -{ - class PHPUnit_Util_ErrorHandler { - public static function handleError($errno, $errstr, $errfile, $errline) - { - $errorHandler = new \PHPUnit\Util\ErrorHandler( - true, - true, - true, - true - ); - - return $errorHandler($errno, $errstr, $errfile, $errline); - } - } -} - -if (!class_exists("PHPUnit_TextUI_ResultPrinter")) -{ - class PHPUnit_TextUI_ResultPrinter extends \PHPUnit\TextUI\ResultPrinter {} -} - +//if (!class_exists("PHPUnit_Util_ErrorHandler")) +//{ +// class PHPUnit_Util_ErrorHandler { +// public static function handleError($errno, $errstr, $errfile, $errline) +// { +// $errorHandler = new \PHPUnit\Util\ErrorHandler( +// true, +// true, +// true, +// true +// ); +// +// return $errorHandler($errno, $errstr, $errfile, $errline); +// } +// } +//} /** * A modified version of PHPUnit's TestCase to rid ourselves of deprecation * warnings since we're using two different versions of PHPUnit in this branch * (PHPUnit 4 and 5). */ -class BC_PHPUnit_Framework_TestCase extends \PHPUnit_Framework_TestCase { +class BC_PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase { + + use \Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames; + public function bc_expectException($exception) { if (method_exists($this, 'expectException')) { @@ -64,21 +61,21 @@ public function bc_getMock($originalClassName, $methods = array(), array $argume } } -// The only deprecation warnings we need to ignore/handle are in PHP 7.4 so far -if (PHP_VERSION_ID >= 70400) { - function customErrorHandler($errno, $errstr, $errfile, $errline) { - // We know about this deprecation warning exists and it's already been - // fixed in the 2.x branch. For BC reasons in the 1.x branch, we'll - // ignore this warning to let tests pass. - if ($errno === E_DEPRECATED) { - if ($errstr === "Function ReflectionType::__toString() is deprecated") { - return true; - } - } - - // Any other error should be left up to PHPUnit to handle - return \PHPUnit_Util_ErrorHandler::handleError($errno, $errstr, $errfile, $errline); - } - - set_error_handler("customErrorHandler"); -} +//// The only deprecation warnings we need to ignore/handle are in PHP 7.4 so far +//if (PHP_VERSION_ID >= 70400) { +// function customErrorHandler($errno, $errstr, $errfile, $errline) { +// // We know about this deprecation warning exists and it's already been +// // fixed in the 2.x branch. For BC reasons in the 1.x branch, we'll +// // ignore this warning to let tests pass. +// if ($errno === E_DEPRECATED) { +// if ($errstr === "Function ReflectionType::__toString() is deprecated") { +// return true; +// } +// } +// +// // Any other error should be left up to PHPUnit to handle +// return \PHPUnit_Util_ErrorHandler::handleError($errno, $errstr, $errfile, $errline); +// } +// +// set_error_handler("customErrorHandler"); +//} diff --git a/src/test/patches/php8-return-types.diff b/src/test/patches/php8-return-types.diff deleted file mode 100644 index 040906d7..00000000 --- a/src/test/patches/php8-return-types.diff +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/vendor/phpunit/phpunit/src/Framework/TestCase.php b/vendor/phpunit/phpunit/src/Framework/TestCase.php -index 1223ca0c8..b5725af4c 100644 ---- a/vendor/phpunit/phpunit/src/Framework/TestCase.php -+++ b/vendor/phpunit/phpunit/src/Framework/TestCase.php -@@ -475,14 +475,14 @@ public static function tearDownAfterClass(): void - /** - * This method is called before each test. - */ -- protected function setUp(): void -+ protected function setUp() - { - } - - /** - * This method is called after each test. - */ -- protected function tearDown(): void -+ protected function tearDown() - { - } - diff --git a/src/test/php/org/bovigo/vfs/DirectoryIterationTestCase.php b/src/test/php/org/bovigo/vfs/DirectoryIterationTestCase.php index 4f30b038..6fcdf2ad 100644 --- a/src/test/php/org/bovigo/vfs/DirectoryIterationTestCase.php +++ b/src/test/php/org/bovigo/vfs/DirectoryIterationTestCase.php @@ -20,7 +20,7 @@ class DirectoryIterationTestCase extends vfsStreamWrapperBaseTestCase /** * clean up test environment */ - public function tearDown() + public function tearDown(): void { vfsStream::enableDotfiles(); } @@ -315,4 +315,4 @@ public function recursiveDirectoryIterationWithDotsDisabled() $pathes ); } -} \ No newline at end of file +} diff --git a/src/test/php/org/bovigo/vfs/FilenameTestCase.php b/src/test/php/org/bovigo/vfs/FilenameTestCase.php index 4b441306..678038f2 100644 --- a/src/test/php/org/bovigo/vfs/FilenameTestCase.php +++ b/src/test/php/org/bovigo/vfs/FilenameTestCase.php @@ -23,7 +23,7 @@ class FilenameTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { vfsStream::setup('root'); $this->rootDir = vfsStream::url('root'); @@ -53,11 +53,11 @@ public function worksWithCorrectName() /** * @test - * @expectedException UnexpectedValueException - * @expectedExceptionMessage ailed to open dir */ public function doesNotWorkWithInvalidName() { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('ailed to open dir'); $results = array(); $it = new \RecursiveDirectoryIterator($this->rootDir . '/lost found/'); foreach ($it as $f) { diff --git a/src/test/php/org/bovigo/vfs/PermissionsTestCase.php b/src/test/php/org/bovigo/vfs/PermissionsTestCase.php index e99a55a4..185be7ff 100644 --- a/src/test/php/org/bovigo/vfs/PermissionsTestCase.php +++ b/src/test/php/org/bovigo/vfs/PermissionsTestCase.php @@ -8,6 +8,8 @@ * @package org\bovigo\vfs */ namespace org\bovigo\vfs; +use PHPUnit\Framework\Error; + /** * Test for permissions related functionality. * @@ -23,7 +25,7 @@ class PermissionsTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setup() + public function setUp(): void { $structure = array('test_directory' => array('test.file' => '')); $this->root = vfsStream::setup('root', null, $structure); @@ -92,13 +94,14 @@ public function canNotChangeGroupWhenFileNotOwned() /** * @test * @group issue_107 - * @expectedException PHPUnit_Framework_Error - * @expectedExceptionMessage Can not create new file in non-writable path root * @requires PHP 5.4 * @since 1.5.0 */ public function touchOnNonWriteableDirectoryTriggersError() { + $this->expectException(Error\Warning::class); + $this->expectExceptionMessage('Can not create new file in non-writable path root'); + $this->root->chmod(0555); touch($this->root->url() . '/touch.txt'); } diff --git a/src/test/php/org/bovigo/vfs/QuotaTestCase.php b/src/test/php/org/bovigo/vfs/QuotaTestCase.php index 8c0f5b24..b56afd9d 100644 --- a/src/test/php/org/bovigo/vfs/QuotaTestCase.php +++ b/src/test/php/org/bovigo/vfs/QuotaTestCase.php @@ -25,7 +25,7 @@ class QuotaTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->quota = new Quota(10); } diff --git a/src/test/php/org/bovigo/vfs/content/LargeFileContentTestCase.php b/src/test/php/org/bovigo/vfs/content/LargeFileContentTestCase.php index c9015e16..203f598b 100644 --- a/src/test/php/org/bovigo/vfs/content/LargeFileContentTestCase.php +++ b/src/test/php/org/bovigo/vfs/content/LargeFileContentTestCase.php @@ -26,7 +26,7 @@ class LargeFileContentTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->largeFileContent = new LargeFileContent(100); } diff --git a/src/test/php/org/bovigo/vfs/content/StringBasedFileContentTestCase.php b/src/test/php/org/bovigo/vfs/content/StringBasedFileContentTestCase.php index 137a0925..75fc3f96 100644 --- a/src/test/php/org/bovigo/vfs/content/StringBasedFileContentTestCase.php +++ b/src/test/php/org/bovigo/vfs/content/StringBasedFileContentTestCase.php @@ -26,7 +26,7 @@ class StringBasedFileContentTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->stringBasedFileContent = new StringBasedFileContent('foobarbaz'); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamBlockTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamBlockTestCase.php index cd8e1a48..40a8b59a 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamBlockTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamBlockTestCase.php @@ -20,7 +20,7 @@ class vfsStreamBlockTestCase extends \BC_PHPUnit_Framework_TestCase */ protected $block; - public function setUp() + public function setUp(): void { $this->block = new vfsStreamBlock('foo'); } @@ -73,10 +73,10 @@ public function addStructure() /** * tests that a blank name for a block device throws an exception * @test - * @expectedException org\bovigo\vfs\vfsStreamException */ public function createWithEmptyName() { + $this->expectException(vfsStreamException::class); $structure = array( 'topLevel' => array( 'thisIsAFile' => 'file contents', diff --git a/src/test/php/org/bovigo/vfs/vfsStreamContainerIteratorTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamContainerIteratorTestCase.php index 934e014d..7698be03 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamContainerIteratorTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamContainerIteratorTestCase.php @@ -35,7 +35,7 @@ class vfsStreamContainerIteratorTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->dir = new vfsStreamDirectory('foo'); $this->mockChild1 = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); @@ -53,7 +53,7 @@ public function setUp() /** * clean up test environment */ - public function tearDown() + public function tearDown(): void { vfsStream::enableDotfiles(); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue134TestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue134TestCase.php index c1c0dda8..3e825891 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue134TestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue134TestCase.php @@ -22,7 +22,7 @@ class vfsStreamDirectoryIssue134TestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->rootDirectory = vfsStream::newDirectory('/'); $this->rootDirectory->addChild(vfsStream::newDirectory('var/log/app')); diff --git a/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue18TestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue18TestCase.php index fdf45b2c..1bf8661e 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue18TestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamDirectoryIssue18TestCase.php @@ -25,7 +25,7 @@ class vfsStreamDirectoryIssue18TestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->rootDirectory = vfsStream::newDirectory('/'); $this->rootDirectory->addChild(vfsStream::newDirectory('var/log/app')); diff --git a/src/test/php/org/bovigo/vfs/vfsStreamDirectoryTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamDirectoryTestCase.php index 19ed51b8..68e1bee9 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamDirectoryTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamDirectoryTestCase.php @@ -23,7 +23,7 @@ class vfsStreamDirectoryTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->dir = new vfsStreamDirectory('foo'); } @@ -32,10 +32,10 @@ public function setUp() * assure that a directory seperator inside the name throws an exception * * @test - * @expectedException org\bovigo\vfs\vfsStreamException */ public function invalidCharacterInName() { + $this->expectException(vfsStreamException::class); $dir = new vfsStreamDirectory('foo/bar'); } @@ -72,10 +72,10 @@ public function rename() * renaming the directory to an invalid name throws a vfsStreamException * * @test - * @expectedException org\bovigo\vfs\vfsStreamException */ public function renameToInvalidNameThrowsvfsStreamException() { + $this->expectException(vfsStreamException::class); $this->dir->rename('foo/baz'); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamExLockTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamExLockTestCase.php index 66ad14d6..891ee1d4 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamExLockTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamExLockTestCase.php @@ -19,7 +19,7 @@ class vfsStreamExLockTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - protected function setUp() + public function setUp(): void { $root = vfsStream::setup(); vfsStream::newFile('testfile')->at($root); diff --git a/src/test/php/org/bovigo/vfs/vfsStreamFileTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamFileTestCase.php index 5b7ade6c..537bcbe3 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamFileTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamFileTestCase.php @@ -23,7 +23,7 @@ class vfsStreamFileTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->file = new vfsStreamFile('foo'); } @@ -327,11 +327,11 @@ public function withContentAcceptsAnyFileContentInstance() /** * @test * @group issue_79 - * @expectedException \InvalidArgumentException * @since 1.3.0 */ public function withContentThrowsInvalidArgumentExceptionWhenContentIsNoStringAndNoFileContent() { + $this->expectException(\InvalidArgumentException::class); $this->file->withContent(313); } } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamResolveIncludePathTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamResolveIncludePathTestCase.php index 74fb773b..7f0130c7 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamResolveIncludePathTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamResolveIncludePathTestCase.php @@ -26,7 +26,7 @@ class vfsStreamResolveIncludePathTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->backupIncludePath = get_include_path(); vfsStream::setup(); @@ -37,7 +37,7 @@ public function setUp() /** * clean up test environment */ - public function tearDown() + public function tearDown(): void { set_include_path($this->backupIncludePath); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php index cc2bad7a..38e1f0d1 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamTestCase.php @@ -19,7 +19,7 @@ class vfsStreamTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { vfsStreamWrapper::register(); } @@ -387,11 +387,11 @@ public function createArraysAreTurnedIntoSubdirectoriesOfRoot() /** * @test * @group issue_20 - * @expectedException \InvalidArgumentException * @since 0.11.0 */ public function createThrowsExceptionIfNoBaseDirGivenAndNoRootSet() { + $this->expectException(\InvalidArgumentException::class); vfsStream::create(array('test' => array())); } @@ -566,11 +566,11 @@ public function inspectWithoutContentGivesRootToVisitor() /** * @test * @group issue_10 - * @expectedException \InvalidArgumentException * @since 0.10.0 */ public function inspectWithoutContentAndWithoutRootThrowsInvalidArgumentException() { + $this->expectException(\InvalidArgumentException::class); $mockVisitor = $this->bc_getMock('org\\bovigo\\vfs\\visitor\\vfsStreamVisitor'); $mockVisitor->expects($this->never()) ->method('visit'); @@ -592,11 +592,11 @@ protected function getFileSystemCopyDir() /** * @test * @group issue_4 - * @expectedException \InvalidArgumentException * @since 0.11.0 */ public function copyFromFileSystemThrowsExceptionIfNoBaseDirGivenAndNoRootSet() { + $this->expectException(\InvalidArgumentException::class); vfsStream::copyFromFileSystem($this->getFileSystemCopyDir()); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamUmaskTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamUmaskTestCase.php index 62fc2e12..2747399b 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamUmaskTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamUmaskTestCase.php @@ -20,7 +20,7 @@ class vfsStreamUmaskTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { vfsStream::umask(0000); } @@ -28,7 +28,7 @@ public function setUp() /** * clean up test environment */ - public function tearDown() + public function tearDown(): void { vfsStream::umask(0000); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperAlreadyRegisteredTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperAlreadyRegisteredTestCase.php index 279a2cee..786c3b84 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperAlreadyRegisteredTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperAlreadyRegisteredTestCase.php @@ -33,7 +33,7 @@ class vfsStreamWrapperAlreadyRegisteredTestCase extends \BC_PHPUnit_Framework_Te /** * set up test environment */ - public function setUp() + public function setUp(): void { TestvfsStreamWrapper::unregister(); $mock = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamWrapper'); @@ -43,7 +43,7 @@ public function setUp() /** * clean up test environment */ - public function tearDown() + public function tearDown(): void { TestvfsStreamWrapper::unregister(); } @@ -53,10 +53,10 @@ public function tearDown() * registered for the vfs scheme should throw an exception * * @test - * @expectedException org\bovigo\vfs\vfsStreamException */ public function registerOverAnotherStreamWrapper() { + $this->expectException(vfsStreamException::class); vfsStreamWrapper::register(); } } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperBaseTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperBaseTestCase.php index 4c12a45e..c60806de 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperBaseTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperBaseTestCase.php @@ -65,7 +65,7 @@ abstract class vfsStreamWrapperBaseTestCase extends \BC_PHPUnit_Framework_TestCa /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->fooURL = vfsStream::url('foo'); $this->barURL = vfsStream::url('foo/bar'); diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirSeparatorTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirSeparatorTestCase.php index 35fc0ce2..f9010437 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirSeparatorTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirSeparatorTestCase.php @@ -26,7 +26,7 @@ class vfsStreamWrapperDirSeparatorTestCase extends \BC_PHPUnit_Framework_TestCas /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->root = vfsStream::setup(); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirTestCase.php index 5f840c47..bd61597a 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperDirTestCase.php @@ -8,6 +8,8 @@ * @package org\bovigo\vfs */ namespace org\bovigo\vfs; +use PHPUnit\Framework\Error; + require_once __DIR__ . '/vfsStreamWrapperBaseTestCase.php'; /** * Test for org\bovigo\vfs\vfsStreamWrapper around mkdir(). @@ -214,11 +216,12 @@ public function mkDirShouldNotOverwriteExistingDirectories() /** * @test * @group issue_28 - * @expectedException PHPUnit_Framework_Error - * @expectedExceptionMessage mkdir(): Path vfs://root/dir exists */ public function mkDirShouldNotOverwriteExistingDirectoriesAndTriggerE_USER_WARNING() { + $this->expectException(Error\Warning::class); + $this->expectExceptionMessage('mkdir(): Path vfs://root/dir exists'); + vfsStream::setup('root'); $dir = vfsStream::url('root/dir'); $this->assertTrue(mkdir($dir)); @@ -239,11 +242,11 @@ public function mkDirShouldNotOverwriteExistingFiles() /** * @test * @group issue_28 - * @expectedException PHPUnit_Framework_Error - * @expectedExceptionMessage mkdir(): Path vfs://root/test.txt exists */ public function mkDirShouldNotOverwriteExistingFilesAndTriggerE_USER_WARNING() { + $this->expectException(Error\Warning::class); + $this->expectExceptionMessage('mkdir(): Path vfs://root/test.txt exists'); $root = vfsStream::setup('root'); vfsStream::newFile('test.txt')->at($root); $this->assertFalse(mkdir(vfsStream::url('root/test.txt'))); diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperFileTimesTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperFileTimesTestCase.php index cd3ea22c..f58b6bca 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperFileTimesTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperFileTimesTestCase.php @@ -37,7 +37,7 @@ class vfsStreamWrapperFileTimesTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { vfsStream::setup() ->lastModified(50) diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperFlockTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperFlockTestCase.php index 3fb137f7..114dd48c 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperFlockTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperFlockTestCase.php @@ -29,7 +29,7 @@ class vfsStreamWrapperFlockTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->root = vfsStream::setup(); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperLargeFileTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperLargeFileTestCase.php index fb5d9fd0..d6ae211a 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperLargeFileTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperLargeFileTestCase.php @@ -29,7 +29,7 @@ class vfsStreamWrapperLargeFileTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $root = vfsStream::setup(); $this->largeFile = vfsStream::newFile('large.txt') diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperQuotaTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperQuotaTestCase.php index 95031909..574ab9f8 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperQuotaTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperQuotaTestCase.php @@ -25,7 +25,7 @@ class vfsStreamWrapperQuotaTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->root = vfsStream::setup(); vfsStream::setQuota(10); diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperSetOptionTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperSetOptionTestCase.php index ff2ab14f..8f232b7b 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperSetOptionTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperSetOptionTestCase.php @@ -27,7 +27,7 @@ class vfsStreamWrapperSetOptionTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->root = vfsStream::setup(); vfsStream::newFile('foo.txt')->at($this->root); diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperTestCase.php index f2b3234d..b9919638 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperTestCase.php @@ -8,6 +8,8 @@ * @package org\bovigo\vfs */ namespace org\bovigo\vfs; +use PHPUnit\Framework\Error; + require_once __DIR__ . '/vfsStreamWrapperBaseTestCase.php'; /** * Test for org\bovigo\vfs\vfsStreamWrapper. @@ -405,7 +407,7 @@ public function renameDirectory() $baz3URL = vfsStream::url('foo/baz3'); $this->assertTrue(rename($this->barURL, $baz3URL)); $this->assertFileExists($baz3URL); - $this->assertFileNotExists($this->barURL); + $this->assertFileDoesNotExist($this->barURL); } /** @@ -417,7 +419,7 @@ public function renameDirectoryWithDots() $baz3URL = vfsStream::url('foo/baz3'); $this->assertTrue(rename($this->barURL . '/.', $baz3URL)); $this->assertFileExists($baz3URL); - $this->assertFileNotExists($this->barURL); + $this->assertFileDoesNotExist($this->barURL); } /** @@ -431,7 +433,7 @@ public function renameDirectoryWithDotsInTarget() $baz3URL = vfsStream::url('foo/../baz3/.'); $this->assertTrue(rename($this->barURL . '/.', $baz3URL)); $this->assertFileExists($baz3URL); - $this->assertFileNotExists($this->barURL); + $this->assertFileDoesNotExist($this->barURL); } /** @@ -443,20 +445,20 @@ public function renameDirectoryOverwritingExistingFile() // move foo/bar to foo/baz2 $this->assertTrue(rename($this->barURL, $this->baz2URL)); $this->assertFileExists(vfsStream::url('foo/baz2/baz1')); - $this->assertFileNotExists($this->barURL); + $this->assertFileDoesNotExist($this->barURL); } /** * @test - * @expectedException PHPUnit_Framework_Error */ public function renameFileIntoFile() { + $this->expectException(Error\Warning::class); // foo/baz2 is a file, so it can not be turned into a directory $baz3URL = vfsStream::url('foo/baz2/baz3'); $this->assertTrue(rename($this->baz1URL, $baz3URL)); $this->assertFileExists($baz3URL); - $this->assertFileNotExists($this->baz1URL); + $this->assertFileDoesNotExist($this->baz1URL); } /** @@ -470,27 +472,27 @@ public function renameFileToDirectory() $this->assertTrue(rename($this->baz1URL, $baz3URL)); $this->assertFileExists($this->barURL); $this->assertFileExists($baz3URL); - $this->assertFileNotExists($this->baz1URL); + $this->assertFileDoesNotExist($this->baz1URL); } /** * assert that trying to rename from a non existing file trigger a warning * - * @expectedException PHPUnit_Framework_Error * @test */ public function renameOnSourceFileNotFound() { + $this->expectException(Error\Warning::class); rename(vfsStream::url('notfound'), $this->baz1URL); } /** * assert that trying to rename to a directory that is not found trigger a warning - * @expectedException PHPUnit_Framework_Error * @test */ public function renameOnDestinationDirectoryFileNotFound() { + $this->expectException(Error\Warning::class); rename($this->baz1URL, vfsStream::url('foo/notfound/file2')); } /** @@ -619,10 +621,10 @@ public function statReturnsFullDataForDirectoriesWithDot() /** * @test - * @expectedException PHPUnit_Framework_Error */ public function openFileWithoutDirectory() { + $this->expectException(Error\Warning::class); vfsStreamWrapper::register(); $this->assertFalse(file_get_contents(vfsStream::url('file.txt'))); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperUnregisterTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperUnregisterTestCase.php index 4e27685a..01d1cfa5 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperUnregisterTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperUnregisterTestCase.php @@ -31,11 +31,11 @@ public function unregisterRegisteredUrlWrapper() * Unregistering a third party wrapper for vfs:// fails. * * @test - * @expectedException org\bovigo\vfs\vfsStreamException * @runInSeparateProcess */ public function unregisterThirdPartyVfsScheme() { + $this->expectException(vfsStreamException::class); // Unregister possible registered URL wrapper. vfsStreamWrapper::unregister(); @@ -49,11 +49,11 @@ public function unregisterThirdPartyVfsScheme() * Unregistering when not in registered state will fail. * * @test - * @expectedException org\bovigo\vfs\vfsStreamException * @runInSeparateProcess */ public function unregisterWhenNotInRegisteredState() { + $this->expectException(vfsStreamException::class); vfsStreamWrapper::register(); stream_wrapper_unregister(vfsStream::SCHEME); vfsStreamWrapper::unregister(); diff --git a/src/test/php/org/bovigo/vfs/vfsStreamWrapperWithoutRootTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamWrapperWithoutRootTestCase.php index 8267a327..03c3d5b9 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamWrapperWithoutRootTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamWrapperWithoutRootTestCase.php @@ -16,7 +16,7 @@ class vfsStreamWrapperWithoutRootTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { vfsStreamWrapper::register(); } diff --git a/src/test/php/org/bovigo/vfs/vfsStreamZipTestCase.php b/src/test/php/org/bovigo/vfs/vfsStreamZipTestCase.php index 210642c2..166186be 100644 --- a/src/test/php/org/bovigo/vfs/vfsStreamZipTestCase.php +++ b/src/test/php/org/bovigo/vfs/vfsStreamZipTestCase.php @@ -18,7 +18,7 @@ class vfsStreamZipTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { if (extension_loaded('zip') === false) { $this->markTestSkipped('No ext/zip installed, skipping test.'); diff --git a/src/test/php/org/bovigo/vfs/visitor/vfsStreamAbstractVisitorTestCase.php b/src/test/php/org/bovigo/vfs/visitor/vfsStreamAbstractVisitorTestCase.php index dfb3ed5a..e1d10109 100644 --- a/src/test/php/org/bovigo/vfs/visitor/vfsStreamAbstractVisitorTestCase.php +++ b/src/test/php/org/bovigo/vfs/visitor/vfsStreamAbstractVisitorTestCase.php @@ -30,7 +30,7 @@ class vfsStreamAbstractVisitorTestCase extends \BC_PHPUnit_Framework_TestCase /** * set up test environment */ - public function setUp() + public function setUp(): void { $this->abstractVisitor = $this->bc_getMock('org\\bovigo\\vfs\\visitor\\vfsStreamAbstractVisitor', array('visitFile', 'visitDirectory') @@ -39,10 +39,10 @@ public function setUp() /** * @test - * @expectedException \InvalidArgumentException */ public function visitThrowsInvalidArgumentExceptionOnUnknownContentType() { + $this->expectException(\InvalidArgumentException::class); $mockContent = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $mockContent->expects($this->any()) ->method('getType') diff --git a/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php b/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php index 294bd77d..3f8b8c70 100644 --- a/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php +++ b/src/test/php/org/bovigo/vfs/visitor/vfsStreamPrintVisitorTestCase.php @@ -22,19 +22,19 @@ class vfsStreamPrintVisitorTestCase extends \BC_PHPUnit_Framework_TestCase { /** * @test - * @expectedException \InvalidArgumentException */ public function constructWithNonResourceThrowsInvalidArgumentException() { + $this->expectException(\InvalidArgumentException::class); new vfsStreamPrintVisitor('invalid'); } /** * @test - * @expectedException \InvalidArgumentException */ public function constructWithNonStreamResourceThrowsInvalidArgumentException() { + $this->expectException(\InvalidArgumentException::class); new vfsStreamPrintVisitor(xml_parser_create()); }