comparison core/tests/Drupal/KernelTests/KernelTestBase.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
64 * @see \Drupal\Tests\KernelTestBase::enableModules() 64 * @see \Drupal\Tests\KernelTestBase::enableModules()
65 * @see \Drupal\Tests\KernelTestBase::installConfig() 65 * @see \Drupal\Tests\KernelTestBase::installConfig()
66 * @see \Drupal\Tests\KernelTestBase::installEntitySchema() 66 * @see \Drupal\Tests\KernelTestBase::installEntitySchema()
67 * @see \Drupal\Tests\KernelTestBase::installSchema() 67 * @see \Drupal\Tests\KernelTestBase::installSchema()
68 * @see \Drupal\Tests\BrowserTestBase 68 * @see \Drupal\Tests\BrowserTestBase
69 *
70 * @ingroup testing
69 */ 71 */
70 abstract class KernelTestBase extends TestCase implements ServiceProviderInterface { 72 abstract class KernelTestBase extends TestCase implements ServiceProviderInterface {
71 73
72 use AssertLegacyTrait; 74 use AssertLegacyTrait;
73 use AssertContentTrait; 75 use AssertContentTrait;
172 * @var \org\bovigo\vfs\vfsStreamDirectory 174 * @var \org\bovigo\vfs\vfsStreamDirectory
173 */ 175 */
174 protected $vfsRoot; 176 protected $vfsRoot;
175 177
176 /** 178 /**
177 * @var int
178 */
179 protected $expectedLogSeverity;
180
181 /**
182 * @var string
183 */
184 protected $expectedLogMessage;
185
186 /**
187 * @todo Move into Config test base class. 179 * @todo Move into Config test base class.
188 * @var \Drupal\Core\Config\ConfigImporter 180 * @var \Drupal\Core\Config\ConfigImporter
189 */ 181 */
190 protected $configImporter; 182 protected $configImporter;
191 183
338 } 330 }
339 // Add this test class as a service provider. 331 // Add this test class as a service provider.
340 $GLOBALS['conf']['container_service_providers']['test'] = $this; 332 $GLOBALS['conf']['container_service_providers']['test'] = $this;
341 333
342 $modules = self::getModulesToEnable(get_class($this)); 334 $modules = self::getModulesToEnable(get_class($this));
343
344 // Prepare a precompiled container for all tests of this class.
345 // Substantially improves performance, since ContainerBuilder::compile()
346 // is very expensive. Encourages testing best practices (small tests).
347 // Normally a setUpBeforeClass() operation, but object scope is required to
348 // inject $this test class instance as a service provider (see above).
349 $rc = new \ReflectionClass(get_class($this));
350 $test_method_count = count(array_filter($rc->getMethods(), function ($method) {
351 // PHPUnit's @test annotations are intentionally ignored/not supported.
352 return strpos($method->getName(), 'test') === 0;
353 }));
354 335
355 // Bootstrap the kernel. Do not use createFromRequest() to retain Settings. 336 // Bootstrap the kernel. Do not use createFromRequest() to retain Settings.
356 $kernel = new DrupalKernel('testing', $this->classLoader, FALSE); 337 $kernel = new DrupalKernel('testing', $this->classLoader, FALSE);
357 $kernel->setSitePath($this->siteDirectory); 338 $kernel->setSitePath($this->siteDirectory);
358 // Boot a new one-time container from scratch. Ensure to set the module list 339 // Boot a new one-time container from scratch. Ensure to set the module list
726 $tables = (array) $tables; 707 $tables = (array) $tables;
727 foreach ($tables as $table) { 708 foreach ($tables as $table) {
728 $schema = drupal_get_module_schema($module, $table); 709 $schema = drupal_get_module_schema($module, $table);
729 if (empty($schema)) { 710 if (empty($schema)) {
730 // BC layer to avoid some contrib tests to fail. 711 // BC layer to avoid some contrib tests to fail.
731 // @todo Remove the BC layer before 8.1.x release.
732 // @see https://www.drupal.org/node/2670360
733 // @see https://www.drupal.org/node/2670454
734 if ($module == 'system') { 712 if ($module == 'system') {
713 @trigger_error('Special handling of system module schemas in \Drupal\KernelTests\KernelTestBase::installSchema has been deprecated in Drupal 8.7.x, remove any calls to this method that use invalid schema names. See https://www.drupal.org/project/drupal/issues/2794347.', E_USER_DEPRECATED);
735 continue; 714 continue;
736 } 715 }
737 throw new \LogicException("$module module does not define a schema for table '$table'."); 716 throw new \LogicException("$module module does not define a schema for table '$table'.");
738 } 717 }
739 $this->container->get('database')->schema()->createTable($table, $schema); 718 $this->container->get('database')->schema()->createTable($table, $schema);
745 * 724 *
746 * @param string $entity_type_id 725 * @param string $entity_type_id
747 * The ID of the entity type. 726 * The ID of the entity type.
748 */ 727 */
749 protected function installEntitySchema($entity_type_id) { 728 protected function installEntitySchema($entity_type_id) {
750 /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ 729 $entity_type_manager = \Drupal::entityTypeManager();
751 $entity_manager = $this->container->get('entity.manager'); 730 $entity_type = $entity_type_manager->getDefinition($entity_type_id);
752 $entity_type = $entity_manager->getDefinition($entity_type_id); 731 \Drupal::service('entity_type.listener')->onEntityTypeCreate($entity_type);
753 $entity_manager->onEntityTypeCreate($entity_type);
754 732
755 // For test runs, the most common storage backend is a SQL database. For 733 // For test runs, the most common storage backend is a SQL database. For
756 // this case, ensure the tables got created. 734 // this case, ensure the tables got created.
757 $storage = $entity_manager->getStorage($entity_type_id); 735 $storage = $entity_type_manager->getStorage($entity_type_id);
758 if ($storage instanceof SqlEntityStorageInterface) { 736 if ($storage instanceof SqlEntityStorageInterface) {
759 $tables = $storage->getTableMapping()->getTableNames(); 737 $tables = $storage->getTableMapping()->getTableNames();
760 $db_schema = $this->container->get('database')->schema(); 738 $db_schema = $this->container->get('database')->schema();
761 $all_tables_exist = TRUE; 739 $all_tables_exist = TRUE;
762 foreach ($tables as $table) { 740 foreach ($tables as $table) {