You are here

trait InvokeMethodTrait in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait
  2. 8.2 tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait
  3. 4.x tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait

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

Hierarchy

3 files declare their use of InvokeMethodTrait
SearchApiBackendUnitTest.php in tests/src/Unit/SearchApiBackendUnitTest.php
SearchApiSolrTest.php in tests/src/Kernel/SearchApiSolrTest.php
SolrFieldNamesTest.php in tests/src/Kernel/SolrFieldNamesTest.php

File

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

Namespace

Drupal\Tests\search_api_solr\Traits
View source
trait InvokeMethodTrait {

  /**
   * Calls protected/private method of a class.
   *
   * @param object &$object
   *   Instantiated object that we will run method on.
   * @param string
   *   Method name to call.
   * @param array $parameters
   *   Array of parameters to pass into method.
   *
   * @return mixed
   *   Method return.
   */
  protected function invokeMethod(&$object, $methodName, array $parameters = []) {
    $reflection = new \ReflectionClass(get_class($object));
    $method = $reflection
      ->getMethod($methodName);
    $method
      ->setAccessible(TRUE);
    return $method
      ->invokeArgs($object, $parameters);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InvokeMethodTrait::invokeMethod protected function Calls protected/private method of a class.