function SerializeQueryTest::testSerializeQuery

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/SerializeQueryTest.php \Drupal\KernelTests\Core\Database\SerializeQueryTest::testSerializeQuery()
  2. 10 core/tests/Drupal/KernelTests/Core/Database/SerializeQueryTest.php \Drupal\KernelTests\Core\Database\SerializeQueryTest::testSerializeQuery()
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/SerializeQueryTest.php \Drupal\KernelTests\Core\Database\SerializeQueryTest::testSerializeQuery()

Confirms that a query can be serialized and unserialized.

File

core/tests/Drupal/KernelTests/Core/Database/SerializeQueryTest.php, line 15

Class

SerializeQueryTest
Tests serializing and unserializing a query.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testSerializeQuery() {
    $query = $this->connection
        ->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->assertEquals(28, $results[0], 'Query properly executed after unserialization.');
}

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