3 namespace Drupal\Tests\permissions_by_term\Unit;
5 use \Symfony\Component\DependencyInjection\ContainerInterface;
11 * @param string $namespace
12 * @param array $methodsReturnMap
16 public function createMock($namespace, array $methodsReturnMap = [])
18 $methodNames = array_keys($methodsReturnMap);
20 ->getMockBuilder($namespace);
22 $mock->disableOriginalConstructor();
25 ->setMethods($methodNames)
28 foreach ($methodsReturnMap as $methodName => $methodReturn) {
32 $this->returnValue($methodReturn)
40 * @param string $class
41 * @param string $propertyName
44 public function modifyPropertyByReflection($class, $propertyName, $value)
46 $reflection = $this->makePropertyAccessible($class, $propertyName);
47 $reflection->setValue($class, $value);
51 * @param string $class
52 * @param string $propertyName
53 * @return \ReflectionProperty
55 public function makePropertyAccessible($class, $propertyName)
57 $reflection = new \ReflectionProperty(get_class($class), $propertyName);
58 $reflection->setAccessible(true);
64 * @param null|array $methodReturnValues
65 * @param null|array $methodReturnValuesMap
69 public function getContainerMock($methodReturnValues = null, $methodReturnValuesMap = null)
71 if (!is_array($methodReturnValues)) {
72 $methodReturnValues = [];
75 if (!is_array($methodReturnValuesMap)) {
76 $methodReturnValuesMap = [];
79 $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->setMethods(array_merge(array_keys($methodReturnValues), array_keys($methodReturnValuesMap)))->getMock();
81 foreach ($methodReturnValues as $methodName => $returnValue) {
82 $container->method($methodName)->will($this->returnValue($returnValue));
85 foreach ($methodReturnValuesMap as $methodName => $returnValueMap) {
86 $container->method($methodName)->will($this->returnValueMap($returnValueMap));
93 * @param string $string
96 public function containsHtml($string)
98 if ($string != strip_tags($string)) {
105 protected function collectServices($defaultServiceContainers, $testSpecificServices)
107 $serviceContainers = $defaultServiceContainers;
109 if (!empty($testSpecificServices)) {
110 $testSpecificServiceKeys = $this->extractTestSpecificContainerKeys($testSpecificServices);
111 $uniqueDefaultServiceContainers = $this->collectUndefinedServicesByDefaultStack($defaultServiceContainers, $testSpecificServiceKeys);
112 $serviceContainers = array_merge($uniqueDefaultServiceContainers, $testSpecificServices);
115 return $serviceContainers;
118 protected function extractTestSpecificContainerKeys($testSpecificServices)
120 foreach ($testSpecificServices as $testSpecificService) {
121 $testSpecificServiceKeys[] = $testSpecificService['0'];
124 return $testSpecificServiceKeys;
127 protected function collectUndefinedServicesByDefaultStack($defaultServiceContainers, $testSpecificServiceKeys)
129 foreach ($defaultServiceContainers as $serviceContainer) {
130 if (!in_array($serviceContainer['0'], $testSpecificServiceKeys)) {
131 $uniqueServiceContainers[] = $serviceContainer;
135 return $uniqueServiceContainers;