function TestSetupTrait::__set

Implements the magic method for setting object properties.

Ensures \Drupal::getContainer() is used when getting the container property, if possible.

File

core/lib/Drupal/Core/Test/TestSetupTrait.php, line 221

Class

TestSetupTrait
Provides a trait for shared test setup functionality.

Namespace

Drupal\Core\Test

Code

public function __set($name, $value) : void {
  if ($name === 'container') {
    $this->privateContainer = $value;
    return;
  }
  // This deprecation message is intended to match the one PHP 8.2+ emits for
  // dynamic properties. The magic setter and this deprecation message will
  // be removed once property hooks can be used.
  // @see https://www.drupal.org/project/drupal/issues/3558863
  // @phpcs:ignore Drupal.Semantics.FunctionTriggerError.TriggerErrorTextLayoutRelaxed
  trigger_error('Creation of dynamic property ' . __CLASS__ . "::\${$name} is deprecated", E_USER_DEPRECATED);
  $this->{$name} = $value;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.