Skip to content

Commit

Permalink
Upgrade tests to run on newer phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapio committed Aug 27, 2024
1 parent dafa558 commit eb843bd
Show file tree
Hide file tree
Showing 34 changed files with 109 additions and 108 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
Expand Down Expand Up @@ -41,4 +40,4 @@
<ini name="memory_limit" value="-1"/>
<ini name="error_reporting" value="30719"/> <!-- E_ALL | E_STRICT -->
</php>
</phpunit>
</phpunit>
76 changes: 35 additions & 41 deletions src/test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,28 @@ 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 {
public function bc_expectException($exception)
{
if (method_exists($this, 'expectException')) {
Expand All @@ -64,21 +58,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");
//}
4 changes: 2 additions & 2 deletions src/test/php/org/bovigo/vfs/DirectoryIterationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DirectoryIterationTestCase extends vfsStreamWrapperBaseTestCase
/**
* clean up test environment
*/
public function tearDown()
public function tearDown(): void
{
vfsStream::enableDotfiles();
}
Expand Down Expand Up @@ -315,4 +315,4 @@ public function recursiveDirectoryIterationWithDotsDisabled()
$pathes
);
}
}
}
6 changes: 3 additions & 3 deletions src/test/php/org/bovigo/vfs/FilenameTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions src/test/php/org/bovigo/vfs/PermissionsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @package org\bovigo\vfs
*/
namespace org\bovigo\vfs;
use PHPUnit\Framework\Error;

/**
* Test for permissions related functionality.
*
Expand All @@ -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);
Expand Down Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/php/org/bovigo/vfs/QuotaTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/php/org/bovigo/vfs/vfsStreamBlockTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -53,7 +53,7 @@ public function setUp()
/**
* clean up test environment
*/
public function tearDown()
public function tearDown(): void
{
vfsStream::enableDotfiles();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
6 changes: 3 additions & 3 deletions src/test/php/org/bovigo/vfs/vfsStreamDirectoryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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');
}

Expand Down Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/php/org/bovigo/vfs/vfsStreamExLockTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/test/php/org/bovigo/vfs/vfsStreamFileTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -37,7 +37,7 @@ public function setUp()
/**
* clean up test environment
*/
public function tearDown()
public function tearDown(): void
{
set_include_path($this->backupIncludePath);
}
Expand Down
Loading

0 comments on commit eb843bd

Please sign in to comment.