You are here

function SerializeQueryTest::testSerializeQuery in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/SerializeQueryTest.php \Drupal\system\Tests\Database\SerializeQueryTest::testSerializeQuery()

Confirms that a query can be serialized and unserialized.

File

core/modules/system/src/Tests/Database/SerializeQueryTest.php, line 19
Contains \Drupal\system\Tests\Database\SerializeQueryTest.

Class

SerializeQueryTest
Tests serializing and unserializing a query.

Namespace

Drupal\system\Tests\Database

Code

function testSerializeQuery() {
  $query = db_select('test');
  $query
    ->addField('test', 'age');
  $query
    ->condition('name', 'Ringo');

  // If this doesn't work, it will throw an exception, so no need for an
  // assertion.
  $query = unserialize(serialize($query));
  $results = $query
    ->execute()
    ->fetchCol();
  $this
    ->assertEqual($results[0], 28, 'Query properly executed after unserialization.');
}