comparison core/tests/Drupal/Tests/UnitTestCase.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 1fec387a4317
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
14 * Provides a base class and helpers for Drupal unit tests. 14 * Provides a base class and helpers for Drupal unit tests.
15 * 15 *
16 * @ingroup testing 16 * @ingroup testing
17 */ 17 */
18 abstract class UnitTestCase extends TestCase { 18 abstract class UnitTestCase extends TestCase {
19
20 use PhpunitCompatibilityTrait;
19 21
20 /** 22 /**
21 * The random generator. 23 * The random generator.
22 * 24 *
23 * @var \Drupal\Component\Utility\Random 25 * @var \Drupal\Component\Utility\Random
133 ->will($this->returnValueMap($map)); 135 ->will($this->returnValueMap($map));
134 $config_editable_map[] = [$config_name, $mutable_config_object]; 136 $config_editable_map[] = [$config_name, $mutable_config_object];
135 } 137 }
136 // Construct a config factory with the array of configuration object stubs 138 // Construct a config factory with the array of configuration object stubs
137 // as its return map. 139 // as its return map.
138 $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'); 140 $config_factory = $this->createMock('Drupal\Core\Config\ConfigFactoryInterface');
139 $config_factory->expects($this->any()) 141 $config_factory->expects($this->any())
140 ->method('get') 142 ->method('get')
141 ->will($this->returnValueMap($config_get_map)); 143 ->will($this->returnValueMap($config_get_map));
142 $config_factory->expects($this->any()) 144 $config_factory->expects($this->any())
143 ->method('getEditable') 145 ->method('getEditable')
155 * 157 *
156 * @return \Drupal\Core\Config\StorageInterface 158 * @return \Drupal\Core\Config\StorageInterface
157 * A mocked config storage. 159 * A mocked config storage.
158 */ 160 */
159 public function getConfigStorageStub(array $configs) { 161 public function getConfigStorageStub(array $configs) {
160 $config_storage = $this->getMock('Drupal\Core\Config\NullStorage'); 162 $config_storage = $this->createMock('Drupal\Core\Config\NullStorage');
161 $config_storage->expects($this->any()) 163 $config_storage->expects($this->any())
162 ->method('listAll') 164 ->method('listAll')
163 ->will($this->returnValue(array_keys($configs))); 165 ->will($this->returnValue(array_keys($configs)));
164 166
165 foreach ($configs as $name => $config) { 167 foreach ($configs as $name => $config) {
202 * 204 *
203 * @return \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\StringTranslation\TranslationInterface 205 * @return \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\StringTranslation\TranslationInterface
204 * A mock translation object. 206 * A mock translation object.
205 */ 207 */
206 public function getStringTranslationStub() { 208 public function getStringTranslationStub() {
207 $translation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface'); 209 $translation = $this->createMock('Drupal\Core\StringTranslation\TranslationInterface');
208 $translation->expects($this->any()) 210 $translation->expects($this->any())
209 ->method('translate') 211 ->method('translate')
210 ->willReturnCallback(function ($string, array $args = [], array $options = []) use ($translation) { 212 ->willReturnCallback(function ($string, array $args = [], array $options = []) use ($translation) {
211 return new TranslatableMarkup($string, $args, $options, $translation); 213 return new TranslatableMarkup($string, $args, $options, $translation);
212 }); 214 });
232 * 234 *
233 * @return \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit_Framework_MockObject_MockObject 235 * @return \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit_Framework_MockObject_MockObject
234 * The container with the cache tags invalidator service. 236 * The container with the cache tags invalidator service.
235 */ 237 */
236 protected function getContainerWithCacheTagsInvalidator(CacheTagsInvalidatorInterface $cache_tags_validator) { 238 protected function getContainerWithCacheTagsInvalidator(CacheTagsInvalidatorInterface $cache_tags_validator) {
237 $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); 239 $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
238 $container->expects($this->any()) 240 $container->expects($this->any())
239 ->method('get') 241 ->method('get')
240 ->with('cache_tags.invalidator') 242 ->with('cache_tags.invalidator')
241 ->will($this->returnValue($cache_tags_validator)); 243 ->will($this->returnValue($cache_tags_validator));
242 244
249 * 251 *
250 * @return \Drupal\Core\DependencyInjection\ClassResolverInterface|\PHPUnit_Framework_MockObject_MockObject 252 * @return \Drupal\Core\DependencyInjection\ClassResolverInterface|\PHPUnit_Framework_MockObject_MockObject
251 * The class resolver stub. 253 * The class resolver stub.
252 */ 254 */
253 protected function getClassResolverStub() { 255 protected function getClassResolverStub() {
254 $class_resolver = $this->getMock('Drupal\Core\DependencyInjection\ClassResolverInterface'); 256 $class_resolver = $this->createMock('Drupal\Core\DependencyInjection\ClassResolverInterface');
255 $class_resolver->expects($this->any()) 257 $class_resolver->expects($this->any())
256 ->method('getInstanceFromDefinition') 258 ->method('getInstanceFromDefinition')
257 ->will($this->returnCallback(function ($class) { 259 ->will($this->returnCallback(function ($class) {
258 if (is_subclass_of($class, 'Drupal\Core\DependencyInjection\ContainerInjectionInterface')) { 260 if (is_subclass_of($class, 'Drupal\Core\DependencyInjection\ContainerInjectionInterface')) {
259 return $class::create(new ContainerBuilder()); 261 return $class::create(new ContainerBuilder());