<commit_before><?php
/**
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE.txt
 * file that was distributed with this source code.
 *
 * Date: 12.02.2016
 * Time: 14:06
 *
 */

namespace Blast\Tests\Orm\Data;


use Blast\Orm\Data\DataObject;
use Blast\Orm\Data\DataHelper;
use Blast\Orm\Data\ImmutableDataObject;
use Blast\Tests\Orm\Stubs\Data\ArrayObject;
use Blast\Tests\Orm\Stubs\Data\PlainObject;

/**
 * @coversDefaultClass \Blast\Db\Data\Helper
 */
class HelperTest extends \PHPUnit_Framework_TestCase
{
    public function testHelperForDataObject()
    {
        $config = [
            'class' => __CLASS__
        ];
        $object = new DataObject();
        $object->setData($config);

        $this->assertArrayHasKey('class', DataHelper::receiveDataFromObject($object));

        $config['method'] = __METHOD__;

        DataHelper::replaceDataFromObject($object, $config);

        $this->assertArrayHasKey('method', DataHelper::receiveDataFromObject($object));
        $this->assertArrayHasKey('method', $object->getData());
    }

    public function testHelperForImmutableDataObject()
    {
        $config = [
            'class' => __CLASS__
        ];
        $object = new DataObject();
        $object->setData($config);

        $this->assertArrayHasKey('class', DataHelper::receiveDataFromObject($object));
    }

    public function testThrowExceptionOnReplacingDataInImmutableDataObject()
    {
        $this->setExpectedException(\InvalidArgumentException::class);
        $config = [
            'class' => __CLASS__
        ];
        $object = new ImmutableDataObject();

        $config['method'] = __METHOD__;

        DataHelper::replaceDataFromObject($object, $config);
    }

    public function testHelperForArrayObject()
    {
        $config = [
            'class' => __CLASS__
        ];

        $object = new ArrayObject($config);

        $this->assertArrayHasKey('class', DataHelper::receiveDataFromObject($object));

        $config['method'] = __METHOD__;

        DataHelper::replaceDataFromObject($object, $config);

        $this->assertArrayHasKey('method', DataHelper::receiveDataFromObject($object));
        $this->assertArrayHasKey('method', $object->getArrayCopy());
    }

    public function testHelperForPlainObject()
    {
        $config = [
            'class' => __CLASS__
        ];

        $object = new PlainObject();

        foreach($config as $key => $value){
            $object->$key = $value;
        }

        $this->assertArrayHasKey('class', DataHelper::receiveDataFromObject($object));

        $config['method'] = __METHOD__;

        $object = DataHelper::replaceDataFromObject($object, $config);

        $this->assertArrayHasKey('method', DataHelper::receiveDataFromObject($object));<commit_msg>fix passing and receiving properties which has been added dynamically to objects<commit_after><?php
/**
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE.txt
 * file that was distributed with this source code.
 *
 * Date: 12.02.2016
 * Time: 14:06
 *
 */

namespace Blast\Tests\Orm\Data;


use Blast\Orm\Data\DataObject;
use Blast\Orm\Data\DataHelper;
use Blast\Orm\Data\ImmutableDataObject;
use Blast\Tests\Orm\Stubs\Data\ArrayObject;
use Blast\Tests\Orm\Stubs\Data\PlainObject;

/**
 * @coversDefaultClass \Blast\Db\Data\Helper
 */
class HelperTest extends \PHPUnit_Framework_TestCase
{
    public function testHelperForDataObject()
    {
        $config = [
            'class' => __CLASS__
        ];
        $object = new DataObject();
        $object->setData($config);

        $this->assertArrayHasKey('class', DataHelper::receiveDataFromObject($object));

        $config['method'] = __METHOD__;

        DataHelper::replaceDataFromObject($object, $config);

        $this->assertArrayHasKey('method', DataHelper::receiveDataFromObject($object));
        $this->assertArrayHasKey('method', $object->getData());
    }

    public function testHelperForImmutableDataObject()
    {
        $config = [
            'class' => __CLASS__
        ];
        $object = new DataObject();
        $object->setData($config);

        $this->assertArrayHasKey('class', DataHelper::receiveDataFromObject($object));
    }

    public function testThrowExceptionOnReplacingDataInImmutableDataObject()
    {
        $this->setExpectedException(\InvalidArgumentException::class);
        $config = [
            'class' => __CLASS__
        ];
        $object = new ImmutableDataObject();

        $config['method'] = __METHOD__;

        DataHelper::replaceDataFromObject($object, $config);
    }

    public function testHelperForArrayObject()
    {
        $config = [
            'class' => __CLASS__
        ];

        $object = new ArrayObject($config);

        $this->assertArrayHasKey('class', DataHelper::receiveDataFromObject($object));

        $config['method'] = __METHOD__;

        DataHelper::replaceDataFromObject($object, $config);

        $this->assertArrayHasKey('method', DataHelper::receiveDataFromObject($object));
        $this->assertArrayHasKey('method', $object->getArrayCopy());
    }

    public function testHelperForPlainObject()
    {
        $config = [
            'class' => __CLASS__
        ];

        $object = new PlainObject();

        foreach($config as $key => $value){
            $object->$key = $value;
        }

        $this->assertArrayHasKey('class', DataHelper::receiveDataFromObject($object));

        $config['method'] = __METHOD__;

        DataHelper::replaceDataFromObject($object, $config);

        $this->assertArrayHasKey('method', DataHelper::receiveDataFromObject($object));
{'fraction_non_alphanumeric': 0.13703897919944066, 'fraction_numerical': 0.004195070791819612, 'mean_word_length': 3.040960451977401, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4195808', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1594, 'n_words': 277}