class MockService

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\MockService
  2. 8.9.x core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\MockService
  3. 11.x 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 1168

Namespace

Drupal\Tests\Component\DependencyInjection
View source
class MockService {
    
    /**
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
     */
    protected $container;
    
    /**
     * @var object
     */
    protected $someOtherService;
    
    /**
     * @var string
     */
    protected $someParameter;
    
    /**
     * @var string
     */
    protected $someOtherParameter;
    
    /**
     * @var string
     */
    public string $someProperty;
    
    /**
     * 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 \Symfony\Component\DependencyInjection\ContainerInterface $container
     *   The container to inject via setter injection.
     */
    public function setContainer(ContainerInterface $container) {
        $this->container = $container;
    }
    
    /**
     * Gets the container object.
     *
     * @return \Symfony\Component\DependencyInjection\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 = []) {
        $r = new \ReflectionClass($class);
        $service = $r->getConstructor() === NULL ? $r->newInstance() : $r->newInstanceArgs($arguments);
        return $service;
    }

}

Members

Title Sort descending Modifiers Object type Summary
MockService::$container protected property
MockService::$someOtherParameter protected property
MockService::$someOtherService protected property
MockService::$someParameter protected property
MockService::$someProperty public 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.

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