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

File tree

3 files changed

+158
-55
lines changed

3 files changed

+158
-55
lines changed

src/Value/BigInteger.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,13 @@
3030
*/
3131
class BigInteger extends Integer
3232
{
33-
/**
34-
* @var \Zend\Math\BigInteger
35-
*/
36-
protected $_integer;
37-
3833
/**
3934
* @param mixed $value
4035
*/
4136
public function __construct($value)
4237
{
43-
$this->_integer = new \Zend\Math\BigInteger();
44-
$this->_value = $this->_integer->init($this->_value);
38+
$integer = new \Zend\Math\BigInteger();
39+
$this->_value = $integer->init($value);
4540
$this->_type = self::XMLRPC_TYPE_I8;
4641
}
4742

@@ -52,6 +47,6 @@ public function __construct($value)
5247
*/
5348
public function getValue()
5449
{
55-
return $this->_integer;
50+
return $this->_value;
5651
}
5752
}

test/BigIntegerValueTest.php

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
/**
3+
* Zend Framework
4+
*
5+
* LICENSE
6+
*
7+
* This source file is subject to the new BSD license that is bundled
8+
* with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://framework.zend.com/license/new-bsd
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to license@zend.com so we can send you a copy immediately.
14+
*
15+
* @category Zend
16+
* @package Zend_XmlRpc
17+
* @subpackage UnitTests
18+
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
19+
* @license http://framework.zend.com/license/new-bsd New BSD License
20+
*/
21+
22+
namespace ZendTest\XmlRpc;
23+
use Zend\XmlRpc\Value;
24+
use Zend\XmlRpc\Value\BigInteger;
25+
use Zend\XmlRpc\Exception;
26+
use Zend\XmlRpc\Generator\GeneratorInterface as Generator;
27+
use Zend\Math\BigInteger as MathBigInteger;
28+
use Zend\Date;
29+
30+
/**
31+
* Test case for Zend_XmlRpc_Value
32+
*
33+
* @category Zend
34+
* @package Zend_XmlRpc
35+
* @subpackage UnitTests
36+
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
37+
* @license http://framework.zend.com/license/new-bsd New BSD License
38+
* @group Zend_XmlRpc
39+
*/
40+
class BigIntegerValueTest extends \PHPUnit_Framework_TestCase
41+
{
42+
public function setUp()
43+
{
44+
try {
45+
$XmlRpcBigInteger = new BigInteger(0);
46+
} catch (\Zend\Math\Exception $e) {
47+
$this->markTestSkipped($e->getMessage());
48+
}
49+
}
50+
51+
// BigInteger
52+
53+
/**
54+
* @group ZF-6445
55+
* @group ZF-8623
56+
*/
57+
public function testBigIntegerGetValue()
58+
{
59+
$bigIntegerValue = (string)(PHP_INT_MAX + 42);
60+
$bigInteger = new BigInteger($bigIntegerValue);
61+
$this->assertSame($bigIntegerValue, $bigInteger->getValue());
62+
}
63+
64+
/**
65+
* @group ZF-6445
66+
*/
67+
public function testBigIntegerGetType()
68+
{
69+
$bigIntegerValue = (string)(PHP_INT_MAX + 42);
70+
$bigInteger = new BigInteger($bigIntegerValue);
71+
$this->assertSame(Value::XMLRPC_TYPE_I8, $bigInteger->getType());
72+
}
73+
74+
/**
75+
* @group ZF-6445
76+
*/
77+
public function testBigIntegerGeneratedXml()
78+
{
79+
$bigIntegerValue = (string)(PHP_INT_MAX + 42);
80+
$bigInteger = new BigInteger($bigIntegerValue);
81+
82+
$this->assertEquals(
83+
'<value><i8>' . $bigIntegerValue . '</i8></value>',
84+
$bigInteger->saveXml()
85+
);
86+
}
87+
88+
/**
89+
* @group ZF-6445
90+
* @dataProvider \ZendTest\XmlRpc\TestProvider::provideGenerators
91+
*/
92+
public function testMarschalBigIntegerFromXmlRpc(Generator $generator)
93+
{
94+
Value::setGenerator($generator);
95+
96+
$bigIntegerValue = (string)(PHP_INT_MAX + 42);
97+
$bigInteger = new BigInteger($bigIntegerValue);
98+
$bigIntegerXml = '<value><i8>' . $bigIntegerValue . '</i8></value>';
99+
100+
$value = Value::getXmlRpcValue(
101+
$bigIntegerXml,
102+
Value::XML_STRING
103+
);
104+
105+
$this->assertSame($bigIntegerValue, $value->getValue());
106+
$this->assertEquals(Value::XMLRPC_TYPE_I8, $value->getType());
107+
$this->assertEquals($this->wrapXml($bigIntegerXml), $value->saveXml());
108+
}
109+
110+
/**
111+
* @group ZF-6445
112+
* @dataProvider \ZendTest\XmlRpc\TestProvider::provideGenerators
113+
*/
114+
public function testMarschalBigIntegerFromApacheXmlRpc(Generator $generator)
115+
{
116+
Value::setGenerator($generator);
117+
118+
$bigIntegerValue = (string)(PHP_INT_MAX + 42);
119+
$bigInteger = new BigInteger($bigIntegerValue);
120+
$bigIntegerXml = '<value><ex:i8 xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/extensions">' . $bigIntegerValue . '</ex:i8></value>';
121+
122+
$value = Value::getXmlRpcValue(
123+
$bigIntegerXml,
124+
Value::XML_STRING
125+
);
126+
127+
$this->assertSame($bigIntegerValue, $value->getValue());
128+
$this->assertEquals(Value::XMLRPC_TYPE_I8, $value->getType());
129+
$this->assertEquals($this->wrapXml($bigIntegerXml), $value->saveXml());
130+
}
131+
132+
/**
133+
* @group ZF-6445
134+
*/
135+
public function testMarshalBigIntegerFromNative()
136+
{
137+
$bigIntegerValue = (string)(PHP_INT_MAX + 42);
138+
139+
$value = Value::getXmlRpcValue(
140+
$bigIntegerValue,
141+
Value::XMLRPC_TYPE_I8
142+
);
143+
144+
$this->assertEquals(Value::XMLRPC_TYPE_I8, $value->getType());
145+
$this->assertSame($bigIntegerValue, $value->getValue());
146+
}
147+
148+
// Custom Assertions and Helper Methods
149+
150+
public function wrapXml($xml)
151+
{
152+
return $xml . "\n";
153+
}
154+
}
155+

