public function testUpdate()
{
$config = static::getConfig();
$this->client = new PhpOrient();
$this->client->configure(array('username' => $config['username'], 'password' => $config['password'], 'hostname' => $config['hostname'], 'port' => $config['port']));
$this->client->dbOpen($this->db_name, 'admin', 'admin');
$tx = $this->client->getTransactionStatement();
$this->assertInstanceOf('PhpOrient\\Protocols\\Binary\\Transaction\\TxCommit', $tx);
$tx = $tx->begin();
$this->assertInstanceOf('PhpOrient\\Protocols\\Binary\\Transaction\\TxCommit', $tx);
$recUp = ['accommodation' => 'mountain cabin'];
$rec2 = new Record();
$rec2->setOData($recUp);
$rec2->setOClass('V');
$rec2->setRid($this->first_rec->getRid());
$rec2->setVersion($this->first_rec->getVersion());
$updateCommand = $this->client->recordUpdate($rec2);
//UPDATE AGAIN!!!
$recUp = ['accommodation' => 'mountain cabin 2'];
$rec3 = new Record();
$rec3->setOData($recUp);
$rec3->setOClass('V');
$rec3->setRid($this->first_rec->getRid());
$rec3->setVersion($this->first_rec->getVersion());
$updateCommand = $this->client->recordUpdate($rec3);
$createCommand = $this->client->recordCreate((new Record())->setOData(['accommodation' => 'bungalow'])->setOClass('V')->setRid(new ID(9)));
//CREATE ANOTHER ONE
$createCommand2 = $this->client->recordCreate((new Record())->setOData(['accommodation' => 'under the sky'])->setOClass('V')->setRid(new ID(9)));
$deleteCommand = $this->client->recordDelete($this->sec_rec->getRid());
$this->assertInstanceOf('PhpOrient\\Protocols\\Binary\\operations\\RecordUpdate', $updateCommand);
$tx->attach($updateCommand);
$tx->attach($createCommand);
$tx->attach($createCommand2);
$tx->attach($deleteCommand);
$result = $tx->commit();
/**
* @var Record $record
*/
foreach ($result as $record) {
if ($record->getRid() == $this->first_rec->getRid()) {
$this->assertEquals($record->getOData(), ['accommodation' => 'mountain cabin 2']);
$this->assertEquals($record->getOClass(), $this->first_rec->getOClass());
} elseif ($record->getRid()->__toString() == '#9:2') {
$this->assertEquals($record->getOData(), ['accommodation' => 'bungalow']);
$this->assertEquals($record->getOClass(), 'V');
} elseif ($record->getRid()->__toString() == '#9:3') {
$this->assertEquals($record->getOData(), ['accommodation' => 'under the sky']);
$this->assertEquals($record->getOClass(), 'V');
}
}
//check for deleted record
$deleted = $this->client->recordLoad($this->sec_rec->getRid());
$this->assertEmpty($deleted);
}