trait InvokeMethodTrait in Commerce Google Tag Manager 8.2
Same name and namespace in other branches
- 8 tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\commerce_google_tag_manager\Traits\InvokeMethodTrait
Provides a function to invoke protected/private methods of a class.
Hierarchy
- trait \Drupal\Tests\commerce_google_tag_manager\Traits\InvokeMethodTrait
3 files declare their use of InvokeMethodTrait
- EventStorageServiceTest.php in tests/
src/ Unit/ EventStorageServiceTest.php - EventTrackerServicePurchaseTest.php in tests/
src/ Kernel/ EventTrackerServicePurchaseTest.php - EventTrackerServiceTest.php in tests/
src/ Kernel/ EventTrackerServiceTest.php
File
- tests/
src/ Traits/ InvokeMethodTrait.php, line 8
Namespace
Drupal\Tests\commerce_google_tag_manager\TraitsView 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
* Method name to call.
* @param array $parameters
* Array of parameters to pass into method.
* @param array $protected_properties
* Array of values that should be set on protected properties.
*
* @return mixed
* Method return.
*/
protected function invokeMethod(&$object, $method_name, array $parameters = [], array $protected_properties = []) {
$reflection = new \ReflectionClass(get_class($object));
foreach ($protected_properties as $property => $value) {
$property = $reflection
->getProperty($property);
$property
->setAccessible(TRUE);
$property
->setValue($object, $value);
}
$method = $reflection
->getMethod($method_name);
$method
->setAccessible(TRUE);
return $method
->invokeArgs($object, $parameters);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InvokeMethodTrait:: |
protected | function | Calls protected/private method of a class. |