Skip to content

Commit

Permalink
Merge pull request #16 from Ocramius/workaround/composer/composer#5237-…
Browse files Browse the repository at this point in the history
…class-parsing

Workaround for composer/composer#5237 - class parsing
  • Loading branch information
Ocramius committed Apr 23, 2016
2 parents a108adf + 0838466 commit 7e9aa66
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/PackageVersions/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);
}
Expand Down
21 changes: 20 additions & 1 deletion test/PackageVersionsTest/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PackageVersionsTest;

use Composer\Autoload\AutoloadGenerator;
use Composer\Composer;
use Composer\Config;
use Composer\EventDispatcher\EventDispatcher;
Expand Down Expand Up @@ -45,6 +44,8 @@ final class InstallerTest extends PHPUnit_Framework_TestCase

/**
* {@inheritDoc}
*
* @throws \PHPUnit_Framework_Exception
*/
protected function setUp()
{
Expand Down Expand Up @@ -298,6 +299,8 @@ public static function getVersion(string $packageName) : string

/**
* @group #12
*
* @throws \RuntimeException
*/
public function testDumpVersionsWithoutPackageSourceDetails()
{
Expand Down Expand Up @@ -403,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)
{
Expand Down Expand Up @@ -524,4 +529,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())
)
);
}
}
2 changes: 1 addition & 1 deletion test/PackageVersionsTest/VersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testValidVersions()

public function testInvalidVersionsAreRejected()
{
$this->setExpectedException(\OutOfBoundsException::class);
$this->expectException(\OutOfBoundsException::class);

Versions::getVersion(uniqid('', true) . '/' . uniqid('', true));
}
Expand Down

0 comments on commit 7e9aa66

Please sign in to comment.