You are here

class MockService in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\MockService

Helper class to test Container::get() method.

@group DependencyInjection

Hierarchy

  • class \Drupal\Tests\Component\DependencyInjection\MockService

Expanded class hierarchy of MockService

File

core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php, line 1072
Contains \Drupal\Tests\Component\DependencyInjection\ContainerTest.

Namespace

Drupal\Tests\Component\DependencyInjection
View source
class MockService {

  /**
   * @var ContainerInterface
   */
  protected $container;

  /**
   * @var object
   */
  protected $someOtherService;

  /**
   * @var string
   */
  protected $someParameter;

  /**
   * @var string
   */
  protected $someOtherParameter;

  /**
   * Constructs a MockService object.
   *
   * @param object $some_other_service
   *   (optional) Another injected service.
   * @param string $some_parameter
   *   (optional) An injected parameter.
   */
  public function __construct($some_other_service = NULL, $some_parameter = NULL) {
    if (is_array($some_other_service)) {
      $some_other_service = $some_other_service[0];
    }
    $this->someOtherService = $some_other_service;
    $this->someParameter = $some_parameter;
  }

  /**
   * Sets the container object.
   *
   * @param ContainerInterface $container
   *   The container to inject via setter injection.
   */
  public function setContainer(ContainerInterface $container) {
    $this->container = $container;
  }

  /**
   * Gets the container object.
   *
   * @return ContainerInterface
   *   The internally set container.
   */
  public function getContainer() {
    return $this->container;
  }

  /**
   * Gets the someOtherService object.
   *
   * @return object
   *   The injected service.
   */
  public function getSomeOtherService() {
    return $this->someOtherService;
  }

  /**
   * Gets the someParameter property.
   *
   * @return string
   *   The injected parameter.
   */
  public function getSomeParameter() {
    return $this->someParameter;
  }

  /**
   * Sets the someOtherParameter property.
   *
   * @param string $some_other_parameter
   *   The setter injected parameter.
   */
  public function setOtherConfigParameter($some_other_parameter) {
    $this->someOtherParameter = $some_other_parameter;
  }

  /**
   * Gets the someOtherParameter property.
   *
   * @return string
   *   The injected parameter.
   */
  public function getSomeOtherParameter() {
    return $this->someOtherParameter;
  }

  /**
   * Provides a factory method to get a service.
   *
   * @param string $class
   *   The class name of the class to instantiate
   * @param array $arguments
   *   (optional) Arguments to pass to the new class.
   *
   * @return object
   *   The instantiated service object.
   */
  public static function getFactoryMethod($class, $arguments = array()) {
    $r = new \ReflectionClass($class);
    $service = $r
      ->getConstructor() === NULL ? $r
      ->newInstance() : $r
      ->newInstanceArgs($arguments);
    return $service;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MockService::$container protected property
MockService::$someOtherParameter protected property
MockService::$someOtherService protected property
MockService::$someParameter protected property
MockService::getContainer public function Gets the container object.
MockService::getFactoryMethod public static function Provides a factory method to get a service.
MockService::getSomeOtherParameter public function Gets the someOtherParameter property.
MockService::getSomeOtherService public function Gets the someOtherService object.
MockService::getSomeParameter public function Gets the someParameter property.
MockService::setContainer public function Sets the container object.
MockService::setOtherConfigParameter public function Sets the someOtherParameter property.
MockService::__construct public function Constructs a MockService object.