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

Commit

Permalink
Merge branch 'hotfix/xmlrpc' of https://github.com/sasezaki/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 55 deletions.
11 changes: 3 additions & 8 deletions src/Value/BigInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,13 @@
*/
class BigInteger extends Integer
{
/**
* @var \Zend\Math\BigInteger
*/
protected $_integer;

/**
* @param mixed $value
*/
public function __construct($value)
{
$this->_integer = new \Zend\Math\BigInteger();
$this->_value = $this->_integer->init($this->_value);
$integer = new \Zend\Math\BigInteger();
$this->_value = $integer->init($value);
$this->_type = self::XMLRPC_TYPE_I8;
}

Expand All @@ -52,6 +47,6 @@ public function __construct($value)
*/
public function getValue()
{
return $this->_integer;
return $this->_value;
}
}
155 changes: 155 additions & 0 deletions test/BigIntegerValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\XmlRpc;
use Zend\XmlRpc\Value;
use Zend\XmlRpc\Value\BigInteger;
use Zend\XmlRpc\Exception;
use Zend\XmlRpc\Generator\GeneratorInterface as Generator;
use Zend\Math\BigInteger as MathBigInteger;
use Zend\Date;

/**
* Test case for Zend_XmlRpc_Value
*
* @category Zend
* @package Zend_XmlRpc
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_XmlRpc
*/
class BigIntegerValueTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
try {
$XmlRpcBigInteger = new BigInteger(0);
} catch (\Zend\Math\Exception $e) {
$this->markTestSkipped($e->getMessage());
}
}

// BigInteger

/**
* @group ZF-6445
* @group ZF-8623
*/
public function testBigIntegerGetValue()
{
$bigIntegerValue = (string)(PHP_INT_MAX + 42);
$bigInteger = new BigInteger($bigIntegerValue);
$this->assertSame($bigIntegerValue, $bigInteger->getValue());
}

/**
* @group ZF-6445
*/
public function testBigIntegerGetType()
{
$bigIntegerValue = (string)(PHP_INT_MAX + 42);
$bigInteger = new BigInteger($bigIntegerValue);
$this->assertSame(Value::XMLRPC_TYPE_I8, $bigInteger->getType());
}

/**
* @group ZF-6445
*/
public function testBigIntegerGeneratedXml()
{
$bigIntegerValue = (string)(PHP_INT_MAX + 42);
$bigInteger = new BigInteger($bigIntegerValue);

$this->assertEquals(
'<value><i8>' . $bigIntegerValue . '</i8></value>',
$bigInteger->saveXml()
);
}

/**
* @group ZF-6445
* @dataProvider \ZendTest\XmlRpc\TestProvider::provideGenerators
*/
public function testMarschalBigIntegerFromXmlRpc(Generator $generator)
{
Value::setGenerator($generator);

$bigIntegerValue = (string)(PHP_INT_MAX + 42);
$bigInteger = new BigInteger($bigIntegerValue);
$bigIntegerXml = '<value><i8>' . $bigIntegerValue . '</i8></value>';

$value = Value::getXmlRpcValue(
$bigIntegerXml,
Value::XML_STRING
);

$this->assertSame($bigIntegerValue, $value->getValue());
$this->assertEquals(Value::XMLRPC_TYPE_I8, $value->getType());
$this->assertEquals($this->wrapXml($bigIntegerXml), $value->saveXml());
}

/**
* @group ZF-6445
* @dataProvider \ZendTest\XmlRpc\TestProvider::provideGenerators
*/
public function testMarschalBigIntegerFromApacheXmlRpc(Generator $generator)
{
Value::setGenerator($generator);

$bigIntegerValue = (string)(PHP_INT_MAX + 42);
$bigInteger = new BigInteger($bigIntegerValue);
$bigIntegerXml = '<value><ex:i8 xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/extensions">' . $bigIntegerValue . '</ex:i8></value>';

$value = Value::getXmlRpcValue(
$bigIntegerXml,
Value::XML_STRING
);

$this->assertSame($bigIntegerValue, $value->getValue());
$this->assertEquals(Value::XMLRPC_TYPE_I8, $value->getType());
$this->assertEquals($this->wrapXml($bigIntegerXml), $value->saveXml());
}

/**
* @group ZF-6445
*/
public function testMarshalBigIntegerFromNative()
{
$bigIntegerValue = (string)(PHP_INT_MAX + 42);

$value = Value::getXmlRpcValue(
$bigIntegerValue,
Value::XMLRPC_TYPE_I8
);

$this->assertEquals(Value::XMLRPC_TYPE_I8, $value->getType());
$this->assertSame($bigIntegerValue, $value->getValue());
}

// Custom Assertions and Helper Methods

public function wrapXml($xml)
{
return $xml . "\n";
}
}

47 changes: 0 additions & 47 deletions test/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,53 +134,6 @@ public function testMarshalIntegerFromOverlongNativeThrowsException()
Value::getXmlRpcValue(PHP_INT_MAX + 5000, Value::XMLRPC_TYPE_INTEGER);
}

// BigInteger

/**
* @group ZF-6445
* @dataProvider ZendTest\XmlRpc\TestProvider::provideGenerators
*/
public function testMarshalBigIntegerFromFromXmlRpc(Generator $generator)
{
Value::setGenerator($generator);
$bigInt = (string)(PHP_INT_MAX + 1);
$native = new BigInteger();
$native->init($bigInt);

$xmlStrings = array("<value><i8>$bigInt</i8></value>",
"<value><ex:i8 xmlns:ex=\"http://ws.apache.org/xmlrpc/namespaces/extensions\">$bigInt</ex:i8></value>");

foreach ($xmlStrings as $xml) {
$value = Value::getXmlRpcValue($xml, Value::XML_STRING);
$this->assertEquals($native, $value->getValue());
$this->assertEquals('i8', $value->getType());
$this->assertEquals($this->wrapXml($xml), $value->saveXml());
}
}

/**
* @group ZF-6445
*/
public function testMarshalBigIntegerFromNative()
{
$native = (string)(PHP_INT_MAX + 1);
$types = array(Value::XMLRPC_TYPE_APACHEI8,
Value::XMLRPC_TYPE_I8);

$bigInt = new BigInteger();
$bigInt->init($native);

foreach ($types as $type) {
$value = Value::getXmlRpcValue($native, $type);
$this->assertSame('i8', $value->getType());
$this->assertEquals($bigInt, $value->getValue());
}

$value = Value::getXmlRpcValue($bigInt);
$this->assertSame('i8', $value->getType());
$this->assertEquals($bigInt, $value->getValue());
}

// Double

public function testFactoryAutodetectsFloat()
Expand Down

0 comments on commit 567588e

Please sign in to comment.