Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit 88e60b5

Browse files
committed
qa: add tests to validate integer value marshaled for i8 values on 64bit systems
1 parent f3eeab8 commit 88e60b5

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/AbstractValue.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ abstract class AbstractValue
4444
protected $xml;
4545

4646
/**
47-
* @var \Zend\XmlRpc\Generator\GeneratorInterface
47+
* True if BigInteger should be used for XMLRPC i8 types
48+
*
49+
* @internal
50+
* @var bool
4851
*/
49-
protected static $generator;
52+
public static $USE_BIGINT_FOR_I8 = PHP_INT_SIZE < 8;
5053

5154
/**
52-
* True if BigInteger should be used for XMLRPC i8 types
55+
* @var \Zend\XmlRpc\Generator\GeneratorInterface
5356
*/
54-
public static $USE_BIGINT_FOR_I8 = PHP_INT_SIZE < 8;
57+
protected static $generator;
5558

5659
/**
5760
* Specify that the XML-RPC native type will be auto detected from a PHP variable type

test/BigIntegerValueTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@
1212
use PHPUnit\Framework\TestCase;
1313
use Zend\XmlRpc\AbstractValue;
1414
use Zend\XmlRpc\Value\BigInteger;
15+
use Zend\XmlRpc\Value\Integer;
1516
use Zend\XmlRpc\Generator\GeneratorInterface as Generator;
1617

1718
/**
1819
* @group Zend_XmlRpc
1920
*/
2021
class BigIntegerValueTest extends TestCase
2122
{
23+
/** @var null|bool */
24+
protected $useBigIntForI8Flag;
25+
2226
public function setUp()
2327
{
28+
$this->useBigIntForI8Flag = AbstractValue::$USE_BIGINT_FOR_I8;
2429
AbstractValue::$USE_BIGINT_FOR_I8 = true;
30+
2531
if (extension_loaded('gmp')) {
2632
$this->markTestSkipped('gmp causes test failure');
2733
}
@@ -32,6 +38,12 @@ public function setUp()
3238
}
3339
}
3440

41+
public function tearDown()
42+
{
43+
AbstractValue::$USE_BIGINT_FOR_I8 = $this->useBigIntForI8Flag;
44+
$this->useBigIntForI8Flag = null;
45+
}
46+
3547
// BigInteger
3648

3749
/**
@@ -137,4 +149,22 @@ public function wrapXml($xml)
137149
{
138150
return $xml . "\n";
139151
}
152+
153+
public function testMarshalsIntegerForI8ValueByDefaultIfSystemIs64Bit()
154+
{
155+
if ($this->useBigIntForI8Flag) {
156+
$this->markTestSkipped('Test only valid for 64bit systems');
157+
}
158+
159+
AbstractValue::$USE_BIGINT_FOR_I8 = $this->useBigIntForI8Flag;
160+
$integerValue = PHP_INT_MAX;
161+
162+
$value = AbstractValue::getXmlRpcValue(
163+
$integerValue,
164+
AbstractValue::XMLRPC_TYPE_I8
165+
);
166+
167+
$this->assertEquals(AbstractValue::XMLRPC_TYPE_INTEGER, $value->getType());
168+
$this->assertSame($integerValue, $value->getValue());
169+
}
140170
}

0 commit comments

Comments
 (0)