You are here

protected function InvokeMethodTrait::invokeMethod in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait::invokeMethod()
  2. 8 tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait::invokeMethod()
  3. 8.2 tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait::invokeMethod()

Calls protected/private method of a class.

Parameters

object &$object: Instantiated object that we will run method on.

string $methodName: Method name to call.

array $parameters: Array of parameters to pass into method.

array $protectedProperties: Array of values that should be set on protected properties.

Return value

mixed Method return.

5 calls to InvokeMethodTrait::invokeMethod()
SearchApiBackendUnitTest::testIndexField in tests/src/Unit/SearchApiBackendUnitTest.php
@covers ::addIndexField
SearchApiSolrTest::checkQueryConditions in tests/src/Kernel/SearchApiSolrTest.php
Tests the conversion of Search API queries into Solr queries.
SearchApiSolrTest::checkRetrieveData in tests/src/Kernel/SearchApiSolrTest.php
Tests retrieve_data options.
SearchApiSolrTest::indexPrefixTest in tests/src/Kernel/SearchApiSolrTest.php
Tests index prefix.
SolrFieldNamesTest::testSolrFieldNames in tests/src/Kernel/SolrFieldNamesTest.php
@covers ::getSolrFieldNames

File

tests/src/Traits/InvokeMethodTrait.php, line 25

Class

InvokeMethodTrait
Provides a function to invoke protected/private methods of a class.

Namespace

Drupal\Tests\search_api_solr\Traits

Code

protected function invokeMethod(&$object, $methodName, array $parameters = [], array $protectedProperties = []) {
  $reflection = new \ReflectionClass(get_class($object));
  foreach ($protectedProperties as $property => $value) {
    $property = $reflection
      ->getProperty($property);
    $property
      ->setAccessible(TRUE);
    $property
      ->setValue($object, $value);
  }
  $method = $reflection
    ->getMethod($methodName);
  $method
    ->setAccessible(TRUE);
  return $method
    ->invokeArgs($object, $parameters);
}