1
0
Fork 0

Remove setExpectedException wrapper

pull/10343/head
Jordi Boggiano 2021-12-09 20:55:26 +01:00
parent 32dcb93f24
commit 6ed3aeb343
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
44 changed files with 98 additions and 101 deletions

View File

@ -146,7 +146,8 @@ class ClassMapGeneratorTest extends TestCase
$find = $r->getMethod('findClasses'); $find = $r->getMethod('findClasses');
$find->setAccessible(true); $find->setAccessible(true);
$this->setExpectedException('RuntimeException', 'does not exist'); self::expectException('RuntimeException');
self::expectExceptionMessage('does not exist');
$find->invoke(null, __DIR__ . '/no-file'); $find->invoke(null, __DIR__ . '/no-file');
} }
@ -232,7 +233,8 @@ class ClassMapGeneratorTest extends TestCase
public function testCreateMapThrowsWhenDirectoryDoesNotExist() 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'); ClassMapGenerator::createMap(__DIR__ . '/no-file.no-foler');
} }

View File

@ -82,14 +82,14 @@ class InitCommandTest extends TestCase
public function testParseEmptyAuthorString() public function testParseEmptyAuthorString()
{ {
$command = new InitCommand; $command = new InitCommand;
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$command->parseAuthorString(''); $command->parseAuthorString('');
} }
public function testParseAuthorStringWithInvalidEmail() public function testParseAuthorStringWithInvalidEmail()
{ {
$command = new InitCommand; $command = new InitCommand;
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$command->parseAuthorString('John Smith <john>'); $command->parseAuthorString('John Smith <john>');
} }

View File

@ -259,10 +259,8 @@ class ConfigTest extends TestCase
*/ */
public function testProhibitedUrlsThrowException($url) public function testProhibitedUrlsThrowException($url)
{ {
$this->setExpectedException( self::expectException('Composer\Downloader\TransportException');
'Composer\Downloader\TransportException', self::expectExceptionMessage('Your configuration does not allow connections to ' . $url);
'Your configuration does not allow connections to ' . $url
);
$config = new Config(false); $config = new Config(false);
$config->prohibitUrlByConfig($url); $config->prohibitUrlByConfig($url);
} }

View File

@ -67,7 +67,7 @@ class RuleSetTest extends TestCase
{ {
$ruleSet = new RuleSet; $ruleSet = new RuleSet;
$this->setExpectedException('OutOfBoundsException'); self::expectException('OutOfBoundsException');
// @phpstan-ignore-next-line // @phpstan-ignore-next-line
$ruleSet->add(new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, array('packageName' => '', 'constraint' => new MatchAllConstraint)), 7); $ruleSet->add(new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, array('packageName' => '', 'constraint' => new MatchAllConstraint)), 7);
} }

View File

@ -537,7 +537,7 @@ class SolverTest extends TestCase
$this->request->requireName('A'); $this->request->requireName('A');
// must explicitly pick the provider, so error in this case // must explicitly pick the provider, so error in this case
$this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); self::expectException('Composer\DependencyResolver\SolverProblemsException');
$this->createSolver(); $this->createSolver();
$this->solver->solve($this->request); $this->solver->solve($this->request);
} }
@ -571,7 +571,7 @@ class SolverTest extends TestCase
$this->request->requireName('A'); $this->request->requireName('A');
$this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); self::expectException('Composer\DependencyResolver\SolverProblemsException');
$this->createSolver(); $this->createSolver();
$this->solver->solve($this->request); $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->request->requireName('C', $this->getVersionConstraint('==', '2.0.0.0-dev'));
$this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); self::expectException('Composer\DependencyResolver\SolverProblemsException');
$this->createSolver(); $this->createSolver();
$this->solver->solve($this->request); $this->solver->solve($this->request);

View File

