public function SerializationTest::testResultSerialization in Search API 8
Tests that serialization of search results works correctly.
File
- tests/src/ Kernel/ System/ SerializationTest.php, line 188 
Class
- SerializationTest
- Tests that various classes can be properly serialized and/or cloned.
Namespace
Drupal\Tests\search_api\Kernel\SystemCode
public function testResultSerialization() {
  $item = $this
    ->createTestItem();
  $results = $this
    ->createTestQuery()
    ->getResults()
    ->setResultCount(3)
    ->setResultItems([
    $item
      ->getId() => $item,
  ])
    ->addIgnoredSearchKey('test')
    ->addWarning('Something went a bit wrong.')
    ->setExtraData('test', [
    'foo' => 'bar',
  ]);
  /** @var \Drupal\search_api\Query\ResultSetInterface $serialized */
  $serialized = unserialize(serialize($results));
  // Call serialize() on the restored results to make "equals" work correctly.
  serialize($serialized);
  $this
    ->assertEquals($results, $serialized);
}