SerializeQueryTest.php

Same filename in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/SerializeQueryTest.php
  2. 10 core/tests/Drupal/KernelTests/Core/Database/SerializeQueryTest.php
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/SerializeQueryTest.php

Namespace

Drupal\KernelTests\Core\Database

File

core/tests/Drupal/KernelTests/Core/Database/SerializeQueryTest.php

View source
<?php

namespace Drupal\KernelTests\Core\Database;


/**
 * Tests serializing and unserializing a query.
 *
 * @group Database
 */
class SerializeQueryTest extends DatabaseTestBase {
    
    /**
     * Confirms that a query can be serialized and unserialized.
     */
    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->assertEqual($results[0], 28, 'Query properly executed after unserialization.');
    }

}

Classes

Title Deprecated Summary
SerializeQueryTest Tests serializing and unserializing a query.

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