diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a70a01cba..16dffa9a6 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -154,7 +154,7 @@ jobs: - name: "Run tests" if: "matrix.php-version != '7.3'" - run: "vendor/bin/simple-phpunit" + run: "vendor/bin/simple-phpunit --verbose" - name: "Run complete test suite on 7.3" if: "matrix.php-version == '7.3'" diff --git a/phpstan/config.neon b/phpstan/config.neon index 06d2ad838..c5d67ffeb 100644 --- a/phpstan/config.neon +++ b/phpstan/config.neon @@ -4,6 +4,7 @@ parameters: - '../tests/Composer/Test/Fixtures/*' - '../tests/Composer/Test/Autoload/Fixtures/*' - '../tests/Composer/Test/Plugin/Fixtures/*' + - '../tests/Composer/Test/PolyfillTestCase.php' ignoreErrors: # unused parameters - '~^Constructor of class Composer\\Repository\\VcsRepository has an unused parameter \$dispatcher\.$~' @@ -24,7 +25,7 @@ parameters: - '~^Unsafe usage of new static\(\)\.$~' # BC with older PHPUnit - - '~^Call to an undefined static method PHPUnit\\Framework\\TestCase::setExpectedException\(\)\.$~' + - '~^Call to an undefined static method Composer\\Test\\PolyfillTestCase::setExpectedException\(\)\.$~' paths: - ../src diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 35dcd37da..dd084ad9f 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -770,8 +770,8 @@ EOF; include $this->vendorDir.'/composer/autoload_classmap.php' ); $this->assertAutoloadFiles('classmap5', $this->vendorDir.'/composer', 'classmap'); - $this->assertNotContains('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php')); - $this->assertNotContains('$loader->setApcuPrefix(', file_get_contents($this->vendorDir.'/composer/autoload_real.php')); + $this->assertStringNotContainsString('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php')); + $this->assertStringNotContainsString('$loader->setApcuPrefix(', file_get_contents($this->vendorDir.'/composer/autoload_real.php')); } public function testClassMapAutoloadingAuthoritativeAndApcu() @@ -819,8 +819,8 @@ EOF; ); $this->assertAutoloadFiles('classmap8', $this->vendorDir.'/composer', 'classmap'); - $this->assertContains('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php')); - $this->assertContains('$loader->setApcuPrefix(', file_get_contents($this->vendorDir.'/composer/autoload_real.php')); + $this->assertStringContainsString('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php')); + $this->assertStringContainsString('$loader->setApcuPrefix(', file_get_contents($this->vendorDir.'/composer/autoload_real.php')); } public function testFilesAutoloadGeneration() @@ -1380,8 +1380,8 @@ EOF; $this->assertStringEqualsFile($vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace); $this->assertStringEqualsFile($vendorDir.'/composer/autoload_psr4.php', $expectedPsr4); $this->assertStringEqualsFile($vendorDir.'/composer/autoload_classmap.php', $expectedClassmap); - $this->assertContains("\$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php')); - $this->assertContains("\$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php')); + $this->assertStringContainsString("\$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php')); + $this->assertStringContainsString("\$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php')); } public function testUpLevelRelativePaths() @@ -1459,7 +1459,7 @@ EOF; $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace); $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_psr4.php', $expectedPsr4); $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_classmap.php', $expectedClassmap); - $this->assertContains("\$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php')); + $this->assertStringContainsString("\$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php')); } public function testEmptyPaths() @@ -1671,10 +1671,10 @@ EOF; if (null === $expectedFixture) { $this->assertFalse(file_exists($this->vendorDir . '/composer/platform_check.php')); - $this->assertNotContains("require __DIR__ . '/platform_check.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php')); + $this->assertStringNotContainsString("require __DIR__ . '/platform_check.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php')); } else { $this->assertFileContentEquals(__DIR__ . '/Fixtures/platform/' . $expectedFixture . '.php', $this->vendorDir . '/composer/platform_check.php'); - $this->assertContains("require __DIR__ . '/platform_check.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php')); + $this->assertStringContainsString("require __DIR__ . '/platform_check.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php')); } } diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index c095baa0c..00ca13712 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -120,16 +120,13 @@ class ClassMapGeneratorTest extends TestCase ), ClassMapGenerator::createMap($finder)); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage does not exist - */ public function testFindClassesThrowsWhenFileDoesNotExist() { $r = new \ReflectionClass('Composer\\Autoload\\ClassMapGenerator'); $find = $r->getMethod('findClasses'); $find->setAccessible(true); + $this->setExpectedException('RuntimeException', 'does not exist'); $find->invoke(null, __DIR__ . '/no-file'); } @@ -213,12 +210,9 @@ class ClassMapGeneratorTest extends TestCase $fs->removeDirectory($tempDir); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Could not scan for classes inside - */ public function testCreateMapThrowsWhenDirectoryDoesNotExist() { + $this->setExpectedException('RuntimeException', 'Could not scan for classes inside'); ClassMapGenerator::createMap(__DIR__ . '/no-file.no-foler'); } diff --git a/tests/Composer/Test/DependencyResolver/RuleSetTest.php b/tests/Composer/Test/DependencyResolver/RuleSetTest.php index 966044bb6..cbb41464c 100644 --- a/tests/Composer/Test/DependencyResolver/RuleSetTest.php +++ b/tests/Composer/Test/DependencyResolver/RuleSetTest.php @@ -63,13 +63,11 @@ class RuleSetTest extends TestCase $this->assertCount(1, $ruleSet->getIteratorFor(array(RuleSet::TYPE_REQUEST))); } - /** - * @expectedException \OutOfBoundsException - */ public function testAddWhenTypeIsNotRecognized() { $ruleSet = new RuleSet; + $this->setExpectedException('OutOfBoundsException'); $ruleSet->add(new GenericRule(array(), Rule::RULE_ROOT_REQUIRE, null), 7); } @@ -152,6 +150,6 @@ class RuleSetTest extends TestCase $ruleSet->add($rule, RuleSet::TYPE_REQUEST); - $this->assertContains('REQUEST : No package found to satisfy root composer.json require foo/bar', $ruleSet->getPrettyString($repositorySetMock, $requestMock, $pool)); + $this->assertStringContainsString('REQUEST : No package found to satisfy root composer.json require foo/bar', $ruleSet->getPrettyString($repositorySetMock, $requestMock, $pool)); } } diff --git a/tests/Composer/Test/Downloader/FileDownloaderTest.php b/tests/Composer/Test/Downloader/FileDownloaderTest.php index ba8f95db9..c47acf6aa 100644 --- a/tests/Composer/Test/Downloader/FileDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FileDownloaderTest.php @@ -37,9 +37,6 @@ class FileDownloaderTest extends TestCase return new FileDownloader($io, $this->config, $httpDownloader, $eventDispatcher, $cache, $filesystem); } - /** - * @expectedException \InvalidArgumentException - */ public function testDownloadForPackageWithoutDistReference() { $packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); @@ -48,6 +45,8 @@ class FileDownloaderTest extends TestCase ->will($this->returnValue(null)) ; + $this->setExpectedException('InvalidArgumentException'); + $downloader = $this->getDownloader(); $downloader->download($packageMock, '/path'); } @@ -78,7 +77,7 @@ class FileDownloaderTest extends TestCase unlink($path); } $this->assertInstanceOf('RuntimeException', $e); - $this->assertContains('exists and is not a directory', $e->getMessage()); + $this->assertStringContainsString('exists and is not a directory', $e->getMessage()); } } @@ -153,7 +152,7 @@ class FileDownloaderTest extends TestCase } $this->assertInstanceOf('UnexpectedValueException', $e, $e->getMessage()); - $this->assertContains('could not be saved to', $e->getMessage()); + $this->assertStringContainsString('could not be saved to', $e->getMessage()); } } @@ -239,7 +238,7 @@ class FileDownloaderTest extends TestCase } $this->assertInstanceOf('UnexpectedValueException', $e, $e->getMessage()); - $this->assertContains('checksum verification', $e->getMessage()); + $this->assertStringContainsString('checksum verification', $e->getMessage()); } } diff --git a/tests/Composer/Test/Downloader/FossilDownloaderTest.php b/tests/Composer/Test/Downloader/FossilDownloaderTest.php index 40ab561db..5121d8546 100644 --- a/tests/Composer/Test/Downloader/FossilDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FossilDownloaderTest.php @@ -45,9 +45,6 @@ class FossilDownloaderTest extends TestCase return new FossilDownloader($io, $config, $executor, $filesystem); } - /** - * @expectedException \InvalidArgumentException - */ public function testInstallForPackageWithoutSourceReference() { $packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); @@ -55,6 +52,8 @@ class FossilDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); + $this->setExpectedException('InvalidArgumentException'); + $downloader = $this->getDownloaderMock(); $downloader->install($packageMock, '/path'); } @@ -92,9 +91,6 @@ class FossilDownloaderTest extends TestCase $downloader->install($packageMock, 'repo'); } - /** - * @expectedException \InvalidArgumentException - */ public function testUpdateforPackageWithoutSourceReference() { $initialPackageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); @@ -103,6 +99,8 @@ class FossilDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); + $this->setExpectedException('InvalidArgumentException'); + $downloader = $this->getDownloaderMock(); $downloader->prepare('update', $sourcePackageMock, '/path', $initialPackageMock); $downloader->update($initialPackageMock, $sourcePackageMock, '/path'); diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index 97b6db9ac..c1aeda651 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -78,9 +78,6 @@ class GitDownloaderTest extends TestCase return new GitDownloader($io, $config, $executor, $filesystem); } - /** - * @expectedException \InvalidArgumentException - */ public function testDownloadForPackageWithoutSourceReference() { $packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); @@ -88,6 +85,8 @@ class GitDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); + $this->setExpectedException('InvalidArgumentException'); + $downloader = $this->getDownloaderMock(); $downloader->download($packageMock, '/path'); $downloader->prepare('install', $packageMock, '/path'); @@ -370,9 +369,6 @@ class GitDownloaderTest extends TestCase } } - /** - * @expectedException \InvalidArgumentException - */ public function testUpdateforPackageWithoutSourceReference() { $initialPackageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); @@ -381,6 +377,8 @@ class GitDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); + $this->setExpectedException('InvalidArgumentException'); + $downloader = $this->getDownloaderMock(); $downloader->download($sourcePackageMock, '/path', $initialPackageMock); $downloader->prepare('update', $sourcePackageMock, '/path', $initialPackageMock); diff --git a/tests/Composer/Test/Downloader/HgDownloaderTest.php b/tests/Composer/Test/Downloader/HgDownloaderTest.php index 0b00bd7d2..cecf78b01 100644 --- a/tests/Composer/Test/Downloader/HgDownloaderTest.php +++ b/tests/Composer/Test/Downloader/HgDownloaderTest.php @@ -45,9 +45,6 @@ class HgDownloaderTest extends TestCase return new HgDownloader($io, $config, $executor, $filesystem); } - /** - * @expectedException \InvalidArgumentException - */ public function testDownloadForPackageWithoutSourceReference() { $packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); @@ -55,6 +52,8 @@ class HgDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); + $this->setExpectedException('InvalidArgumentException'); + $downloader = $this->getDownloaderMock(); $downloader->install($packageMock, '/path'); } @@ -86,9 +85,6 @@ class HgDownloaderTest extends TestCase $downloader->install($packageMock, 'composerPath'); } - /** - * @expectedException \InvalidArgumentException - */ public function testUpdateforPackageWithoutSourceReference() { $initialPackageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); @@ -97,6 +93,8 @@ class HgDownloaderTest extends TestCase ->method('getSourceReference') ->will($this->returnValue(null)); + $this->setExpectedException('InvalidArgumentException'); + $downloader = $this->getDownloaderMock(); $downloader->prepare('update', $sourcePackageMock, '/path', $initialPackageMock); $downloader->update($initialPackageMock, $sourcePackageMock, '/path'); diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index dc0f55aec..e21078469 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -96,16 +96,13 @@ class ZipDownloaderTest extends TestCase $this->fail('Download of invalid zip files should throw an exception'); } catch (\Exception $e) { - $this->assertContains('is not a zip archive', $e->getMessage()); + $this->assertStringContainsString('is not a zip archive', $e->getMessage()); } } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage There was an error extracting the ZIP file - */ public function testZipArchiveOnlyFailed() { + $this->setExpectedException('RuntimeException', 'There was an error extracting the ZIP file'); if (!class_exists('ZipArchive')) { $this->markTestSkipped('zip extension missing'); } @@ -126,12 +123,9 @@ class ZipDownloaderTest extends TestCase $this->wait($promise); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems): Not a directory - */ 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'); if (!class_exists('ZipArchive')) { $this->markTestSkipped('zip extension missing'); } @@ -174,12 +168,9 @@ class ZipDownloaderTest extends TestCase $this->wait($promise); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Failed to extract : (1) unzip - */ public function testSystemUnzipOnlyFailed() { + $this->setExpectedException('Exception', 'Failed to extract : (1) unzip'); $this->setPrivateProperty('isWindows', false); $this->setPrivateProperty('hasSystemUnzip', true); $this->setPrivateProperty('hasZipArchive', false); @@ -272,12 +263,9 @@ class ZipDownloaderTest extends TestCase $this->wait($promise); } - /** - * @expectedException \Exception - * @expectedExceptionMessage There was an error extracting the ZIP file - */ public function testNonWindowsFallbackFailed() { + $this->setExpectedException('Exception', 'There was an error extracting the ZIP file'); if (!class_exists('ZipArchive')) { $this->markTestSkipped('zip extension missing'); } @@ -345,12 +333,9 @@ class ZipDownloaderTest extends TestCase $this->wait($promise); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Failed to execute (1) unzip - */ public function testWindowsFallbackFailed() { + $this->setExpectedException('Exception', 'Failed to execute (1) unzip'); 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 c038681da..3f8bcc7d3 100644 --- a/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php +++ b/tests/Composer/Test/EventDispatcher/EventDispatcherTest.php @@ -27,11 +27,10 @@ use Symfony\Component\Console\Output\OutputInterface; class EventDispatcherTest extends TestCase { - /** - * @expectedException RuntimeException - */ public function testListenerExceptionsAreCaught() { + $this->setExpectedException('RuntimeException'); + $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $dispatcher = $this->getDispatcherStubForListenersTest(array( 'Composer\Test\EventDispatcher\EventDispatcherTest::call', @@ -425,11 +424,10 @@ class EventDispatcherTest extends TestCase $this->assertEquals($expected, $io->getOutput()); } - /** - * @expectedException RuntimeException - */ public function testDispatcherDetectInfiniteRecursion() { + $this->setExpectedException('RuntimeException'); + $process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') ->setConstructorArgs(array( diff --git a/tests/Composer/Test/IO/NullIOTest.php b/tests/Composer/Test/IO/NullIOTest.php index d37fb2a4f..11430379b 100644 --- a/tests/Composer/Test/IO/NullIOTest.php +++ b/tests/Composer/Test/IO/NullIOTest.php @@ -42,7 +42,7 @@ class NullIOTest extends TestCase { $io = new NullIO(); - $this->assertInternalType('array', $io->getAuthentications()); + $this->assertTrue(is_array($io->getAuthentications())); $this->assertEmpty($io->getAuthentications()); $this->assertEquals(array('username' => null, 'password' => null), $io->getAuthentication('foo')); } diff --git a/tests/Composer/Test/Json/JsonFileTest.php b/tests/Composer/Test/Json/JsonFileTest.php index 7ac7d0277..8f8b6a2c2 100644 --- a/tests/Composer/Test/Json/JsonFileTest.php +++ b/tests/Composer/Test/Json/JsonFileTest.php @@ -216,7 +216,7 @@ class JsonFileTest extends TestCase $result = JsonFile::parseJson($json); $this->fail(sprintf("Parsing should have failed but didn't.\nExpected:\n\"%s\"\nFor:\n\"%s\"\nGot:\n\"%s\"", $text, $json, var_export($result, true))); } catch (ParsingException $e) { - $this->assertContains($text, $e->getMessage()); + $this->assertStringContainsString($text, $e->getMessage()); } } diff --git a/tests/Composer/Test/Package/BasePackageTest.php b/tests/Composer/Test/Package/BasePackageTest.php index 5f5f17cd1..2bbf42593 100644 --- a/tests/Composer/Test/Package/BasePackageTest.php +++ b/tests/Composer/Test/Package/BasePackageTest.php @@ -33,11 +33,10 @@ class BasePackageTest extends TestCase } } - /** - * @expectedException LogicException - */ public function testSetAnotherRepository() { + $this->setExpectedException('LogicException'); + $package = $this->getMockForAbstractClass('Composer\Package\BasePackage', array('foo')); $package->setRepository($this->getMockBuilder('Composer\Repository\RepositoryInterface')->getMock()); diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index b73907b48..ec854ce25 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -398,10 +398,11 @@ class PluginInstallerTest extends TestCase /** * @dataProvider invalidImplementationClassNames - * @expectedException \UnexpectedValueException */ - public function testQueryingWithInvalidCapabilityClassNameThrows($invalidImplementationClassNames) + public function testQueryingWithInvalidCapabilityClassNameThrows($invalidImplementationClassNames, $expect = 'UnexpectedValueException') { + $this->setExpectedException($expect); + $capabilityApi = 'Composer\Plugin\Capability\Capability'; $plugin = $this->getMockBuilder('Composer\Test\Plugin\Mock\CapablePluginInterface') @@ -434,10 +435,9 @@ class PluginInstallerTest extends TestCase /** * @dataProvider nonExistingOrInvalidImplementationClassTypes - * @expectedException \RuntimeException */ public function testQueryingWithNonExistingOrWrongCapabilityClassTypesThrows($wrongImplementationClassTypes) { - $this->testQueryingWithInvalidCapabilityClassNameThrows($wrongImplementationClassTypes); + $this->testQueryingWithInvalidCapabilityClassNameThrows($wrongImplementationClassTypes, 'RuntimeException'); } } diff --git a/tests/Composer/Test/PolyfillTestCase.php b/tests/Composer/Test/PolyfillTestCase.php new file mode 100644 index 000000000..344175ac5 --- /dev/null +++ b/tests/Composer/Test/PolyfillTestCase.php @@ -0,0 +1,762 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Test { + use PHPUnit\Framework\TestCase; + use PHPUnit\Framework\Constraint\IsEqual; + use PHPUnit\Framework\Constraint\LogicalNot; + use PHPUnit\Framework\Constraint\RegularExpression; + use PHPUnit\Framework\Constraint\StringContains; + use PHPUnit\Framework\Constraint\TraversableContains; + + if (method_exists('PHPUnit\Framework\TestCase', 'assertStringContainsString')) { + abstract class PolyfillTestCase extends TestCase {} + } else { + abstract class PolyfillTestCase extends TestCase + { + // all the functions below are form https://github.com/symfony/phpunit-bridge/blob/bd341a45ef79b30918376e8b8e2279fac6894c3b/Legacy/PolyfillAssertTrait.php + + /** + * @param string $message + * + * @return void + */ + public static function assertIsInt($actual, $message = '') + { + static::assertInternalType('int', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsNumeric($actual, $message = '') + { + static::assertInternalType('numeric', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsObject($actual, $message = '') + { + static::assertInternalType('object', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsResource($actual, $message = '') + { + static::assertInternalType('resource', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsString($actual, $message = '') + { + static::assertInternalType('string', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsScalar($actual, $message = '') + { + static::assertInternalType('scalar', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsCallable($actual, $message = '') + { + static::assertInternalType('callable', $actual, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertIsIterable($actual, $message = '') + { + static::assertInternalType('iterable', $actual, $message); + } + + /** + * @param string $needle + * @param string $haystack + * @param string $message + * + * @return void + */ + public static function assertStringContainsString($needle, $haystack, $message = '') + { + $constraint = new StringContains($needle, false); + static::assertThat($haystack, $constraint, $message); + } + + /** + * @param string $needle + * @param string $haystack + * @param string $message + * + * @return void + */ + public static function assertStringContainsStringIgnoringCase($needle, $haystack, $message = '') + { + $constraint = new StringContains($needle, true); + static::assertThat($haystack, $constraint, $message); + } + + /** + * @param string $needle + * @param string $haystack + * @param string $message + * + * @return void + */ + public static function assertStringNotContainsString($needle, $haystack, $message = '') + { + $constraint = new LogicalNot(new StringContains($needle, false)); + static::assertThat($haystack, $constraint, $message); + } + + /** + * @param string $needle + * @param string $haystack + * @param string $message + * + * @return void + */ + public static function assertStringNotContainsStringIgnoringCase($needle, $haystack, $message = '') + { + $constraint = new LogicalNot(new StringContains($needle, true)); + static::assertThat($haystack, $constraint, $message); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertFinite($actual, $message = '') + { + static::assertInternalType('float', $actual, $message); + static::assertTrue(is_finite($actual), $message ? $message : "Failed asserting that $actual is finite."); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertInfinite($actual, $message = '') + { + static::assertInternalType('float', $actual, $message); + static::assertTrue(is_infinite($actual), $message ? $message : "Failed asserting that $actual is infinite."); + } + + /** + * @param string $message + * + * @return void + */ + public static function assertNan($actual, $message = '') + { + static::assertInternalType('float', $actual, $message); + static::assertTrue(is_nan($actual), $message ? $message : "Failed asserting that $actual is nan."); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertIsReadable($filename, $message = '') + { + static::assertInternalType('string', $filename, $message); + static::assertTrue(is_readable($filename), $message ? $message : "Failed asserting that $filename is readable."); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertNotIsReadable($filename, $message = '') + { + static::assertInternalType('string', $filename, $message); + static::assertFalse(is_readable($filename), $message ? $message : "Failed asserting that $filename is not readable."); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertIsNotReadable($filename, $message = '') + { + static::assertNotIsReadable($filename, $message); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertIsWritable($filename, $message = '') + { + static::assertInternalType('string', $filename, $message); + static::assertTrue(is_writable($filename), $message ? $message : "Failed asserting that $filename is writable."); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertNotIsWritable($filename, $message = '') + { + static::assertInternalType('string', $filename, $message); + static::assertFalse(is_writable($filename), $message ? $message : "Failed asserting that $filename is not writable."); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertIsNotWritable($filename, $message = '') + { + static::assertNotIsWritable($filename, $message); + } + + /** + * @param string $directory + * @param string $message + * + * @return void + */ + public static function assertDirectoryExists($directory, $message = '') + { + static::assertInternalType('string', $directory, $message); + static::assertTrue(is_dir($directory), $message ? $message : "Failed asserting that $directory exists."); + } + + /** + * @param string $directory + * @param string $message + * + * @return void + */ + public static function assertDirectoryNotExists($directory, $message = '') + { + static::assertInternalType('string', $directory, $message); + static::assertFalse(is_dir($directory), $message ? $message : "Failed asserting that $directory does not exist."); + } + + /** + * @param string $directory + * @param string $message + * + * @return void + */ + public static function assertDirectoryDoesNotExist($directory, $message = '') + { + static::assertDirectoryNotExists($directory, $message); + } + + /** + * @param string $directory + * @param string $message + * + * @return void + */ + public static function assertDirectoryIsReadable($directory, $message = '') + { + static::assertDirectoryExists($directory, $message); + static::assertIsReadable($directory, $message); + } + + /** + * @param string $directory + * @param string $message + * + * @return void + */ + public static function assertDirectoryNotIsReadable($directory, $message = '') + { + static::assertDirectoryExists($directory, $message); + static::assertNotIsReadable($directory, $message); + } + + /** + * @param string $directory + * @param string $message + * + * @return void + */ + public static function assertDirectoryIsNotReadable($directory, $message = '') + { + static::assertDirectoryNotIsReadable($directory, $message); + } + + /** + * @param string $directory + * @param string $message + * + * @return void + */ + public static function assertDirectoryIsWritable($directory, $message = '') + { + static::assertDirectoryExists($directory, $message); + static::assertIsWritable($directory, $message); + } + + /** + * @param string $directory + * @param string $message + * + * @return void + */ + public static function assertDirectoryNotIsWritable($directory, $message = '') + { + static::assertDirectoryExists($directory, $message); + static::assertNotIsWritable($directory, $message); + } + + /** + * @param string $directory + * @param string $message + * + * @return void + */ + public static function assertDirectoryIsNotWritable($directory, $message = '') + { + static::assertDirectoryNotIsWritable($directory, $message); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertFileExists($filename, $message = '') + { + static::assertInternalType('string', $filename, $message); + static::assertTrue(file_exists($filename), $message ? $message : "Failed asserting that $filename exists."); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertFileNotExists($filename, $message = '') + { + static::assertInternalType('string', $filename, $message); + static::assertFalse(file_exists($filename), $message ? $message : "Failed asserting that $filename does not exist."); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertFileDoesNotExist($filename, $message = '') + { + static::assertFileNotExists($filename, $message); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertFileIsReadable($filename, $message = '') + { + static::assertFileExists($filename, $message); + static::assertIsReadable($filename, $message); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertFileNotIsReadable($filename, $message = '') + { + static::assertFileExists($filename, $message); + static::assertNotIsReadable($filename, $message); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertFileIsNotReadable($filename, $message = '') + { + static::assertFileNotIsReadable($filename, $message); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertFileIsWritable($filename, $message = '') + { + static::assertFileExists($filename, $message); + static::assertIsWritable($filename, $message); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertFileNotIsWritable($filename, $message = '') + { + static::assertFileExists($filename, $message); + static::assertNotIsWritable($filename, $message); + } + + /** + * @param string $filename + * @param string $message + * + * @return void + */ + public static function assertFileIsNotWritable($filename, $message = '') + { + static::assertFileNotIsWritable($filename, $message); + } + + /** + * @param string $pattern + * @param string $string + * @param string $message + * + * @return void + */ + public static function assertMatchesRegularExpression($pattern, $string, $message = '') + { + static::assertRegExp($pattern, $string, $message); + } + + /** + * @param string $pattern + * @param string $string + * @param string $message + * + * @return void + */ + public static function assertDoesNotMatchRegularExpression($pattern, $string, $message = '') + { + static::assertNotRegExp($pattern, $string, $message); + } + } + } +} + + +namespace { + foreach (array( + 'PHPUnit\Framework\Constraint\IsEqual', + 'PHPUnit\Framework\Constraint\StringContains', + 'PHPUnit\Framework\Constraint\TraversableContains', + ) as $class) { + if (!class_exists($class) && class_exists(str_replace('\\', '_', $class))) { + class_alias(str_replace('\\', '_', $class), $class); + } + } + + foreach (array( + 'PHPUnit\Framework\SelfDescribing', + ) as $interface) { + if (!interface_exists($interface) && interface_exists(str_replace('\\', '_', $interface))) { + class_alias(str_replace('\\', '_', $interface), $interface); + } + } + + if (!class_exists('PHPUnit\Framework\Constraint\Constraint')) { + class_alias('PHPUnit_Framework_Constraint', 'PHPUnit\Framework\Constraint\Constraint'); + } +} + +// all the code below taken from various PHPUnit versions to make things work on PHPUnit 4.8 / PHP 5.3 +/* + * This file is part of PHPUnit. + * + * (c) Sebastian Bergmann + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\Constraint { + use Countable; + use PHPUnit\Framework\ExpectationFailedException; + + if (!class_exists('PHPUnit\Framework\Constraint\RegularExpression')) { + /** + * Constraint that asserts that the string it is evaluated for matches + * a regular expression. + * + * Checks a given value using the Perl Compatible Regular Expression extension + * in PHP. The pattern is matched by executing preg_match(). + * + * The pattern string passed in the constructor. + */ + class RegularExpression extends Constraint + { + /** + * @var string + */ + protected $pattern; + + /** + * @param string $pattern + */ + public function __construct($pattern) + { + parent::__construct(); + $this->pattern = $pattern; + } + + /** + * Evaluates the constraint for parameter $other. Returns true if the + * constraint is met, false otherwise. + * + * @param mixed $other Value or object to evaluate. + * + * @return bool + */ + protected function matches($other) + { + return \preg_match($this->pattern, $other) > 0; + } + + /** + * Returns a string representation of the constraint. + * + * @return string + */ + public function toString() + { + return \sprintf( + 'matches PCRE pattern "%s"', + $this->pattern + ); + } + } + } + + if (!class_exists('PHPUnit\Framework\Constraint\LogicalNot')) { + /** + * Logical NOT. + */ + class LogicalNot extends Constraint + { + /** + * @var Constraint + */ + protected $constraint; + + /** + * @param Constraint $constraint + */ + public function __construct($constraint) + { + parent::__construct(); + + if (!($constraint instanceof Constraint)) { + $constraint = new IsEqual($constraint); + } + + $this->constraint = $constraint; + } + + /** + * @param string $string + * + * @return string + */ + public static function negate($string) + { + $positives = array( + 'contains ', + 'exists', + 'has ', + 'is ', + 'are ', + 'matches ', + 'starts with ', + 'ends with ', + 'reference ', + 'not not ' + ); + + $negatives = array( + 'does not contain ', + 'does not exist', + 'does not have ', + 'is not ', + 'are not ', + 'does not match ', + 'starts not with ', + 'ends not with ', + 'don\'t reference ', + 'not ' + ); + + \preg_match('/(\'[\w\W]*\')([\w\W]*)("[\w\W]*")/i', $string, $matches); + + if (\count($matches) > 0) { + $nonInput = $matches[2]; + + $negatedString = \str_replace( + $nonInput, + \str_replace( + $positives, + $negatives, + $nonInput + ), + $string + ); + } else { + $negatedString = \str_replace( + $positives, + $negatives, + $string + ); + } + + return $negatedString; + } + + /** + * Evaluates the constraint for parameter $other + * + * If $returnResult is set to false (the default), an exception is thrown + * in case of a failure. null is returned otherwise. + * + * If $returnResult is true, the result of the evaluation is returned as + * a boolean value instead: true in case of success, false in case of a + * failure. + * + * @param mixed $other Value or object to evaluate. + * @param string $description Additional information about the test + * @param bool $returnResult Whether to return a result or throw an exception + * + * @return mixed + * + * @throws ExpectationFailedException + */ + public function evaluate($other, $description = '', $returnResult = false) + { + $success = !$this->constraint->evaluate($other, $description, true); + + if ($returnResult) { + return $success; + } + + if (!$success) { + $this->fail($other, $description); + } + } + + /** + * Returns the description of the failure + * + * The beginning of failure messages is "Failed asserting that" in most + * cases. This method should return the second part of that sentence. + * + * @param mixed $other Evaluated value or object. + * + * @return string + */ + protected function failureDescription($other) + { + switch (\get_class($this->constraint)) { + case 'PHPUnit\Framework\Constraint\LogicalAnd': + case 'PHPUnit\Framework\Constraint\LogicalNot': + case 'PHPUnit\Framework\Constraint\LogicalOr': + return 'not( ' . $this->constraint->failureDescription($other) . ' )'; + + default: + return self::negate( + $this->constraint->failureDescription($other) + ); + } + } + + /** + * Returns a string representation of the constraint. + * + * @return string + */ + public function toString() + { + switch (\get_class($this->constraint)) { + case 'PHPUnit\Framework\Constraint\LogicalAnd': + case 'PHPUnit\Framework\Constraint\LogicalNot': + case 'PHPUnit\Framework\Constraint\LogicalOr': + return 'not( ' . $this->constraint->toString() . ' )'; + + default: + return self::negate( + $this->constraint->toString() + ); + } + } + + /** + * Counts the number of constraint elements. + * + * @return int + */ + public function count() + { + return \count($this->constraint); + } + } + } +} diff --git a/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php b/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php index cdd8f3e1d..1f2454599 100644 --- a/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php +++ b/tests/Composer/Test/Question/StrictConfirmationQuestionTest.php @@ -38,14 +38,14 @@ class StrictConfirmationQuestionTest extends TestCase } /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Please answer yes, y, no, or n. * @dataProvider getAskConfirmationBadData */ public function testAskConfirmationBadAnswer($answer) { list($input, $dialog) = $this->createInput($answer."\n"); + $this->setExpectedException('InvalidArgumentException', 'Please answer yes, y, no, or n.'); + $question = new StrictConfirmationQuestion('Do you like French fries?'); $question->setMaxAttempts(1); $dialog->ask($input, $this->createOutputInterface(), $question); diff --git a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php index e2959fde8..0f64f2488 100644 --- a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php @@ -43,11 +43,9 @@ class FilesystemRepositoryTest extends TestCase $this->assertSame('vendor', $packages[0]->getType()); } - /** - * @expectedException \Composer\Repository\InvalidRepositoryException - */ public function testCorruptedRepositoryFile() { + $this->setExpectedException('Composer\Repository\InvalidRepositoryException'); $json = $this->createJsonFileMock(); $repository = new FilesystemRepository($json); diff --git a/tests/Composer/Test/Repository/PathRepositoryTest.php b/tests/Composer/Test/Repository/PathRepositoryTest.php index f1c394156..30fa983f7 100644 --- a/tests/Composer/Test/Repository/PathRepositoryTest.php +++ b/tests/Composer/Test/Repository/PathRepositoryTest.php @@ -19,12 +19,9 @@ use Composer\Package\Version\VersionParser; class PathRepositoryTest extends TestCase { - - /** - * @expectedException RuntimeException - */ public function testLoadPackageFromFileSystemWithIncorrectPath() { + $this->setExpectedException('RuntimeException'); $ioInterface = $this->getMockBuilder('Composer\IO\IOInterface') ->getMock(); diff --git a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php index b43cbbc2a..41ee56ff6 100644 --- a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php @@ -40,11 +40,10 @@ class SvnDriverTest extends TestCase $fs->removeDirectory($this->home); } - /** - * @expectedException RuntimeException - */ public function testWrongCredentialsInUrl() { + $this->setExpectedException('RuntimeException'); + $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 331d41199..ab115a474 100644 --- a/tests/Composer/Test/TestCase.php +++ b/tests/Composer/Test/TestCase.php @@ -19,12 +19,11 @@ use Composer\Package\PackageInterface; use Composer\Semver\Constraint\Constraint; use Composer\Util\Filesystem; use Composer\Util\Silencer; -use PHPUnit\Framework\TestCase as BaseTestCase; use Symfony\Component\Process\ExecutableFinder; use Composer\Package\Loader\ArrayLoader; use Composer\Package\BasePackage; -abstract class TestCase extends BaseTestCase +abstract class TestCase extends PolyfillTestCase { private static $parser; private static $executableCache = array(); diff --git a/tests/Composer/Test/Util/AuthHelperTest.php b/tests/Composer/Test/Util/AuthHelperTest.php index 11e546ed1..f26ba3d31 100644 --- a/tests/Composer/Test/Util/AuthHelperTest.php +++ b/tests/Composer/Test/Util/AuthHelperTest.php @@ -472,11 +472,10 @@ class AuthHelperTest extends TestCase $this->authHelper->storeAuth($origin, $storeAuth); } - /** - * @expectedException RuntimeException - */ public function testStoreAuthWithPromptInvalidAnswer() { + $this->setExpectedException('RuntimeException'); + $origin = 'github.com'; $storeAuth = 'prompt'; $answer = 'invalid'; diff --git a/tests/Composer/Test/Util/BitbucketTest.php b/tests/Composer/Test/Util/BitbucketTest.php index 04841f65f..a52b32cab 100644 --- a/tests/Composer/Test/Util/BitbucketTest.php +++ b/tests/Composer/Test/Util/BitbucketTest.php @@ -261,11 +261,9 @@ class BitbucketTest extends TestCase $this->assertEquals('', $this->bitbucket->requestToken($this->origin, $this->username, $this->password)); } - /** - * @expectedException \Composer\Downloader\TransportException - */ public function testRequestAccessTokenWithUsernameAndPasswordWithNotFoundResponse() { + $this->setExpectedException('Composer\Downloader\TransportException'); $this->config->expects($this->once()) ->method('get') ->with('bitbucket-oauth') diff --git a/tests/Composer/Test/Util/GitLabTest.php b/tests/Composer/Test/Util/GitLabTest.php index c9ac9dbf6..7a3643bd7 100644 --- a/tests/Composer/Test/Util/GitLabTest.php +++ b/tests/Composer/Test/Util/GitLabTest.php @@ -72,12 +72,9 @@ class GitLabTest extends TestCase $this->assertTrue($gitLab->authorizeOAuthInteractively('http', $this->origin, $this->message)); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Invalid GitLab credentials 5 times in a row, aborting. - */ public function testUsernamePasswordFailure() { + $this->setExpectedException('RuntimeException', '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 d534573d6..e7f46d55a 100644 --- a/tests/Composer/Test/Util/GitTest.php +++ b/tests/Composer/Test/Util/GitTest.php @@ -62,11 +62,10 @@ class GitTest extends TestCase ); } - /** - * @expectedException \RuntimeException - */ public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithoutAuthentication() { + $this->setExpectedException('RuntimeException'); + $that = $this; $commandCallable = function ($url) use ($that) { $that->assertSame('https://github.com/acme/repo', $url); diff --git a/tests/Composer/Test/Util/IniHelperTest.php b/tests/Composer/Test/Util/IniHelperTest.php index a77c117ea..43048989a 100644 --- a/tests/Composer/Test/Util/IniHelperTest.php +++ b/tests/Composer/Test/Util/IniHelperTest.php @@ -30,7 +30,7 @@ class IniHelperTest extends TestCase ); $this->setEnv($paths); - $this->assertContains('does not exist', IniHelper::getMessage()); + $this->assertStringContainsString('does not exist', IniHelper::getMessage()); $this->assertEquals($paths, IniHelper::getAll()); } @@ -41,7 +41,7 @@ class IniHelperTest extends TestCase ); $this->setEnv($paths); - $this->assertContains('loaded.ini', IniHelper::getMessage()); + $this->assertStringContainsString('loaded.ini', IniHelper::getMessage()); } public function testWithLoadedIniAndAdditional() @@ -53,7 +53,7 @@ class IniHelperTest extends TestCase ); $this->setEnv($paths); - $this->assertContains('multiple ini files', IniHelper::getMessage()); + $this->assertStringContainsString('multiple ini files', IniHelper::getMessage()); $this->assertEquals($paths, IniHelper::getAll()); } @@ -66,7 +66,7 @@ class IniHelperTest extends TestCase ); $this->setEnv($paths); - $this->assertContains('multiple ini files', IniHelper::getMessage()); + $this->assertStringContainsString('multiple ini files', IniHelper::getMessage()); $this->assertEquals($paths, IniHelper::getAll()); } diff --git a/tests/Composer/Test/Util/RemoteFilesystemTest.php b/tests/Composer/Test/Util/RemoteFilesystemTest.php index 361dd1669..8fe685fbc 100644 --- a/tests/Composer/Test/Util/RemoteFilesystemTest.php +++ b/tests/Composer/Test/Util/RemoteFilesystemTest.php @@ -122,7 +122,7 @@ class RemoteFilesystemTest extends TestCase { $fs = new RemoteFilesystem($this->getIOInterfaceMock(), $this->getConfigMock()); $this->callCallbackGet($fs, STREAM_NOTIFY_FILE_SIZE_IS, 0, '', 0, 0, 20); - $this->assertAttributeEquals(20, 'bytesMax', $fs); + $this->assertAttributeEqualsCustom(20, 'bytesMax', $fs); } public function testCallbackGetNotifyProgress() @@ -138,7 +138,7 @@ class RemoteFilesystemTest extends TestCase $this->setAttribute($fs, 'progress', true); $this->callCallbackGet($fs, STREAM_NOTIFY_PROGRESS, 0, '', 0, 10, 20); - $this->assertAttributeEquals(50, 'lastProgress', $fs); + $this->assertAttributeEqualsCustom(50.0, 'lastProgress', $fs); } public function testCallbackGetPassesThrough404() @@ -152,7 +152,7 @@ class RemoteFilesystemTest extends TestCase { $fs = new RemoteFilesystem($this->getIOInterfaceMock(), $this->getConfigMock()); - $this->assertContains('testGetContents', $fs->getContents('http://example.org', 'file://'.__FILE__)); + $this->assertStringContainsString('testGetContents', $fs->getContents('http://example.org', 'file://'.__FILE__)); } public function testCopy() @@ -162,15 +162,13 @@ class RemoteFilesystemTest extends TestCase $file = tempnam(sys_get_temp_dir(), 'c'); $this->assertTrue($fs->copy('http://example.org', 'file://'.__FILE__, $file)); $this->assertFileExists($file); - $this->assertContains('testCopy', file_get_contents($file)); + $this->assertStringContainsString('testCopy', file_get_contents($file)); unlink($file); } - /** - * @expectedException \Composer\Downloader\TransportException - */ public function testCopyWithNoRetryOnFailure() { + $this->setExpectedException('Composer\Downloader\TransportException'); $fs = $this->getRemoteFilesystemWithMockedMethods(array('getRemoteContents')); $fs->expects($this->once())->method('getRemoteContents') @@ -240,7 +238,7 @@ class RemoteFilesystemTest extends TestCase $this->assertTrue($copyResult); $this->assertFileExists($file); - $this->assertContains('Copied', file_get_contents($file)); + $this->assertStringContainsString('Copied', file_get_contents($file)); unlink($file); } @@ -394,6 +392,13 @@ class RemoteFilesystemTest extends TestCase $attr->setValue($object, $value); } + private function assertAttributeEqualsCustom($value, $attribute, $object) + { + $attr = new ReflectionProperty($object, $attribute); + $attr->setAccessible(true); + $this->assertSame($value, $attr->getValue($object)); + } + /** * @return MockObject|IOInterface */ diff --git a/tests/Composer/Test/Util/TarTest.php b/tests/Composer/Test/Util/TarTest.php index b14d0c0f9..7079c7d43 100644 --- a/tests/Composer/Test/Util/TarTest.php +++ b/tests/Composer/Test/Util/TarTest.php @@ -33,19 +33,15 @@ class TarTest extends TestCase $this->assertNull($result); } - /** - * @expectedException \RuntimeException - */ public function testThrowsExceptionIfTheTarHasNoComposerJson() { + $this->setExpectedException('RuntimeException'); Tar::getComposerJson(__DIR__.'/Fixtures/Tar/nojson.tar.gz'); } - /** - * @expectedException \RuntimeException - */ public function testThrowsExceptionIfTheComposerJsonIsInASubSubfolder() { + $this->setExpectedException('RuntimeException'); Tar::getComposerJson(__DIR__.'/Fixtures/Tar/subfolders.tar.gz'); } @@ -61,11 +57,9 @@ class TarTest extends TestCase $this->assertEquals("{\n \"name\": \"foo/bar\"\n}\n", $result); } - /** - * @expectedException \RuntimeException - */ public function testMultipleTopLevelDirsIsInvalid() { + $this->setExpectedException('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 ba61e8bf6..282c9b27c 100644 --- a/tests/Composer/Test/Util/ZipTest.php +++ b/tests/Composer/Test/Util/ZipTest.php @@ -55,9 +55,6 @@ class ZipTest extends TestCase $this->assertNull($result); } - /** - * @expectedException \RuntimeException - */ public function testThrowsExceptionIfTheZipHasNoComposerJson() { if (!extension_loaded('zip')) { @@ -65,12 +62,11 @@ class ZipTest extends TestCase return; } + $this->setExpectedException('\RuntimeException', 'No composer.json found either at the top level or within the topmost directory'); + Zip::getComposerJson(__DIR__.'/Fixtures/Zip/nojson.zip'); } - /** - * @expectedException \RuntimeException - */ public function testThrowsExceptionIfTheComposerJsonIsInASubSubfolder() { if (!extension_loaded('zip')) { @@ -78,6 +74,8 @@ class ZipTest extends TestCase return; } + $this->setExpectedException('\RuntimeException', 'No composer.json found either at the top level or within the topmost directory'); + Zip::getComposerJson(__DIR__.'/Fixtures/Zip/subfolders.zip'); } @@ -104,9 +102,6 @@ class ZipTest extends TestCase $this->assertEquals("{\n \"name\": \"foo/bar\"\n}\n", $result); } - /** - * @expectedException \RuntimeException - */ public function testMultipleTopLevelDirsIsInvalid() { if (!extension_loaded('zip')) { @@ -114,6 +109,8 @@ class ZipTest extends TestCase return; } + $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/'); + Zip::getComposerJson(__DIR__.'/Fixtures/Zip/multiple.zip'); } @@ -129,9 +126,6 @@ class ZipTest extends TestCase $this->assertEquals("{\n \"name\": \"foo/bar\"\n}\n", $result); } - /** - * @expectedException \RuntimeException - */ public function testThrowsExceptionIfMultipleComposerInSubFoldersWereFound() { if (!extension_loaded('zip')) { @@ -139,6 +133,8 @@ class ZipTest extends TestCase return; } + $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: foo3/,__MACOSX/'); + Zip::getComposerJson(__DIR__.'/Fixtures/Zip/multiple_subfolders.zip'); } }