1
0
Fork 0

Merge pull request #9133 from lstrojny/dev/check-inet-pton

Fix regression when inet_pton() does not exist
pull/9138/head
Jordi Boggiano 2020-08-18 16:52:45 +02:00 committed by GitHub
commit 38f49acfdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 3 deletions

View File

@ -34,6 +34,15 @@ class Runtime
return constant(ltrim($class.'::'.$constant, ':')); return constant(ltrim($class.'::'.$constant, ':'));
} }
/**
* @param string $fn
* @return bool
*/
public function hasFunction($fn)
{
return function_exists($fn);
}
/** /**
* @param callable $callable * @param callable $callable
* @param array $arguments * @param array $arguments

View File

@ -125,7 +125,7 @@ class PlatformRepository extends ArrayRepository
// The AF_INET6 constant is only defined if ext-sockets is available but // The AF_INET6 constant is only defined if ext-sockets is available but
// IPv6 support might still be available. // 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 = new CompletePackage('php-ipv6', $version, $prettyVersion);
$phpIpv6->setDescription('The PHP interpreter, with IPv6 support'); $phpIpv6->setDescription('The PHP interpreter, with IPv6 support');
$this->addPackage($phpIpv6); $this->addPackage($phpIpv6);

View File

@ -95,8 +95,19 @@ class PlatformRepositoryTest extends TestCase
), ),
array( array(
array('inet_pton', 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() public static function getLibraryTestCases()
{ {
return array( return array(