@ -37,7 +37,7 @@ class DownloadManagerTest extends TestCase
$manager->setDownloader('test', $downloader); $manager->setDownloader('test', $downloader);
$this->assertSame($downloader, $manager->getDownloader('test')); $this->assertSame($downloader, $manager->getDownloader('test'));
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$manager->getDownloader('unregistered'); $manager->getDownloader('unregistered');
} }
@ -51,7 +51,7 @@ class DownloadManagerTest extends TestCase
$manager = new DownloadManager($this->io, false, $this->filesystem); $manager = new DownloadManager($this->io, false, $this->filesystem);
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$manager->getDownloaderForPackage($package); $manager->getDownloaderForPackage($package);
} }
@ -117,7 +117,7 @@ class DownloadManagerTest extends TestCase
->with('git') ->with('git')
->will($this->returnValue($downloader)); ->will($this->returnValue($downloader));
$this->setExpectedException('LogicException'); self::expectException('LogicException');
$manager->getDownloaderForPackage($package); $manager->getDownloaderForPackage($package);
} }
@ -183,7 +183,7 @@ class DownloadManagerTest extends TestCase
->with('pear') ->with('pear')
->will($this->returnValue($downloader)); ->will($this->returnValue($downloader));
$this->setExpectedException('LogicException'); self::expectException('LogicException');
$manager->getDownloaderForPackage($package); $manager->getDownloaderForPackage($package);
} }
@ -304,7 +304,7 @@ class DownloadManagerTest extends TestCase
$manager = new DownloadManager($this->io, false, $this->filesystem); $manager = new DownloadManager($this->io, false, $this->filesystem);
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$manager->download($package, 'target_dir'); $manager->download($package, 'target_dir');
} }
@ -536,7 +536,7 @@ class DownloadManagerTest extends TestCase
$manager = new DownloadManager($this->io, false, $this->filesystem); $manager = new DownloadManager($this->io, false, $this->filesystem);
$manager->setPreferSource(true); $manager->setPreferSource(true);
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$manager->download($package, 'target_dir'); $manager->download($package, 'target_dir');
} }

View File

@ -67,7 +67,7 @@ class FileDownloaderTest extends TestCase
->will($this->returnValue(null)) ->will($this->returnValue(null))
; ;
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$downloader = $this->getDownloader(); $downloader = $this->getDownloader();
$downloader->download($packageMock, '/path'); $downloader->download($packageMock, '/path');

View File

@ -60,7 +60,7 @@ class FossilDownloaderTest extends TestCase
->method('getSourceReference') ->method('getSourceReference')
->will($this->returnValue(null)); ->will($this->returnValue(null));
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$downloader = $this->getDownloaderMock(); $downloader = $this->getDownloaderMock();
$downloader->install($packageMock, '/path'); $downloader->install($packageMock, '/path');
@ -95,7 +95,7 @@ class FossilDownloaderTest extends TestCase
->method('getSourceReference') ->method('getSourceReference')
->will($this->returnValue(null)); ->will($this->returnValue(null));
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$downloader = $this->getDownloaderMock(); $downloader = $this->getDownloaderMock();
$downloader->prepare('update', $sourcePackageMock, '/path', $initialPackageMock); $downloader->prepare('update', $sourcePackageMock, '/path', $initialPackageMock);

View File

@ -100,7 +100,7 @@ class GitDownloaderTest extends TestCase
->method('getSourceReference') ->method('getSourceReference')
->will($this->returnValue(null)); ->will($this->returnValue(null));
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$downloader = $this->getDownloaderMock(); $downloader = $this->getDownloaderMock();
$downloader->download($packageMock, '/path'); $downloader->download($packageMock, '/path');
@ -322,7 +322,7 @@ class GitDownloaderTest extends TestCase
->method('getSourceReference') ->method('getSourceReference')
->will($this->returnValue(null)); ->will($this->returnValue(null));
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$downloader = $this->getDownloaderMock(); $downloader = $this->getDownloaderMock();
$downloader->download($sourcePackageMock, '/path', $initialPackageMock); $downloader->download($sourcePackageMock, '/path', $initialPackageMock);

View File

@ -60,7 +60,7 @@ class HgDownloaderTest extends TestCase
->method('getSourceReference') ->method('getSourceReference')
->will($this->returnValue(null)); ->will($this->returnValue(null));
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$downloader = $this->getDownloaderMock(); $downloader = $this->getDownloaderMock();
$downloader->install($packageMock, '/path'); $downloader->install($packageMock, '/path');
@ -94,7 +94,7 @@ class HgDownloaderTest extends TestCase
->method('getSourceReference') ->method('getSourceReference')
->will($this->returnValue(null)); ->will($this->returnValue(null));
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$downloader = $this->getDownloaderMock(); $downloader = $this->getDownloaderMock();
$downloader->prepare('update', $sourcePackageMock, '/path', $initialPackageMock); $downloader->prepare('update', $sourcePackageMock, '/path', $initialPackageMock);

View File