test/ValueTest.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -134,53 +134,6 @@ public function testMarshalIntegerFromOverlongNativeThrowsException()
134134
Value::getXmlRpcValue(PHP_INT_MAX + 5000, Value::XMLRPC_TYPE_INTEGER);
135135
}
136136

137-
// BigInteger
138-
139-
/**
140-
* @group ZF-6445
141-
* @dataProvider ZendTest\XmlRpc\TestProvider::provideGenerators
142-
*/
143-
public function testMarshalBigIntegerFromFromXmlRpc(Generator $generator)
144-
{
145-
Value::setGenerator($generator);
146-
$bigInt = (string)(PHP_INT_MAX + 1);
147-
$native = new BigInteger();
148-
$native->init($bigInt);
149-
150-
$xmlStrings = array("<value><i8>$bigInt</i8></value>",
151-
"<value><ex:i8 xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">$bigInt</ex:i8></value>");
152-
153-
foreach ($xmlStrings as $xml) {
154-
$value = Value::getXmlRpcValue($xml, Value::XML_STRING);
155-
$this->assertEquals($native, $value->getValue());
156-
$this->assertEquals('i8', $value->getType());
157-
$this->assertEquals($this->wrapXml($xml), $value->saveXml());
158-
}
159-
}
160-
161-
/**
162-
* @group ZF-6445
163-
*/
164-
public function testMarshalBigIntegerFromNative()
165-
{
166-
$native = (string)(PHP_INT_MAX + 1);
167-
$types = array(Value::XMLRPC_TYPE_APACHEI8,
168-
Value::XMLRPC_TYPE_I8);
169-
170-
$bigInt = new BigInteger();
171-
$bigInt->init($native);
172-
173-
foreach ($types as $type) {
174-
$value = Value::getXmlRpcValue($native, $type);
175-
$this->assertSame('i8', $value->getType());
176-
$this->assertEquals($bigInt, $value->getValue());
177-
}
178-
179-
$value = Value::getXmlRpcValue($bigInt);
180-
$this->assertSame('i8', $value->getType());
181-
$this->assertEquals($bigInt, $value->getValue());
182-
}
183-
184137
// Double
185138

186139
public function testFactoryAutodetectsFloat()

0 commit comments

Comments
 (0)