<commit_before><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendTest\XmlRpc;

use PHPUnit\Framework\TestCase;
use Zend\XmlRpc\AbstractValue;
use Zend\XmlRpc\Value\BigInteger;
use Zend\XmlRpc\Value\Integer;
use Zend\XmlRpc\Generator\GeneratorInterface as Generator;

/**
 * @group      Zend_XmlRpc
 */
class BigIntegerValueTest extends TestCase
{
    /** @var null|bool */
    protected $useBigIntForI8Flag;

    public function setUp()
    {
        $this->useBigIntForI8Flag = AbstractValue::$USE_BIGINT_FOR_I8;
        AbstractValue::$USE_BIGINT_FOR_I8 = true;

        if (extension_loaded('gmp')) {
            $this->markTestSkipped('gmp causes test failure');
        }
        try {
            $XmlRpcBigInteger = new BigInteger(0);
        } catch (\Zend\Math\Exception $e) {
            $this->markTestSkipped($e->getMessage());
        }
    }

    public function tearDown()
    {
        AbstractValue::$USE_BIGINT_FOR_I8 = $this->useBigIntForI8Flag;
        $this->useBigIntForI8Flag = null;
    }

    // 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(AbstractValue::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)
    {
        AbstractValue::setGenerator($generator);

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

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

        $this->assertSame($bigIntegerValue, $value->getValue());
        $this->assertEquals(AbstractValue::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)
    {
        AbstractValue::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 = AbstractValue::getXmlRpcValue(
            $bigIntegerXml,
            AbstractValue::XML_STRING
        );

        $this->assertSame($bigIntegerValue, $value->getValue());
        $this->assertEquals(AbstractValue::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 = AbstractValue::getXmlRpcValue(
            $bigIntegerValue,
            AbstractValue::XMLRPC_TYPE_I8
        );

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

    // Custom Assertions and Helper Methods

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

    public function testMarshalsIntegerForI8ValueByDefaultIfSystemIs64Bit()
    {
        if ($this->useBigIntForI8Flag) {
            $this->markTestSkipped('Test only valid for 64bit systems');
        }
        
        AbstractValue::$USE_BIGINT_FOR_I8 = $this->useBigIntForI8Flag;
        $integerValue = PHP_INT_MAX;

        $value = AbstractValue::getXmlRpcValue(
            $integerValue,
            AbstractValue::XMLRPC_TYPE_I8
        );<commit_msg>qa: cs fixes per phpcs<commit_after><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendTest\XmlRpc;

use PHPUnit\Framework\TestCase;
use Zend\XmlRpc\AbstractValue;
use Zend\XmlRpc\Value\BigInteger;
use Zend\XmlRpc\Value\Integer;
use Zend\XmlRpc\Generator\GeneratorInterface as Generator;

/**
 * @group      Zend_XmlRpc
 */
class BigIntegerValueTest extends TestCase
{
    /** @var null|bool */
    protected $useBigIntForI8Flag;

    public function setUp()
    {
        $this->useBigIntForI8Flag = AbstractValue::$USE_BIGINT_FOR_I8;
        AbstractValue::$USE_BIGINT_FOR_I8 = true;

        if (extension_loaded('gmp')) {
            $this->markTestSkipped('gmp causes test failure');
        }
        try {
            $XmlRpcBigInteger = new BigInteger(0);
        } catch (\Zend\Math\Exception $e) {
            $this->markTestSkipped($e->getMessage());
        }
    }

    public function tearDown()
    {
        AbstractValue::$USE_BIGINT_FOR_I8 = $this->useBigIntForI8Flag;
        $this->useBigIntForI8Flag = null;
    }

    // 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(AbstractValue::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)
    {
        AbstractValue::setGenerator($generator);

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

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

        $this->assertSame($bigIntegerValue, $value->getValue());
        $this->assertEquals(AbstractValue::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)
    {
        AbstractValue::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 = AbstractValue::getXmlRpcValue(
            $bigIntegerXml,
            AbstractValue::XML_STRING
        );

        $this->assertSame($bigIntegerValue, $value->getValue());
        $this->assertEquals(AbstractValue::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 = AbstractValue::getXmlRpcValue(
            $bigIntegerValue,
            AbstractValue::XMLRPC_TYPE_I8
        );

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

    // Custom Assertions and Helper Methods

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

    public function testMarshalsIntegerForI8ValueByDefaultIfSystemIs64Bit()
    {
        if ($this->useBigIntForI8Flag) {
            $this->markTestSkipped('Test only valid for 64bit systems');
        }

        AbstractValue::$USE_BIGINT_FOR_I8 = $this->useBigIntForI8Flag;
        $integerValue = PHP_INT_MAX;

        $value = AbstractValue::getXmlRpcValue(
            $integerValue,
            AbstractValue::XMLRPC_TYPE_I8
        );
{'fraction_non_alphanumeric': 0.13390775468829194, 'fraction_numerical': 0.015610745058286872, 'mean_word_length': 2.7132103876552502, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3075415', 'n_tokens_mistral': 3112, 'n_tokens_neox': 2989, 'n_words': 458}