From 9ac47008bc76691ccd7ef2607bfd6ff8867788cf Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 23 Apr 2016 16:55:51 +0200 Subject: [PATCH 1/5] Test that validates the presence of composer/composer#5237 --- test/PackageVersionsTest/InstallerTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/PackageVersionsTest/InstallerTest.php b/test/PackageVersionsTest/InstallerTest.php index bb42c9f..32802b7 100644 --- a/test/PackageVersionsTest/InstallerTest.php +++ b/test/PackageVersionsTest/InstallerTest.php @@ -524,4 +524,18 @@ function (string $dirItem) { ) ); } + + /** + * @group composer/composer#5237 + */ + public function testWillEscapeRegexParsingOfClassDefinitions() + { + self::assertSame( + 1, + preg_match_all( + '{^((?:final\s+)?(?:\s*))class\s+(\S+)}mi', + file_get_contents((new \ReflectionClass(Installer::class))->getFileName()) + ) + ); + } } From b181d94a3cb30ce4a35be782a4ae946cd597afa8 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 23 Apr 2016 16:56:08 +0200 Subject: [PATCH 2/5] Applying workaround for composer/composer#5237 --- src/PackageVersions/Installer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PackageVersions/Installer.php b/src/PackageVersions/Installer.php index 9f4520d..8299970 100644 --- a/src/PackageVersions/Installer.php +++ b/src/PackageVersions/Installer.php @@ -27,7 +27,7 @@ final class Installer implements PluginInterface, EventSubscriberInterface * * This file is overwritten at every run of `composer install` or `composer update`. */ -final class Versions +%s { const VERSIONS = %s; @@ -99,6 +99,7 @@ private static function generateVersionsClass(Composer $composer) : string { return sprintf( self::$generatedClassTemplate, + 'fin' . 'al ' . 'cla' . 'ss ' . 'Versions', // note: workaround for regex-based code parsers :-( var_export(iterator_to_array(self::getVersions($composer->getLocker(), $composer->getPackage())), true) ); } From e93d5b419805e85210fa7162b22366aa78c335dd Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 23 Apr 2016 17:13:14 +0200 Subject: [PATCH 3/5] Removed unused import statement --- test/PackageVersionsTest/InstallerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/test/PackageVersionsTest/InstallerTest.php b/test/PackageVersionsTest/InstallerTest.php index 32802b7..a598a28 100644 --- a/test/PackageVersionsTest/InstallerTest.php +++ b/test/PackageVersionsTest/InstallerTest.php @@ -2,7 +2,6 @@ namespace PackageVersionsTest; -use Composer\Autoload\AutoloadGenerator; use Composer\Composer; use Composer\Config; use Composer\EventDispatcher\EventDispatcher; From b15b454de46401395c196dc9cf97413300b5f1ea Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 23 Apr 2016 17:13:51 +0200 Subject: [PATCH 4/5] Documenting thrown exceptions --- test/PackageVersionsTest/InstallerTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/PackageVersionsTest/InstallerTest.php b/test/PackageVersionsTest/InstallerTest.php index a598a28..78d47a2 100644 --- a/test/PackageVersionsTest/InstallerTest.php +++ b/test/PackageVersionsTest/InstallerTest.php @@ -44,6 +44,8 @@ final class InstallerTest extends PHPUnit_Framework_TestCase /** * {@inheritDoc} + * + * @throws \PHPUnit_Framework_Exception */ protected function setUp() { @@ -297,6 +299,8 @@ public static function getVersion(string $packageName) : string /** * @group #12 + * + * @throws \RuntimeException */ public function testDumpVersionsWithoutPackageSourceDetails() { @@ -402,6 +406,8 @@ public static function getVersion(string $packageName) : string * * @param RootPackageInterface $rootPackage * @param bool $inVendor + * + * @throws \RuntimeException */ public function testDumpsVersionsClassToSpecificLocation(RootPackageInterface $rootPackage, bool $inVendor) { From 083846658edac9dbdaaf22811caf395491a353c0 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 23 Apr 2016 17:16:02 +0200 Subject: [PATCH 5/5] Removing deprecated method usage --- test/PackageVersionsTest/VersionsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PackageVersionsTest/VersionsTest.php b/test/PackageVersionsTest/VersionsTest.php index 62415f1..a6798b0 100644 --- a/test/PackageVersionsTest/VersionsTest.php +++ b/test/PackageVersionsTest/VersionsTest.php @@ -28,7 +28,7 @@ public function testValidVersions() public function testInvalidVersionsAreRejected() { - $this->setExpectedException(\OutOfBoundsException::class); + $this->expectException(\OutOfBoundsException::class); Versions::getVersion(uniqid('', true) . '/' . uniqid('', true)); }