@ -108,7 +108,8 @@ class ZipDownloaderTest extends TestCase
public function testZipArchiveOnlyFailed() 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')) { if (!class_exists('ZipArchive')) {
$this->markTestSkipped('zip extension missing'); $this->markTestSkipped('zip extension missing');
} }
@ -130,7 +131,8 @@ class ZipDownloaderTest extends TestCase
public function testZipArchiveExtractOnlyFailed() 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')) { if (!class_exists('ZipArchive')) {
$this->markTestSkipped('zip extension missing'); $this->markTestSkipped('zip extension missing');
} }
@ -173,7 +175,8 @@ class ZipDownloaderTest extends TestCase
public function testSystemUnzipOnlyFailed() 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('isWindows', false);
$this->setPrivateProperty('hasZipArchive', false); $this->setPrivateProperty('hasZipArchive', false);
$this->setPrivateProperty('unzipCommands', array(array('unzip', 'unzip -qq %s -d %s'))); $this->setPrivateProperty('unzipCommands', array(array('unzip', 'unzip -qq %s -d %s')));
@ -267,7 +270,8 @@ class ZipDownloaderTest extends TestCase
public function testNonWindowsFallbackFailed() 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')) { if (!class_exists('ZipArchive')) {
$this->markTestSkipped('zip extension missing'); $this->markTestSkipped('zip extension missing');
} }

View File

