class MockService in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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\DependencyInjectionView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MockService:: |
protected | property | ||
MockService:: |
protected | property | ||
MockService:: |
protected | property | ||
MockService:: |
protected | property | ||
MockService:: |
public | function | Gets the container object. | |
MockService:: |
public static | function | Provides a factory method to get a service. | |
MockService:: |
public | function | Gets the someOtherParameter property. | |
MockService:: |
public | function | Gets the someOtherService object. | |
MockService:: |
public | function | Gets the someParameter property. | |
MockService:: |
public | function | Sets the container object. | |
MockService:: |
public | function | Sets the someOtherParameter property. | |
MockService:: |
public | function | Constructs a MockService object. |