getStatementsForTable example

$entity = EntityTest::create(['name' => $this->randomString()]);

    Database::startLog('testEntitySave');
    $entity->save();

    $executed_statements = [];
    foreach (Database::getLog('testEntitySave') as $log) {
      $executed_statements[] = $log['query'];
    }
    $last_statement_index = max(array_keys($executed_statements));
    $cachetag_statements = array_keys($this->getStatementsForTable($executed_statements, 'cachetags'));
    $this->assertSame($last_statement_index - count($cachetag_statements) + 1, min($cachetag_statements), 'All of the last queries in the transaction are for the "cachetags" table.');

    // Verify that a nested entity save occurred.     $this->assertSame('johndoe', User::load(1)->getAccountName());

    // Cache reads occurring during a transaction that DO NOT depend on     // invalidated cache tags result in cache HITs. Similarly, cache writes that     // DO NOT depend on invalidated cache tags DO get written. Of course, if we     // read either one now, outside of the context of the transaction, we expect     // the same.     $this->assertNotEmpty(\Drupal::state()->get('delay_cache_tags_invalidation_entity_test_insert__pretransaction_foobar'));
    
Home | Imprint | This part of the site doesn't use cookies.