From 6ed3aeb343fe1c83af7d9a3b3c6f4e49f756ce27 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 9 Dec 2021 20:55:26 +0100 Subject: [PATCH] Remove setExpectedException wrapper --- .../Test/Autoload/ClassMapGeneratorTest.php | 6 ++++-- .../Composer/Test/Command/InitCommandTest.php | 4 ++-- tests/Composer/Test/ConfigTest.php | 6 ++---- .../Test/DependencyResolver/RuleSetTest.php | 2 +- .../Test/DependencyResolver/SolverTest.php | 6 +++--- .../Test/Downloader/DownloadManagerTest.php | 12 +++++------ .../Test/Downloader/FileDownloaderTest.php | 2 +- .../Test/Downloader/FossilDownloaderTest.php | 4 ++-- .../Test/Downloader/GitDownloaderTest.php | 4 ++-- .../Test/Downloader/HgDownloaderTest.php | 4 ++-- .../Test/Downloader/ZipDownloaderTest.php | 12 +++++++---- .../EventDispatcher/EventDispatcherTest.php | 6 +++--- .../PlatformRequirementFilterFactoryTest.php | 3 ++- tests/Composer/Test/IO/BufferIOTest.php | 3 ++- tests/Composer/Test/InstalledVersionsTest.php | 2 +- .../Installer/InstallationManagerTest.php | 2 +- .../Test/Installer/LibraryInstallerTest.php | 4 ++-- .../Installer/MetapackageInstallerTest.php | 4 ++-- tests/Composer/Test/InstallerTest.php | 5 +++-- .../Package/Archiver/ArchiveManagerTest.php | 2 +- .../Composer/Test/Package/BasePackageTest.php | 2 +- tests/Composer/Test/Package/LockerTest.php | 4 ++-- .../Test/Plugin/PluginInstallerTest.php | 4 ++-- .../StrictConfirmationQuestionTest.php | 3 ++- .../Repository/FilesystemRepositoryTest.php | 2 +- .../Repository/InstalledRepositoryTest.php | 2 +- .../Test/Repository/PathRepositoryTest.php | 2 +- .../Test/Repository/RepositoryManagerTest.php | 4 ++-- .../Repository/Vcs/GitBitbucketDriverTest.php | 6 ++---- .../Test/Repository/Vcs/SvnDriverTest.php | 3 ++- tests/Composer/Test/TestCase.php | 21 ------------------- tests/Composer/Test/Util/AuthHelperTest.php | 2 +- tests/Composer/Test/Util/BitbucketTest.php | 2 +- tests/Composer/Test/Util/ErrorHandlerTest.php | 12 +++++++---- tests/Composer/Test/Util/FilesystemTest.php | 3 ++- tests/Composer/Test/Util/GitLabTest.php | 3 ++- tests/Composer/Test/Util/GitTest.php | 2 +- .../Test/Util/Http/ProxyHelperTest.php | 2 +- .../Test/Util/Http/ProxyManagerTest.php | 2 +- .../Test/Util/RemoteFilesystemTest.php | 2 +- tests/Composer/Test/Util/SilencerTest.php | 3 ++- .../Test/Util/StreamContextFactoryTest.php | 2 +- tests/Composer/Test/Util/TarTest.php | 6 +++--- tests/Composer/Test/Util/ZipTest.php | 12 +++++++---- 44 files changed, 98 insertions(+), 101 deletions(-) diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index 5b3b114ce..b08983e2f 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -146,7 +146,8 @@ class ClassMapGeneratorTest extends TestCase $find = $r->getMethod('findClasses'); $find->setAccessible(true); - $this->setExpectedException('RuntimeException', 'does not exist'); + self::expectException('RuntimeException'); + self::expectExceptionMessage('does not exist'); $find->invoke(null, __DIR__ . '/no-file'); } @@ -232,7 +233,8 @@ class ClassMapGeneratorTest extends TestCase public function testCreateMapThrowsWhenDirectoryDoesNotExist() { - $this->setExpectedException('RuntimeException', 'Could not scan for classes inside'); + self::expectException('RuntimeException'); + self::expectExceptionMessage('Could not scan for classes inside'); ClassMapGenerator::createMap(__DIR__ . '/no-file.no-foler'); } diff --git a/tests/Composer/Test/Command/InitCommandTest.php b/tests/Composer/Test/Command/InitCommandTest.php index 8006fe106..7cb6fe94c 100644 --- a/tests/Composer/Test/Command/InitCommandTest.php +++ b/tests/Composer/Test/Command/InitCommandTest.php @@ -82,14 +82,14 @@ class InitCommandTest extends TestCase public function testParseEmptyAuthorString() { $command = new InitCommand; - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $command->parseAuthorString(''); } public function testParseAuthorStringWithInvalidEmail() { $command = new InitCommand; - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $command->parseAuthorString('John Smith '); } diff --git a/tests/Composer/Test/ConfigTest.php b/tests/Composer/Test/ConfigTest.php index 06f655721..579987a52 100644 --- a/tests/Composer/Test/ConfigTest.php +++ b/tests/Composer/Test/ConfigTest.php @@ -259,10 +259,8 @@ class ConfigTest extends TestCase */ public function testProhibitedUrlsThrowException($url) { - $this->setExpectedException( - 'Composer\Downloader\TransportException', - 'Your configuration does not allow connections to ' . $url - ); + self::expectException('Composer\Downloader\TransportException'); + self::expectExceptionMessage('Your configuration does not allow connections to ' . $url); $config = new Config(false); $config->prohibitUrlByConfig($url); } diff --git a/tests/Composer/Test/DependencyResolver/RuleSetTest.php b/tests/Composer/Test/DependencyResolver/RuleSetTest.php index 1cdd83a9b..f25e3df4f 100644 --- a/tests/Composer/Test/DependencyResolver/RuleSetTest.php +++ b/tests/Composer/Test/DependencyResolver/RuleSetTest.php @@ -67,7 +67,7 @@ class RuleSetTest extends TestCase { $ruleSet = new RuleSet; - $this->setExpectedException('OutOfBoundsException'); + self::expectException('OutOfBoundsException'); // @phpstan-ignore-next-line $ruleSet->add(new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, array('packageName' => '', 'constraint' => new MatchAllConstraint)), 7); } diff --git a/tests/Composer/Test/DependencyResolver/SolverTest.php b/tests/Composer/Test/DependencyResolver/SolverTest.php index f62d5230f..e6e51c2fb 100644 --- a/tests/Composer/Test/DependencyResolver/SolverTest.php +++ b/tests/Composer/Test/DependencyResolver/SolverTest.php @@ -537,7 +537,7 @@ class SolverTest extends TestCase $this->request->requireName('A'); // must explicitly pick the provider, so error in this case - $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); + self::expectException('Composer\DependencyResolver\SolverProblemsException'); $this->createSolver(); $this->solver->solve($this->request); } @@ -571,7 +571,7 @@ class SolverTest extends TestCase $this->request->requireName('A'); - $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); + self::expectException('Composer\DependencyResolver\SolverProblemsException'); $this->createSolver(); $this->solver->solve($this->request); } @@ -743,7 +743,7 @@ class SolverTest extends TestCase $this->request->requireName('C', $this->getVersionConstraint('==', '2.0.0.0-dev')); - $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); + self::expectException('Composer\DependencyResolver\SolverProblemsException'); $this->createSolver(); $this->solver->solve($this->request); diff --git a/tests/Composer/Test/Downloader/DownloadManagerTest.php b/tests/Composer/Test/Downloader/DownloadManagerTest.php index d2f03aa3f..345a74b76 100644 --- a/tests/Composer/Test/Downloader/DownloadManagerTest.php +++ b/tests/Composer/Test/Downloader/DownloadManagerTest.php @@ -37,7 +37,7 @@ class DownloadManagerTest extends TestCase $manager->setDownloader('test', $downloader); $this->assertSame($downloader, $manager->getDownloader('test')); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $manager->getDownloader('unregistered'); } @@ -51,7 +51,7 @@ class DownloadManagerTest extends TestCase $manager = new DownloadManager($this->io, false, $this->filesystem); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $manager->getDownloaderForPackage($package); } @@ -117,7 +117,7 @@ class DownloadManagerTest extends TestCase ->with('git') ->will($this->returnValue($downloader)); - $this->setExpectedException('LogicException'); + self::expectException('LogicException'); $manager->getDownloaderForPackage($package); } @@ -183,7 +183,7 @@ class DownloadManagerTest extends TestCase ->with('pear') ->will($this->returnValue($downloader)); - $this->setExpectedException('LogicException'); + self::expectException('LogicException'); $manager->getDownloaderForPackage($package); } @@ -304,7 +304,7 @@ class DownloadManagerTest extends TestCase $manager = new DownloadManager($this->io, false, $this->filesystem); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $manager->download($package, 'target_dir'); } @@ -536,7 +536,7 @@ class DownloadManagerTest extends TestCase $manager = new DownloadManager($this->io, false, $this->filesystem); $manager->setPreferSource(true); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $manager->download($package, 'target_dir'); } diff --git a/tests/Composer/Test/Downloader/FileDownloaderTest.php b/tests/Composer/Test/Downloader/FileDownloaderTest.php index f8e617f0b..0cd7856f6 100644 --- a/tests/Composer/Test/Downloader/FileDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FileDownloaderTest.php @@ -67,7 +67,7 @@ class FileDownloaderTest extends TestCase ->will($this->returnValue(null)) ; - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $downloader = $this->getDownloader(); $downloader->download($packageMock, '/path'); diff --git a/tests/Composer/Test/Downloader/FossilDownloaderTest.php b/tests/Composer/Test/Downloader/FossilDownloaderTest.php index db26b9d8c..da9b04c5d 100644 --- a/tests/Composer/Test/Downloader/FossilDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FossilDownloaderTest.php @@ -60,7 +60,7 @@ class FossilDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $downloader = $this->getDownloaderMock(); $downloader->install($packageMock, '/path'); @@ -95,7 +95,7 @@ class FossilDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $downloader = $this->getDownloaderMock(); $downloader->prepare('update', $sourcePackageMock, '/path', $initialPackageMock); diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index 442978080..d5494564d 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -100,7 +100,7 @@ class GitDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $downloader = $this->getDownloaderMock(); $downloader->download($packageMock, '/path'); @@ -322,7 +322,7 @@ class GitDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $downloader = $this->getDownloaderMock(); $downloader->download($sourcePackageMock, '/path', $initialPackageMock); diff --git a/tests/Composer/Test/Downloader/HgDownloaderTest.php b/tests/Composer/Test/Downloader/HgDownloaderTest.php index decf69854..dbe816bd2 100644 --- a/tests/Composer/Test/Downloader/HgDownloaderTest.php +++ b/tests/Composer/Test/Downloader/HgDownloaderTest.php @@ -60,7 +60,7 @@ class HgDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $downloader = $this->getDownloaderMock(); $downloader->install($packageMock, '/path'); @@ -94,7 +94,7 @@ class HgDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $downloader = $this->getDownloaderMock(); $downloader->prepare('update', $sourcePackageMock, '/path', $initialPackageMock); diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index bd5b06c8b..8ecb2719f 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -108,7 +108,8 @@ class ZipDownloaderTest extends TestCase public function testZipArchiveOnlyFailed() { - $this->setExpectedException('RuntimeException', 'There was an error extracting the ZIP file'); + self::expectException('RuntimeException'); + self::expectExceptionMessage('There was an error extracting the ZIP file'); if (!class_exists('ZipArchive')) { $this->markTestSkipped('zip extension missing'); } @@ -130,7 +131,8 @@ class ZipDownloaderTest extends TestCase public function testZipArchiveExtractOnlyFailed() { - $this->setExpectedException('RuntimeException', 'The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems): Not a directory'); + self::expectException('RuntimeException'); + self::expectExceptionMessage('The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems): Not a directory'); if (!class_exists('ZipArchive')) { $this->markTestSkipped('zip extension missing'); } @@ -173,7 +175,8 @@ class ZipDownloaderTest extends TestCase public function testSystemUnzipOnlyFailed() { - $this->setExpectedException('Exception', 'Failed to extract : (1) unzip'); + self::expectException('Exception'); + self::expectExceptionMessage('Failed to extract : (1) unzip'); $this->setPrivateProperty('isWindows', false); $this->setPrivateProperty('hasZipArchive', false); $this->setPrivateProperty('unzipCommands', array(array('unzip', 'unzip -qq %s -d %s'))); @@ -267,7 +270,8 @@ class ZipDownloaderTest extends TestCase public function testNonWindowsFallbackFailed() { - $this->setExpectedException('Exception', 'There was an error extracting the ZIP file'); + self::expectException('Exception'); + self::expectExceptionMessage('There was an error extracting the ZIP file'); if (!class_exists('ZipArchive')) { $this->markTestSkipped('zip extension missing'); } diff --git a/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php b/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php index fc3c3df0b..78d1fdd91 100644 --- a/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php +++ b/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php @@ -31,7 +31,7 @@ class EventDispatcherTest extends TestCase { public function testListenerExceptionsAreCaught() { - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $dispatcher = $this->getDispatcherStubForListenersTest(array( @@ -449,7 +449,7 @@ class EventDispatcherTest extends TestCase public function testDispatcherDetectInfiniteRecursion() { - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') ->setConstructorArgs(array( @@ -569,7 +569,7 @@ class EventDispatcherTest extends TestCase ->method('isInteractive') ->willReturn(1); - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false); } diff --git a/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php b/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php index 10eaa3fb3..5db37cacf 100644 --- a/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php +++ b/tests/Composer/Test/Filter/PlatformRequirementFilter/PlatformRequirementFilterFactoryTest.php @@ -32,7 +32,8 @@ final class PlatformRequirementFilterFactoryTest extends TestCase public function testFromBoolThrowsExceptionIfTypeIsUnknown() { - $this->setExpectedException('InvalidArgumentException', 'PlatformRequirementFilter: Unknown $boolOrList parameter NULL. Please report at https://github.com/composer/composer/issues/new.'); + self::expectException('InvalidArgumentException'); + self::expectExceptionMessage('PlatformRequirementFilter: Unknown $boolOrList parameter NULL. Please report at https://github.com/composer/composer/issues/new.'); PlatformRequirementFilterFactory::fromBoolOrList(null); } diff --git a/tests/Composer/Test/IO/BufferIOTest.php b/tests/Composer/Test/IO/BufferIOTest.php index 7b8bf2f41..52c11562a 100644 --- a/tests/Composer/Test/IO/BufferIOTest.php +++ b/tests/Composer/Test/IO/BufferIOTest.php @@ -27,7 +27,8 @@ class BufferIOTest extends TestCase $input = $refl->getValue($bufferIO); if (!$input instanceof StreamableInputInterface) { - $this->setExpectedException('\RuntimeException', 'Setting the user inputs requires at least the version 3.2 of the symfony/console component.'); + self::expectException('\RuntimeException'); + self::expectExceptionMessage('Setting the user inputs requires at least the version 3.2 of the symfony/console component.'); } $bufferIO->setUserInputs(array( diff --git a/tests/Composer/Test/InstalledVersionsTest.php b/tests/Composer/Test/InstalledVersionsTest.php index b0317e6c4..e5ead9f65 100644 --- a/tests/Composer/Test/InstalledVersionsTest.php +++ b/tests/Composer/Test/InstalledVersionsTest.php @@ -200,7 +200,7 @@ class InstalledVersionsTest extends TestCase public function testGetVersionOutOfBounds() { - $this->setExpectedException('OutOfBoundsException'); + self::expectException('OutOfBoundsException'); InstalledVersions::getVersion('not/installed'); } diff --git a/tests/Composer/Test/Installer/InstallationManagerTest.php b/tests/Composer/Test/Installer/InstallationManagerTest.php index ba4c07071..4fe32e989 100644 --- a/tests/Composer/Test/Installer/InstallationManagerTest.php +++ b/tests/Composer/Test/Installer/InstallationManagerTest.php @@ -59,7 +59,7 @@ class InstallationManagerTest extends TestCase $manager->addInstaller($installer); $this->assertSame($installer, $manager->getInstaller('vendor')); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $manager->getInstaller('unregistered'); } diff --git a/tests/Composer/Test/Installer/LibraryInstallerTest.php b/tests/Composer/Test/Installer/LibraryInstallerTest.php index 6d0e1f5a9..a302c0b90 100644 --- a/tests/Composer/Test/Installer/LibraryInstallerTest.php +++ b/tests/Composer/Test/Installer/LibraryInstallerTest.php @@ -223,7 +223,7 @@ class LibraryInstallerTest extends TestCase $this->assertFileExists($this->vendorDir, 'Vendor dir should be created'); $this->assertFileExists($this->binDir, 'Bin dir should be created'); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $library->update($this->repository, $initial, $target); } @@ -260,7 +260,7 @@ class LibraryInstallerTest extends TestCase $library->uninstall($this->repository, $package); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $library->uninstall($this->repository, $package); } diff --git a/tests/Composer/Test/Installer/MetapackageInstallerTest.php b/tests/Composer/Test/Installer/MetapackageInstallerTest.php index 6972519e5..e66bf28d3 100644 --- a/tests/Composer/Test/Installer/MetapackageInstallerTest.php +++ b/tests/Composer/Test/Installer/MetapackageInstallerTest.php @@ -80,7 +80,7 @@ class MetapackageInstallerTest extends TestCase $this->installer->update($this->repository, $initial, $target); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $this->installer->update($this->repository, $initial, $target); } @@ -102,7 +102,7 @@ class MetapackageInstallerTest extends TestCase $this->installer->uninstall($this->repository, $package); - $this->setExpectedException('InvalidArgumentException'); + self::expectException('InvalidArgumentException'); $this->installer->uninstall($this->repository, $package); } diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 667aa9f96..e6f4eb677 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -302,7 +302,7 @@ class InstallerTest extends TestCase * @param ?mixed[] $expectInstalled * @param ?string $expectOutput * @param string $expect - * @param int|string $expectResult + * @param int|class-string<\Throwable> $expectResult * @return void */ private function doTestIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expect, $expectResult) @@ -319,7 +319,8 @@ class InstallerTest extends TestCase // Prepare for exceptions if (!is_int($expectResult)) { $normalizedOutput = rtrim(str_replace("\n", PHP_EOL, $expect)); - $this->setExpectedException($expectResult, $normalizedOutput); + self::expectException($expectResult); + self::expectExceptionMessage($normalizedOutput); } // Create Composer mock object according to configuration diff --git a/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php b/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php index d54bb3339..9d1aff56e 100644 --- a/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php +++ b/tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php @@ -50,7 +50,7 @@ class ArchiveManagerTest extends ArchiverTest public function testUnknownFormat() { - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); $package = $this->setupPackage(); diff --git a/tests/Composer/Test/Package/BasePackageTest.php b/tests/Composer/Test/Package/BasePackageTest.php index 7ecaa5de6..3a2449bb0 100644 --- a/tests/Composer/Test/Package/BasePackageTest.php +++ b/tests/Composer/Test/Package/BasePackageTest.php @@ -35,7 +35,7 @@ class BasePackageTest extends TestCase public function testSetAnotherRepository() { - $this->setExpectedException('LogicException'); + self::expectException('LogicException'); $package = $this->getMockForAbstractClass('Composer\Package\BasePackage', array('foo')); diff --git a/tests/Composer/Test/Package/LockerTest.php b/tests/Composer/Test/Package/LockerTest.php index bf8957bbe..ea7d96750 100644 --- a/tests/Composer/Test/Package/LockerTest.php +++ b/tests/Composer/Test/Package/LockerTest.php @@ -53,7 +53,7 @@ class LockerTest extends TestCase ->method('exists') ->will($this->returnValue(false)); - $this->setExpectedException('LogicException'); + self::expectException('LogicException'); $locker->getLockedRepository(); } @@ -170,7 +170,7 @@ class LockerTest extends TestCase ->method('getPrettyName') ->will($this->returnValue('pkg1')); - $this->setExpectedException('LogicException'); + self::expectException('LogicException'); $locker->setLockData(array($package1), array(), array(), array(), array(), 'dev', array(), false, false, array()); } diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index a08f45daf..1ef0a6047 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -432,13 +432,13 @@ class PluginInstallerTest extends TestCase /** * @dataProvider invalidImplementationClassNames * @param callable $invalidImplementationClassNames - * @param string $expect + * @param class-string<\Throwable> $expect * * @return void */ public function testQueryingWithInvalidCapabilityClassNameThrows($invalidImplementationClassNames, $expect = 'UnexpectedValueException') { - $this->setExpectedException($expect); + self::expectException($expect); $capabilityApi = 'Composer\Plugin\Capability\Capability'; diff --git a/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php b/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php index 78e0b3cb0..90fbb4a86 100644 --- a/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php +++ b/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php @@ -50,7 +50,8 @@ class StrictConfirmationQuestionTest extends TestCase { list($input, $dialog) = $this->createInput($answer."\n"); - $this->setExpectedException('InvalidArgumentException', 'Please answer yes, y, no, or n.'); + self::expectException('InvalidArgumentException'); + self::expectExceptionMessage('Please answer yes, y, no, or n.'); $question = new StrictConfirmationQuestion('Do you like French fries?'); $question->setMaxAttempts(1); diff --git a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php index 91e314407..ac1d78e4d 100644 --- a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php @@ -48,7 +48,7 @@ class FilesystemRepositoryTest extends TestCase public function testCorruptedRepositoryFile() { - $this->setExpectedException('Composer\Repository\InvalidRepositoryException'); + self::expectException('Composer\Repository\InvalidRepositoryException'); $json = $this->createJsonFileMock(); $repository = new FilesystemRepository($json); diff --git a/tests/Composer/Test/Repository/InstalledRepositoryTest.php b/tests/Composer/Test/Repository/InstalledRepositoryTest.php index 7b0d767ca..136c19c7b 100644 --- a/tests/Composer/Test/Repository/InstalledRepositoryTest.php +++ b/tests/Composer/Test/Repository/InstalledRepositoryTest.php @@ -45,7 +45,7 @@ class InstalledRepositoryTest extends TestCase { $arrayRepoOne = new ArrayRepository; - $this->setExpectedException('LogicException'); + self::expectException('LogicException'); new InstalledRepository(array($arrayRepoOne)); } diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index 03b6fe103..cb1aa0e3f 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -19,7 +19,7 @@ class PathRepositoryTest extends TestCase { public function testLoadPackageFromFileSystemWithIncorrectPath() { - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') ->getMock(); diff --git a/tests/Composer/Test/Repository/RepositoryManagerTest.php b/tests/Composer/Test/Repository/RepositoryManagerTest.php index 59f23dff1..e89a36599 100644 --- a/tests/Composer/Test/Repository/RepositoryManagerTest.php +++ b/tests/Composer/Test/Repository/RepositoryManagerTest.php @@ -57,12 +57,12 @@ class RepositoryManagerTest extends TestCase * * @param string $type * @param array $options - * @param string|null $exception + * @param class-string<\Throwable>|null $exception */ public function testRepoCreation($type, $options, $exception = null) { if ($exception) { - $this->setExpectedException($exception); + self::expectException($exception); } $rm = new RepositoryManager( diff --git a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php index 50e89f52b..a8ee520f0 100644 --- a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php @@ -81,10 +81,8 @@ class GitBitbucketDriverTest extends TestCase public function testGetRootIdentifierWrongScmType() { - $this->setExpectedException( - '\RuntimeException', - 'https://bitbucket.org/user/repo.git does not appear to be a git repository, use https://bitbucket.org/user/repo but remember that Bitbucket no longer supports the mercurial repositories. https://bitbucket.org/blog/sunsetting-mercurial-support-in-bitbucket' - ); + self::expectException('RuntimeException'); + self::expectExceptionMessage('https://bitbucket.org/user/repo.git does not appear to be a git repository, use https://bitbucket.org/user/repo but remember that Bitbucket no longer supports the mercurial repositories. https://bitbucket.org/blog/sunsetting-mercurial-support-in-bitbucket'); $this->httpDownloader->expects($this->once()) ->method('get') diff --git a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php index 440d2e35a..84e3df046 100644 --- a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php @@ -49,7 +49,8 @@ class SvnDriverTest extends TestCase public function testWrongCredentialsInUrl() { - $this->setExpectedException('RuntimeException', "Repository https://till:secret@corp.svn.local/repo could not be processed, wrong credentials provided (svn: OPTIONS of 'https://corp.svn.local/repo': authorization failed: Could not authenticate to server: rejected Basic challenge (https://corp.svn.local/))"); + self::expectException('RuntimeException'); + self::expectExceptionMessage("Repository https://till:secret@corp.svn.local/repo could not be processed, wrong credentials provided (svn: OPTIONS of 'https://corp.svn.local/repo': authorization failed: Could not authenticate to server: rejected Basic challenge (https://corp.svn.local/))"); $console = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(); diff --git a/tests/Composer/Test/TestCase.php b/tests/Composer/Test/TestCase.php index 8640a946a..a815f5446 100644 --- a/tests/Composer/Test/TestCase.php +++ b/tests/Composer/Test/TestCase.php @@ -209,27 +209,6 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase } } - /** - * @param string $exception - * @param string|null $message - * @param int|null $code - * @return void - */ - public function setExpectedException($exception, $message = null, $code = null) - { - if (!class_exists('PHPUnit\Framework\Error\Notice')) { - $exception = str_replace('PHPUnit\\Framework\\Error\\', 'PHPUnit_Framework_Error_', $exception); - } - if (method_exists($this, 'expectException')) { - $this->expectException($exception); - if (null !== $message) { - $this->expectExceptionMessage($message); - } - } else { - parent::setExpectedException($exception, $message, $code); - } - } - /** * Transforms an escaped non-Windows command to match Windows escaping. * diff --git a/tests/Composer/Test/Util/AuthHelperTest.php b/tests/Composer/Test/Util/AuthHelperTest.php index 0129868eb..a65d022c1 100644 --- a/tests/Composer/Test/Util/AuthHelperTest.php +++ b/tests/Composer/Test/Util/AuthHelperTest.php @@ -475,7 +475,7 @@ class AuthHelperTest extends TestCase public function testStoreAuthWithPromptInvalidAnswer() { - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); $origin = 'github.com'; $storeAuth = 'prompt'; diff --git a/tests/Composer/Test/Util/BitbucketTest.php b/tests/Composer/Test/Util/BitbucketTest.php index 4f40f6ed2..e7fbf4eed 100644 --- a/tests/Composer/Test/Util/BitbucketTest.php +++ b/tests/Composer/Test/Util/BitbucketTest.php @@ -270,7 +270,7 @@ class BitbucketTest extends TestCase public function testRequestAccessTokenWithUsernameAndPasswordWithNotFoundResponse() { - $this->setExpectedException('Composer\Downloader\TransportException'); + self::expectException('Composer\Downloader\TransportException'); $this->config->expects($this->once()) ->method('get') ->with('bitbucket-oauth') diff --git a/tests/Composer/Test/Util/ErrorHandlerTest.php b/tests/Composer/Test/Util/ErrorHandlerTest.php index 8e082ecb4..6dc0c8ec6 100644 --- a/tests/Composer/Test/Util/ErrorHandlerTest.php +++ b/tests/Composer/Test/Util/ErrorHandlerTest.php @@ -37,9 +37,11 @@ class ErrorHandlerTest extends TestCase public function testErrorHandlerCaptureNotice() { if (PHP_VERSION_ID >= 80000) { - $this->setExpectedException('\ErrorException', 'Undefined array key "baz"'); + self::expectException('\ErrorException'); + self::expectExceptionMessage('Undefined array key "baz"'); } else { - $this->setExpectedException('\ErrorException', 'Undefined index: baz'); + self::expectException('\ErrorException'); + self::expectExceptionMessage('Undefined index: baz'); } $array = array('foo' => 'bar'); @@ -53,9 +55,11 @@ class ErrorHandlerTest extends TestCase public function testErrorHandlerCaptureWarning() { if (PHP_VERSION_ID >= 80000) { - $this->setExpectedException('TypeError', 'array_merge'); + self::expectException('TypeError'); + self::expectExceptionMessage('array_merge'); } else { - $this->setExpectedException('ErrorException', 'array_merge'); + self::expectException('ErrorException'); + self::expectExceptionMessage('array_merge'); } // @phpstan-ignore-next-line diff --git a/tests/Composer/Test/Util/FilesystemTest.php b/tests/Composer/Test/Util/FilesystemTest.php index 6123b95f7..2c7fa5657 100644 --- a/tests/Composer/Test/Util/FilesystemTest.php +++ b/tests/Composer/Test/Util/FilesystemTest.php @@ -308,7 +308,8 @@ class FilesystemTest extends TestCase if (!defined('PHP_WINDOWS_VERSION_BUILD')) { $this->assertFalse($fs->isJunction($this->workingDir)); $this->assertFalse($fs->removeJunction($this->workingDir)); - $this->setExpectedException('LogicException', 'not available on non-Windows platform'); + self::expectException('LogicException'); + self::expectExceptionMessage('not available on non-Windows platform'); } $target = $this->workingDir . '/real/../real/nesting'; diff --git a/tests/Composer/Test/Util/GitLabTest.php b/tests/Composer/Test/Util/GitLabTest.php index cd2a85dad..e7ef0b94b 100644 --- a/tests/Composer/Test/Util/GitLabTest.php +++ b/tests/Composer/Test/Util/GitLabTest.php @@ -75,7 +75,8 @@ class GitLabTest extends TestCase public function testUsernamePasswordFailure() { - $this->setExpectedException('RuntimeException', 'Invalid GitLab credentials 5 times in a row, aborting.'); + self::expectException('RuntimeException'); + self::expectExceptionMessage('Invalid GitLab credentials 5 times in a row, aborting.'); $io = $this->getIOMock(); $io ->expects($this->exactly(5)) diff --git a/tests/Composer/Test/Util/GitTest.php b/tests/Composer/Test/Util/GitTest.php index 8b7b90770..8e3928a62 100644 --- a/tests/Composer/Test/Util/GitTest.php +++ b/tests/Composer/Test/Util/GitTest.php @@ -73,7 +73,7 @@ class GitTest extends TestCase public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithoutAuthentication() { - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); $that = $this; $commandCallable = function ($url) use ($that) { diff --git a/tests/Composer/Test/Util/Http/ProxyHelperTest.php b/tests/Composer/Test/Util/Http/ProxyHelperTest.php index e8c00a827..72e1d2f6d 100644 --- a/tests/Composer/Test/Util/Http/ProxyHelperTest.php +++ b/tests/Composer/Test/Util/Http/ProxyHelperTest.php @@ -53,7 +53,7 @@ class ProxyHelperTest extends TestCase { $_SERVER['http_proxy'] = $url; - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); ProxyHelper::getProxyData(); } diff --git a/tests/Composer/Test/Util/Http/ProxyManagerTest.php b/tests/Composer/Test/Util/Http/ProxyManagerTest.php index 84365aa9b..16d926039 100644 --- a/tests/Composer/Test/Util/Http/ProxyManagerTest.php +++ b/tests/Composer/Test/Util/Http/ProxyManagerTest.php @@ -63,7 +63,7 @@ class ProxyManagerTest extends TestCase { $_SERVER['http_proxy'] = 'localhost'; $proxyManager = ProxyManager::getInstance(); - $this->setExpectedException('Composer\Downloader\TransportException'); + self::expectException('Composer\Downloader\TransportException'); $proxyManager->getProxyForRequest('http://example.com'); } diff --git a/tests/Composer/Test/Util/RemoteFilesystemTest.php b/tests/Composer/Test/Util/RemoteFilesystemTest.php index 1fd35cffd..6073e9e59 100644 --- a/tests/Composer/Test/Util/RemoteFilesystemTest.php +++ b/tests/Composer/Test/Util/RemoteFilesystemTest.php @@ -172,7 +172,7 @@ class RemoteFilesystemTest extends TestCase public function testCopyWithNoRetryOnFailure() { - $this->setExpectedException('Composer\Downloader\TransportException'); + self::expectException('Composer\Downloader\TransportException'); $fs = $this->getRemoteFilesystemWithMockedMethods(array('getRemoteContents')); $fs->expects($this->once())->method('getRemoteContents') diff --git a/tests/Composer/Test/Util/SilencerTest.php b/tests/Composer/Test/Util/SilencerTest.php index 6e93c3c22..9072a7cda 100644 --- a/tests/Composer/Test/Util/SilencerTest.php +++ b/tests/Composer/Test/Util/SilencerTest.php @@ -52,7 +52,8 @@ class SilencerTest extends TestCase public function testSilencedException() { $verification = microtime(); - $this->setExpectedException('\RuntimeException', $verification); + self::expectException('RuntimeException'); + self::expectExceptionMessage($verification); Silencer::call(function () use ($verification) { throw new \RuntimeException($verification); }); diff --git a/tests/Composer/Test/Util/StreamContextFactoryTest.php b/tests/Composer/Test/Util/StreamContextFactoryTest.php index 4a4c8b50c..ca86d16ce 100644 --- a/tests/Composer/Test/Util/StreamContextFactoryTest.php +++ b/tests/Composer/Test/Util/StreamContextFactoryTest.php @@ -157,7 +157,7 @@ class StreamContextFactoryTest extends TestCase $_SERVER['https_proxy'] = 'https://woopproxy.net'; // Pointless test replaced by ProxyHelperTest.php - $this->setExpectedException('Composer\Downloader\TransportException'); + self::expectException('Composer\Downloader\TransportException'); $context = StreamContextFactory::getContext('https://example.org', array('http' => array('method' => 'GET', 'header' => 'User-Agent: foo'))); } diff --git a/tests/Composer/Test/Util/TarTest.php b/tests/Composer/Test/Util/TarTest.php index 7079c7d43..c15470071 100644 --- a/tests/Composer/Test/Util/TarTest.php +++ b/tests/Composer/Test/Util/TarTest.php @@ -35,13 +35,13 @@ class TarTest extends TestCase public function testThrowsExceptionIfTheTarHasNoComposerJson() { - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); Tar::getComposerJson(__DIR__.'/Fixtures/Tar/nojson.tar.gz'); } public function testThrowsExceptionIfTheComposerJsonIsInASubSubfolder() { - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); Tar::getComposerJson(__DIR__.'/Fixtures/Tar/subfolders.tar.gz'); } @@ -59,7 +59,7 @@ class TarTest extends TestCase public function testMultipleTopLevelDirsIsInvalid() { - $this->setExpectedException('RuntimeException'); + self::expectException('RuntimeException'); Tar::getComposerJson(__DIR__.'/Fixtures/Tar/multiple.tar.gz'); } } diff --git a/tests/Composer/Test/Util/ZipTest.php b/tests/Composer/Test/Util/ZipTest.php index 32fff6a5c..b55208c3e 100644 --- a/tests/Composer/Test/Util/ZipTest.php +++ b/tests/Composer/Test/Util/ZipTest.php @@ -26,7 +26,8 @@ class ZipTest extends TestCase $this->markTestSkipped('The PHP zip extension is loaded.'); } - $this->setExpectedException('\RuntimeException', 'The Zip Util requires PHP\'s zip extension'); + self::expectException('RuntimeException'); + self::expectExceptionMessage('The Zip Util requires PHP\'s zip extension'); Zip::getComposerJson(''); } @@ -59,7 +60,8 @@ class ZipTest extends TestCase $this->markTestSkipped('The PHP zip extension is not loaded.'); } - $this->setExpectedException('\RuntimeException', 'No composer.json found either at the top level or within the topmost directory'); + self::expectException('RuntimeException'); + self::expectExceptionMessage('No composer.json found either at the top level or within the topmost directory'); Zip::getComposerJson(__DIR__.'/Fixtures/Zip/nojson.zip'); } @@ -70,7 +72,8 @@ class ZipTest extends TestCase $this->markTestSkipped('The PHP zip extension is not loaded.'); } - $this->setExpectedException('\RuntimeException', 'No composer.json found either at the top level or within the topmost directory'); + self::expectException('RuntimeException'); + self::expectExceptionMessage('No composer.json found either at the top level or within the topmost directory'); Zip::getComposerJson(__DIR__.'/Fixtures/Zip/subfolders.zip'); } @@ -102,7 +105,8 @@ class ZipTest extends TestCase $this->markTestSkipped('The PHP zip extension is not loaded.'); } - $this->setExpectedException('\RuntimeException', 'Archive has more than one top level directories, and no composer.json was found on the top level, so it\'s an invalid archive. Top level paths found were: folder1/,folder2/'); + self::expectException('RuntimeException'); + self::expectExceptionMessage('Archive has more than one top level directories, and no composer.json was found on the top level, so it\'s an invalid archive. Top level paths found were: folder1/,folder2/'); Zip::getComposerJson(__DIR__.'/Fixtures/Zip/multiple.zip'); }