@ -31,7 +31,7 @@ class EventDispatcherTest extends TestCase
{ {
public function testListenerExceptionsAreCaught() public function testListenerExceptionsAreCaught()
{ {
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$dispatcher = $this->getDispatcherStubForListenersTest(array( $dispatcher = $this->getDispatcherStubForListenersTest(array(
@ -449,7 +449,7 @@ class EventDispatcherTest extends TestCase
public function testDispatcherDetectInfiniteRecursion() public function testDispatcherDetectInfiniteRecursion()
{ {
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs(array( ->setConstructorArgs(array(
@ -569,7 +569,7 @@ class EventDispatcherTest extends TestCase
->method('isInteractive') ->method('isInteractive')
->willReturn(1); ->willReturn(1);
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
$dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false); $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false);
} }

View File

@ -32,7 +32,8 @@ final class PlatformRequirementFilterFactoryTest extends TestCase
public function testFromBoolThrowsExceptionIfTypeIsUnknown() 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); PlatformRequirementFilterFactory::fromBoolOrList(null);
} }

View File

@ -27,7 +27,8 @@ class BufferIOTest extends TestCase
$input = $refl->getValue($bufferIO); $input = $refl->getValue($bufferIO);
if (!$input instanceof StreamableInputInterface) { 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( $bufferIO->setUserInputs(array(

View File

@ -200,7 +200,7 @@ class InstalledVersionsTest extends TestCase
public function testGetVersionOutOfBounds() public function testGetVersionOutOfBounds()
{ {
$this->setExpectedException('OutOfBoundsException'); self::expectException('OutOfBoundsException');
InstalledVersions::getVersion('not/installed'); InstalledVersions::getVersion('not/installed');
} }

View File

@ -59,7 +59,7 @@ class InstallationManagerTest extends TestCase
$manager->addInstaller($installer); $manager->addInstaller($installer);
$this->assertSame($installer, $manager->getInstaller('vendor')); $this->assertSame($installer, $manager->getInstaller('vendor'));
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$manager->getInstaller('unregistered'); $manager->getInstaller('unregistered');
} }

View File

@ -223,7 +223,7 @@ class LibraryInstallerTest extends TestCase
$this->assertFileExists($this->vendorDir, 'Vendor dir should be created'); $this->assertFileExists($this->vendorDir, 'Vendor dir should be created');
$this->assertFileExists($this->binDir, 'Bin 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); $library->update($this->repository, $initial, $target);
} }
@ -260,7 +260,7 @@ class LibraryInstallerTest extends TestCase
$library->uninstall($this->repository, $package); $library->uninstall($this->repository, $package);
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$library->uninstall($this->repository, $package); $library->uninstall($this->repository, $package);
} }

View File

@ -80,7 +80,7 @@ class MetapackageInstallerTest extends TestCase
$this->installer->update($this->repository, $initial, $target); $this->installer->update($this->repository, $initial, $target);
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$this->installer->update($this->repository, $initial, $target); $this->installer->update($this->repository, $initial, $target);
} }
@ -102,7 +102,7 @@ class MetapackageInstallerTest extends TestCase
$this->installer->uninstall($this->repository, $package); $this->installer->uninstall($this->repository, $package);
$this->setExpectedException('InvalidArgumentException'); self::expectException('InvalidArgumentException');
$this->installer->uninstall($this->repository, $package); $this->installer->uninstall($this->repository, $package);
} }

View File

@ -302,7 +302,7 @@ class InstallerTest extends TestCase
* @param ?mixed[] $expectInstalled * @param ?mixed[] $expectInstalled
* @param ?string $expectOutput * @param ?string $expectOutput
* @param string $expect * @param string $expect
* @param int|string $expectResult * @param int|class-string<\Throwable> $expectResult
* @return void * @return void
*/ */
private function doTestIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expect, $expectResult) 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 // Prepare for exceptions
if (!is_int($expectResult)) { if (!is_int($expectResult)) {
$normalizedOutput = rtrim(str_replace("\n", PHP_EOL, $expect)); $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 // Create Composer mock object according to configuration

View File

@ -50,7 +50,7 @@ class ArchiveManagerTest extends ArchiverTest
public function testUnknownFormat() public function testUnknownFormat()
{ {
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
$package = $this->setupPackage(); $package = $this->setupPackage();

View File

@ -35,7 +35,7 @@ class BasePackageTest extends TestCase
public function testSetAnotherRepository() public function testSetAnotherRepository()
{ {
$this->setExpectedException('LogicException'); self::expectException('LogicException');
$package = $this->getMockForAbstractClass('Composer\Package\BasePackage', array('foo')); $package = $this->getMockForAbstractClass('Composer\Package\BasePackage', array('foo'));

View File

@ -53,7 +53,7 @@ class LockerTest extends TestCase
->method('exists') ->method('exists')
->will($this->returnValue(false)); ->will($this->returnValue(false));
$this->setExpectedException('LogicException'); self::expectException('LogicException');
$locker->getLockedRepository(); $locker->getLockedRepository();
} }
@ -170,7 +170,7 @@ class LockerTest extends TestCase
->method('getPrettyName') ->method('getPrettyName')
->will($this->returnValue('pkg1')); ->will($this->returnValue('pkg1'));
$this->setExpectedException('LogicException'); self::expectException('LogicException');
$locker->setLockData(array($package1), array(), array(), array(), array(), 'dev', array(), false, false, array()); $locker->setLockData(array($package1), array(), array(), array(), array(), 'dev', array(), false, false, array());
} }

View File

@ -432,13 +432,13 @@ class PluginInstallerTest extends TestCase
/** /**
* @dataProvider invalidImplementationClassNames * @dataProvider invalidImplementationClassNames
* @param callable $invalidImplementationClassNames * @param callable $invalidImplementationClassNames
* @param string $expect * @param class-string<\Throwable> $expect
* *
* @return void * @return void
*/ */
public function testQueryingWithInvalidCapabilityClassNameThrows($invalidImplementationClassNames, $expect = 'UnexpectedValueException') public function testQueryingWithInvalidCapabilityClassNameThrows($invalidImplementationClassNames, $expect = 'UnexpectedValueException')
{ {
$this->setExpectedException($expect); self::expectException($expect);
$capabilityApi = 'Composer\Plugin\Capability\Capability'; $capabilityApi = 'Composer\Plugin\Capability\Capability';

View File

@ -50,7 +50,8 @@ class StrictConfirmationQuestionTest extends TestCase
{ {
list($input, $dialog) = $this->createInput($answer."\n"); 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 = new StrictConfirmationQuestion('Do you like French fries?');
$question->setMaxAttempts(1); $question->setMaxAttempts(1);

View File

@ -48,7 +48,7 @@ class FilesystemRepositoryTest extends TestCase
public function testCorruptedRepositoryFile() public function testCorruptedRepositoryFile()
{ {
$this->setExpectedException('Composer\Repository\InvalidRepositoryException'); self::expectException('Composer\Repository\InvalidRepositoryException');
$json = $this->createJsonFileMock(); $json = $this->createJsonFileMock();
$repository = new FilesystemRepository($json); $repository = new FilesystemRepository($json);

View File

@ -45,7 +45,7 @@ class InstalledRepositoryTest extends TestCase
{ {
$arrayRepoOne = new ArrayRepository; $arrayRepoOne = new ArrayRepository;
$this->setExpectedException('LogicException'); self::expectException('LogicException');
new InstalledRepository(array($arrayRepoOne)); new InstalledRepository(array($arrayRepoOne));
} }

View File

@ -19,7 +19,7 @@ class PathRepositoryTest extends TestCase
{ {
public function testLoadPackageFromFileSystemWithIncorrectPath() public function testLoadPackageFromFileSystemWithIncorrectPath()
{ {
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
->getMock(); ->getMock();

View File

@ -57,12 +57,12 @@ class RepositoryManagerTest extends TestCase
* *
* @param string $type * @param string $type
* @param array<string, mixed> $options * @param array<string, mixed> $options
* @param string|null $exception * @param class-string<\Throwable>|null $exception
*/ */
public function testRepoCreation($type, $options, $exception = null) public function testRepoCreation($type, $options, $exception = null)
{ {
if ($exception) { if ($exception) {
$this->setExpectedException($exception); self::expectException($exception);
} }
$rm = new RepositoryManager( $rm = new RepositoryManager(

View File

@ -81,10 +81,8 @@ class GitBitbucketDriverTest extends TestCase
public function testGetRootIdentifierWrongScmType() public function testGetRootIdentifierWrongScmType()
{ {
$this->setExpectedException( self::expectException('RuntimeException');
'\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');
'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()) $this->httpDownloader->expects($this->once())
->method('get') ->method('get')

View File

@ -49,7 +49,8 @@ class SvnDriverTest extends TestCase
public function testWrongCredentialsInUrl() 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(); $console = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(); $httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock();

View File

@ -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. * Transforms an escaped non-Windows command to match Windows escaping.
* *

View File

@ -475,7 +475,7 @@ class AuthHelperTest extends TestCase
public function testStoreAuthWithPromptInvalidAnswer() public function testStoreAuthWithPromptInvalidAnswer()
{ {
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
$origin = 'github.com'; $origin = 'github.com';
$storeAuth = 'prompt'; $storeAuth = 'prompt';

View File

@ -270,7 +270,7 @@ class BitbucketTest extends TestCase
public function testRequestAccessTokenWithUsernameAndPasswordWithNotFoundResponse() public function testRequestAccessTokenWithUsernameAndPasswordWithNotFoundResponse()
{ {
$this->setExpectedException('Composer\Downloader\TransportException'); self::expectException('Composer\Downloader\TransportException');
$this->config->expects($this->once()) $this->config->expects($this->once())
->method('get') ->method('get')
->with('bitbucket-oauth') ->with('bitbucket-oauth')

View File

@ -37,9 +37,11 @@ class ErrorHandlerTest extends TestCase
public function testErrorHandlerCaptureNotice() public function testErrorHandlerCaptureNotice()
{ {
if (PHP_VERSION_ID >= 80000) { if (PHP_VERSION_ID >= 80000) {
$this->setExpectedException('\ErrorException', 'Undefined array key "baz"'); self::expectException('\ErrorException');
self::expectExceptionMessage('Undefined array key "baz"');
} else { } else {
$this->setExpectedException('\ErrorException', 'Undefined index: baz'); self::expectException('\ErrorException');
self::expectExceptionMessage('Undefined index: baz');
} }
$array = array('foo' => 'bar'); $array = array('foo' => 'bar');
@ -53,9 +55,11 @@ class ErrorHandlerTest extends TestCase
public function testErrorHandlerCaptureWarning() public function testErrorHandlerCaptureWarning()
{ {
if (PHP_VERSION_ID >= 80000) { if (PHP_VERSION_ID >= 80000) {
$this->setExpectedException('TypeError', 'array_merge'); self::expectException('TypeError');
self::expectExceptionMessage('array_merge');
} else { } else {
$this->setExpectedException('ErrorException', 'array_merge'); self::expectException('ErrorException');
self::expectExceptionMessage('array_merge');
} }
// @phpstan-ignore-next-line // @phpstan-ignore-next-line

View File

@ -308,7 +308,8 @@ class FilesystemTest extends TestCase
if (!defined('PHP_WINDOWS_VERSION_BUILD')) { if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->assertFalse($fs->isJunction($this->workingDir)); $this->assertFalse($fs->isJunction($this->workingDir));
$this->assertFalse($fs->removeJunction($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'; $target = $this->workingDir . '/real/../real/nesting';

View File

@ -75,7 +75,8 @@ class GitLabTest extends TestCase
public function testUsernamePasswordFailure() 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 = $this->getIOMock();
$io $io
->expects($this->exactly(5)) ->expects($this->exactly(5))

View File

@ -73,7 +73,7 @@ class GitTest extends TestCase
public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithoutAuthentication() public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithoutAuthentication()
{ {
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
$that = $this; $that = $this;
$commandCallable = function ($url) use ($that) { $commandCallable = function ($url) use ($that) {

View File

@ -53,7 +53,7 @@ class ProxyHelperTest extends TestCase
{ {
$_SERVER['http_proxy'] = $url; $_SERVER['http_proxy'] = $url;
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
ProxyHelper::getProxyData(); ProxyHelper::getProxyData();
} }

View File

@ -63,7 +63,7 @@ class ProxyManagerTest extends TestCase
{ {
$_SERVER['http_proxy'] = 'localhost'; $_SERVER['http_proxy'] = 'localhost';
$proxyManager = ProxyManager::getInstance(); $proxyManager = ProxyManager::getInstance();
$this->setExpectedException('Composer\Downloader\TransportException'); self::expectException('Composer\Downloader\TransportException');
$proxyManager->getProxyForRequest('http://example.com'); $proxyManager->getProxyForRequest('http://example.com');
} }

View File

@ -172,7 +172,7 @@ class RemoteFilesystemTest extends TestCase
public function testCopyWithNoRetryOnFailure() public function testCopyWithNoRetryOnFailure()
{ {
$this->setExpectedException('Composer\Downloader\TransportException'); self::expectException('Composer\Downloader\TransportException');
$fs = $this->getRemoteFilesystemWithMockedMethods(array('getRemoteContents')); $fs = $this->getRemoteFilesystemWithMockedMethods(array('getRemoteContents'));
$fs->expects($this->once())->method('getRemoteContents') $fs->expects($this->once())->method('getRemoteContents')

View File

@ -52,7 +52,8 @@ class SilencerTest extends TestCase
public function testSilencedException() public function testSilencedException()
{ {
$verification = microtime(); $verification = microtime();
$this->setExpectedException('\RuntimeException', $verification); self::expectException('RuntimeException');
self::expectExceptionMessage($verification);
Silencer::call(function () use ($verification) { Silencer::call(function () use ($verification) {
throw new \RuntimeException($verification); throw new \RuntimeException($verification);
}); });

View File

@ -157,7 +157,7 @@ class StreamContextFactoryTest extends TestCase
$_SERVER['https_proxy'] = 'https://woopproxy.net'; $_SERVER['https_proxy'] = 'https://woopproxy.net';
// Pointless test replaced by ProxyHelperTest.php // 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'))); $context = StreamContextFactory::getContext('https://example.org', array('http' => array('method' => 'GET', 'header' => 'User-Agent: foo')));
} }

View File

@ -35,13 +35,13 @@ class TarTest extends TestCase
public function testThrowsExceptionIfTheTarHasNoComposerJson() public function testThrowsExceptionIfTheTarHasNoComposerJson()
{ {
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
Tar::getComposerJson(__DIR__.'/Fixtures/Tar/nojson.tar.gz'); Tar::getComposerJson(__DIR__.'/Fixtures/Tar/nojson.tar.gz');
} }
public function testThrowsExceptionIfTheComposerJsonIsInASubSubfolder() public function testThrowsExceptionIfTheComposerJsonIsInASubSubfolder()
{ {
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
Tar::getComposerJson(__DIR__.'/Fixtures/Tar/subfolders.tar.gz'); Tar::getComposerJson(__DIR__.'/Fixtures/Tar/subfolders.tar.gz');
} }
@ -59,7 +59,7 @@ class TarTest extends TestCase
public function testMultipleTopLevelDirsIsInvalid() public function testMultipleTopLevelDirsIsInvalid()
{ {
$this->setExpectedException('RuntimeException'); self::expectException('RuntimeException');
Tar::getComposerJson(__DIR__.'/Fixtures/Tar/multiple.tar.gz'); Tar::getComposerJson(__DIR__.'/Fixtures/Tar/multiple.tar.gz');
} }
} }

View File

@ -26,7 +26,8 @@ class ZipTest extends TestCase
$this->markTestSkipped('The PHP zip extension is loaded.'); $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(''); Zip::getComposerJson('');
} }
@ -59,7 +60,8 @@ class ZipTest extends TestCase
$this->markTestSkipped('The PHP zip extension is not loaded.'); $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'); 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->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'); 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->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'); Zip::getComposerJson(__DIR__.'/Fixtures/Zip/multiple.zip');
} }