From 404dea61c2a40f27a91c203c00ed33fb286ebedc Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 29 Jul 2020 19:30:57 +0200 Subject: [PATCH 1/2] Allow specifying a version requirement for the relevant CLDR --- .../Repository/PlatformRepository.php | 35 +++++++++++++------ .../Repository/PlatformRepositoryTest.php | 32 +++++++++++++++++ 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index ecd4ca256..848576aa3 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -154,7 +154,12 @@ class PlatformRepository extends ArrayRepository break; case 'intl': - $name = 'ICU'; + # Add a seperate version for the CLDR library version + $cldrVersion = \ResourceBundle::create('root', 'ICUDATA-curr', false)->get('Version'); + $this->addLibrary('cldr', 'The unicode CLDR project', $cldrVersion); + + $name = 'icu'; + $description = 'The ICU unicode and globalization support library'; if (defined('INTL_ICU_VERSION')) { $prettyVersion = INTL_ICU_VERSION; } else { @@ -228,15 +233,7 @@ class PlatformRepository extends ArrayRepository continue 2; } - try { - $version = $this->versionParser->normalize($prettyVersion); - } catch (\UnexpectedValueException $e) { - continue; - } - - $lib = new CompletePackage('lib-'.$name, $version, $prettyVersion); - $lib->setDescription($description); - $this->addPackage($lib); + $this->addLibrary($name, $description, $prettyVersion); } $hhvmVersion = defined('HHVM_VERSION') ? HHVM_VERSION : null; @@ -346,4 +343,22 @@ class PlatformRepository extends ArrayRepository { return 'ext-' . str_replace(' ', '-', $name); } + + /** + * @param string $name + * @param string $description + * @param string $prettyVersion + */ + private function addLibrary($name, $description, $prettyVersion) + { + try { + $version = $this->versionParser->normalize($prettyVersion); + } catch (\UnexpectedValueException $e) { + return; + } + + $lib = new CompletePackage('lib-'.$name, $version, $prettyVersion); + $lib->setDescription($description); + $this->addPackage($lib); + } } diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index aa51a2fc6..20dd295fc 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -12,6 +12,7 @@ namespace Composer\Test\Repository; +use Composer\Package\Package; use Composer\Repository\PlatformRepository; use Composer\Test\TestCase; use Composer\Util\Platform; @@ -67,4 +68,35 @@ class PlatformRepositoryTest extends TestCase { $this->assertNotNull($package, 'failed to find HHVM package'); $this->assertSame('4.0.1.0-dev', $package->getVersion()); } + + public function testICULibraryVersion() + { + if (!defined('INTL_ICU_VERSION')) { + $this->markTestSkipped('Test only work with ext-intl present'); + } + + $platformRepository = new PlatformRepository(); + $packages = $platformRepository->getPackages(); + + /** @var Package $icuPackage */ + $icuPackage = null; + /** @var Package $cldrPackage */ + $cldrPackage = null; + + foreach ($packages as $package) { + if ($package->getName() === 'lib-icu') { + $icuPackage = $package; + } + + if ($package->getName() === 'lib-cldr') { + $cldrPackage = $package; + } + } + + self::assertNotNull($icuPackage, 'Expected to find lib-icu in packages'); + self::assertNotNull($cldrPackage, 'Expected to find lib-cldr in packages'); + + self::assertSame(3, substr_count($icuPackage->getVersion(), '.'), 'Expected to find real ICU version'); + self::assertSame(3, substr_count($cldrPackage->getVersion(), '.'), 'Expected to find real CLDR version'); + } } From 5a02ea6a9622476a63515f34b1b2ef26c05ac405 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 30 Jul 2020 14:29:48 +0200 Subject: [PATCH 2/2] Check that class exists --- src/Composer/Repository/PlatformRepository.php | 8 +++++--- tests/Composer/Test/Repository/PlatformRepositoryTest.php | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 848576aa3..5d240fa9c 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -154,9 +154,11 @@ class PlatformRepository extends ArrayRepository break; case 'intl': - # Add a seperate version for the CLDR library version - $cldrVersion = \ResourceBundle::create('root', 'ICUDATA-curr', false)->get('Version'); - $this->addLibrary('cldr', 'The unicode CLDR project', $cldrVersion); + if (class_exists('ResourceBundle', false)) { + # Add a seperate version for the CLDR library version + $cldrVersion = \ResourceBundle::create('root', 'ICUDATA-curr', false)->get('Version'); + $this->addLibrary('cldr', 'The unicode CLDR project', $cldrVersion); + } $name = 'icu'; $description = 'The ICU unicode and globalization support library'; diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index 20dd295fc..e254720fb 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -69,12 +69,15 @@ class PlatformRepositoryTest extends TestCase { $this->assertSame('4.0.1.0-dev', $package->getVersion()); } - public function testICULibraryVersion() - { + public function testICULibraryVersion() { if (!defined('INTL_ICU_VERSION')) { $this->markTestSkipped('Test only work with ext-intl present'); } + if (!class_exists('ResourceBundle', false)) { + $this->markTestSkipped('Test only work with ResourceBundle class present'); + } + $platformRepository = new PlatformRepository(); $packages = $platformRepository->getPackages();