<commit_before><?php

/**
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright <NAME>, NetMonsters LLC, 2011
 * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE
 * @link https://github.com/AntonTerekhov/OrientDB-PHP
 * @package OrientDB-PHP
 */

require_once 'OrientDB/OrientDB.php';
require_once 'OrientDBBaseTest.php';

/**
 * recordUpdate() test in OrientDB tests
 *
 * @author <NAME> <<EMAIL>>
 * @package OrientDB-PHP
 * @subpackage Tests
 */
class OrientDBRecordUpdateTest extends OrientDBBaseTesting
{

    protected $clusterID = 1;

    protected $recordContent = 'testrecord:0';

    protected $recordContentUpd = 'testrecord:1';

    protected function setUp()
    {
        $this->db = new OrientDB('localhost', 2424);
    }

    protected function tearDown()
    {
        $this->db = null;
    }

    public function testRecordUpdateOnNotConnectedDB()
    {
        $this->setExpectedException('OrientDBWrongCommandException');
        $list = $this->db->recordUpdate();
    }

    public function testRecordUpdateOnConnectedDB()
    {
        $this->db->connect('root', $this->root_password);
        $this->setExpectedException('OrientDBWrongCommandException');
        $list = $this->db->recordUpdate();
    }

    public function testRecordUpdateOnNotOpenDB()
    {
        $this->setExpectedException('OrientDBWrongCommandException');
        $list = $this->db->recordUpdate();
    }

    public function testRecordUpdateOnOpenDB()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent);
        $this->assertInternalType('integer', $recordPos);
        $record1 = $this->db->recordLoad($this->clusterID . ':' . $recordPos, '');
        $version = $this->db->recordUpdate($this->clusterID . ':' . $recordPos, $this->recordContentUpd);
        $this->AssertSame($record1->version + 1, $version);
        $record2 = $this->db->recordLoad($this->clusterID . ':' . $recordPos, '');
        $this->AssertSame($version, $record2->version);
        $this->AssertSame($this->recordContentUpd, $record2->content);
        $this->db->recordDelete($this->clusterID . ':' . $recordPos);
    }

    public function testRecordUpdateWithWrongOptionCount()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBWrongParamsException');
        $record = $this->db->recordUpdate($this->clusterID);
    }

    public function testRecordUpdateWithWrongRecordIDOne()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBException');
        $record = $this->db->recordUpdate('INVALID', $this->recordContent);
    }

    public function testRecordUpdateWithWrongRecordIDTwo()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBException');
        $record = $this->db->recordUpdate(':INVALID', $this->recordContent);
    }

    public function testRecordUpdateWithWrongRecordIDThree()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBException');
        $record = $this->db->recordUpdate('INVALID:', $this->recordContent);
    }

    public function testRecordUpdateWithWrongRecordIDFour()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBException');
        $record = $this->db->recordUpdate('1:INVALID', $this->recordContent);
    }

    public function testRecordUpdateWithRecordPosZero()
    {
        $recordPos = 0;
        $this->db->DBOpen('demo', 'writer', 'writer');
        $record = $this->db->recordLoad($this->clusterID . ':' . $recordPos, '');
        $version = $this->db->recordUpdate($this->clusterID . ':' . $recordPos, $record->content);
        $record2 = $this->db->recordLoad($this->clusterID . ':' . $recordPos, '');
        $this->AssertSame($version, $record2->version);
    }

    public function testRecordUpdateWithRecordNotExist()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent);
        $this->assertInternalType('integer', $recordPos);<commit_msg>Fix issue in test: trying to cast record of OrientDB::RECORD_TYPE_BYTES type to OrientDB::RECORD_TYPE_DOCUMENT <commit_after><?php

/**
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright <NAME>, NetMonsters LLC, 2011
 * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE
 * @link https://github.com/AntonTerekhov/OrientDB-PHP
 * @package OrientDB-PHP
 */

require_once 'OrientDB/OrientDB.php';
require_once 'OrientDBBaseTest.php';

/**
 * recordUpdate() test in OrientDB tests
 *
 * @author <NAME> <<EMAIL>>
 * @package OrientDB-PHP
 * @subpackage Tests
 */
class OrientDBRecordUpdateTest extends OrientDBBaseTesting
{

    protected $clusterID = 1;

    protected $recordContent = 'testrecord:0';

    protected $recordContentUpd = 'testrecord:1';

    protected function setUp()
    {
        $this->db = new OrientDB('localhost', 2424);
    }

    protected function tearDown()
    {
        $this->db = null;
    }

    public function testRecordUpdateOnNotConnectedDB()
    {
        $this->setExpectedException('OrientDBWrongCommandException');
        $list = $this->db->recordUpdate();
    }

    public function testRecordUpdateOnConnectedDB()
    {
        $this->db->connect('root', $this->root_password);
        $this->setExpectedException('OrientDBWrongCommandException');
        $list = $this->db->recordUpdate();
    }

    public function testRecordUpdateOnNotOpenDB()
    {
        $this->setExpectedException('OrientDBWrongCommandException');
        $list = $this->db->recordUpdate();
    }

    public function testRecordUpdateOnOpenDB()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent);
        $this->assertInternalType('integer', $recordPos);
        $record1 = $this->db->recordLoad($this->clusterID . ':' . $recordPos, '');
        $version = $this->db->recordUpdate($this->clusterID . ':' . $recordPos, $this->recordContentUpd);
        $this->AssertSame($record1->version + 1, $version);
        $record2 = $this->db->recordLoad($this->clusterID . ':' . $recordPos, '');
        $this->AssertSame($version, $record2->version);
        $this->AssertSame($this->recordContentUpd, $record2->content);
        $this->db->recordDelete($this->clusterID . ':' . $recordPos);
    }

    public function testRecordUpdateWithWrongOptionCount()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBWrongParamsException');
        $record = $this->db->recordUpdate($this->clusterID);
    }

    public function testRecordUpdateWithWrongRecordIDOne()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBException');
        $record = $this->db->recordUpdate('INVALID', $this->recordContent);
    }

    public function testRecordUpdateWithWrongRecordIDTwo()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBException');
        $record = $this->db->recordUpdate(':INVALID', $this->recordContent);
    }

    public function testRecordUpdateWithWrongRecordIDThree()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBException');
        $record = $this->db->recordUpdate('INVALID:', $this->recordContent);
    }

    public function testRecordUpdateWithWrongRecordIDFour()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $this->setExpectedException('OrientDBException');
        $record = $this->db->recordUpdate('1:INVALID', $this->recordContent);
    }

    public function testRecordUpdateWithRecordPosZero()
    {
        $recordPos = 0;
        $this->db->DBOpen('demo', 'writer', 'writer');
        $record = $this->db->recordLoad($this->clusterID . ':' . $recordPos, '');
        $version = $this->db->recordUpdate($this->clusterID . ':' . $recordPos, $record->content, -1, $record->type);
        $record2 = $this->db->recordLoad($this->clusterID . ':' . $recordPos, '');
        $this->AssertSame($version, $record2->version);
    }

    public function testRecordUpdateWithRecordNotExist()
    {
        $this->db->DBOpen('demo', 'writer', 'writer');
        $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent);
        $this->assertInternalType('integer', $recordPos);
{'fraction_non_alphanumeric': 0.17057939169654215, 'fraction_numerical': 0.004972822944373771, 'mean_word_length': 3.542016806722689, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 202, 'https://': 4, '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': '3387392', 'n_tokens_mistral': 2605, 'n_tokens_neox': 2559, 'n_words': 388}