function NonPublicSchemaTest::testInsert

Same name and namespace in other branches
  1. 11.x core/modules/pgsql/tests/src/Kernel/pgsql/NonPublicSchemaTest.php \Drupal\Tests\pgsql\Kernel\pgsql\NonPublicSchemaTest::testInsert()

@covers \Drupal\Core\Database\Connection::insert
@covers \Drupal\Core\Database\Connection::select

File

core/modules/pgsql/tests/src/Kernel/pgsql/NonPublicSchemaTest.php, line 146

Class

NonPublicSchemaTest
Tests schema API for non-public schema for the PostgreSQL driver.

Namespace

Drupal\Tests\pgsql\Kernel\pgsql

Code

public function testInsert() : void {
  $num_records_before = $this->testingFakeConnection
    ->query('SELECT COUNT(*) FROM {faking_table}')
    ->fetchField();
  $this->testingFakeConnection
    ->insert('faking_table')
    ->fields([
    'id' => '123',
    'test_field' => '55',
  ])
    ->execute();
  // Testing that the insert is correct.
  $results = $this->testingFakeConnection
    ->select('faking_table')
    ->fields('faking_table')
    ->condition('id', '123')
    ->execute()
    ->fetchAll();
  $this->assertIsArray($results);
  $num_records_after = $this->testingFakeConnection
    ->query('SELECT COUNT(*) FROM {faking_table}')
    ->fetchField();
  $this->assertEquals($num_records_before + 1, $num_records_after, 'Merge inserted properly.');
  $this->assertSame('123', $results[0]->id);
  $this->assertSame('55', $results[0]->test_field);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.