UpdateTest.php in Drupal driver for SQL Server and SQL Azure 4.0.x
File
tests/src/Kernel/UpdateTest.php
View source
<?php
namespace Drupal\Tests\sqlsrv\Kernel;
use Drupal\KernelTests\Core\Database\DatabaseTestBase;
class UpdateTest extends DatabaseTestBase {
public function testPrimaryKeyUpdate() {
$this
->expectException(\Exception::class);
$num_updated = $this->connection
->update('test')
->fields([
'id' => 42,
'name' => 'John',
])
->condition('id', '1')
->execute();
}
public function testNamespaceConditionObject() {
$namespace = (new \ReflectionObject($this->connection))
->getNamespaceName() . "\\Condition";
$update = $this->connection
->update('test');
$reflection = new \ReflectionObject($update);
$condition_property = $reflection
->getProperty('condition');
$condition_property
->setAccessible(TRUE);
$this
->assertIdentical($namespace, get_class($condition_property
->getValue($update)));
$nested_and_condition = $update
->andConditionGroup();
$this
->assertIdentical($namespace, get_class($nested_and_condition));
$nested_or_condition = $update
->orConditionGroup();
$this
->assertIdentical($namespace, get_class($nested_or_condition));
}
}