diff --git a/src/Composer/Platform/Runtime.php b/src/Composer/Platform/Runtime.php index 82211ec88..3c77a9250 100644 --- a/src/Composer/Platform/Runtime.php +++ b/src/Composer/Platform/Runtime.php @@ -34,6 +34,15 @@ class Runtime return constant(ltrim($class.'::'.$constant, ':')); } + /** + * @param string $fn + * @return bool + */ + public function hasFunction($fn) + { + return function_exists($fn); + } + /** * @param callable $callable * @param array $arguments diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 5a8f70627..ac6d49525 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -125,7 +125,7 @@ class PlatformRepository extends ArrayRepository // The AF_INET6 constant is only defined if ext-sockets is available but // IPv6 support might still be available. - if ($this->runtime->hasConstant('AF_INET6') || Silencer::call(array($this->runtime, 'invoke'), array('inet_pton', '::')) !== false) { + if ($this->runtime->hasConstant('AF_INET6') || Silencer::call(array($this->runtime, 'invoke'), 'inet_pton', array('::')) !== false) { $phpIpv6 = new CompletePackage('php-ipv6', $version, $prettyVersion); $phpIpv6->setDescription('The PHP interpreter, with IPv6 support'); $this->addPackage($phpIpv6); diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index d90fcbc73..2da09c1dd 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -95,8 +95,19 @@ class PlatformRepositoryTest extends TestCase ), array( array('inet_pton', array('::'), ''), - ) - ) + ), + ), + array( + array( + 'PHP_VERSION' => '7.2.31-1+ubuntu16.04.1+deb.sury.org+1', + ), + array( + 'php' => '7.2.31', + ), + array( + array('inet_pton', array('::'), false), + ), + ), ); } @@ -133,6 +144,39 @@ class PlatformRepositoryTest extends TestCase } } + public function testInetPtonRegression() + { + $runtime = $this->getMockBuilder('Composer\Platform\Runtime')->getMock(); + + $runtime + ->expects(self::once()) + ->method('invoke') + ->with('inet_pton', array('::')) + ->willReturn(false); + $runtime + ->method('hasConstant') + ->willReturnMap( + array( + array('PHP_ZTS', false), + array('AF_INET6', false), + ) + ); + $runtime + ->method('getExtensions') + ->willReturn(array()); + $runtime + ->method('getConstant') + ->willReturnMap( + array( + array('PHP_VERSION', null, '7.0.0'), + array('PHP_DEBUG', null, false), + ) + ); + $repository = new PlatformRepository(array(), array(), $runtime); + $package = $repository->findPackage('php-ipv6', '*'); + self::assertNull($package); + } + public static function getLibraryTestCases() { return array(