You are here

public function EntitySubjectTest::setProtectedProperty in Changed Fields API 8.3

Sets a protected property on a given object via reflection.

Parameters

mixed $object: Instance in which protected value is being modified.

string $property: Property on instance being modified.

mixed $value: New value of the property being modified.

2 calls to EntitySubjectTest::setProtectedProperty()
EntitySubjectTest::testNotifyNewEntity in tests/src/Unit/EntitySubjectTest.php
Observer is not notified because node:article is new.
EntitySubjectTest::testNotifyObservers in tests/src/Unit/EntitySubjectTest.php
Observers 1 and 2 are notified. Observer 3 is not notified.

File

tests/src/Unit/EntitySubjectTest.php, line 31

Class

EntitySubjectTest
@coversDefaultClass \Drupal\changed_fields\EntitySubject

Namespace

Drupal\Tests\changed_fields\Unit

Code

public function setProtectedProperty($object, $property, $value) {
  $reflection = new \ReflectionClass($object);
  $reflection_property = $reflection
    ->getProperty($property);
  $reflection_property
    ->setAccessible(TRUE);
  $reflection_property
    ->setValue($object, $value);
}