From 62afe77683720f5aff619786c2c78ad184404497 Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Thu, 23 Jan 2020 08:03:36 +1000 Subject: [PATCH] Issue #3097892 by mondrake, longwave, Berdir: Remove all @deprecated code in test base classes --- .../src/Functional/FileFieldTestBase.php | 9 -- .../migrate/source/ContentEntityTest.php | 2 +- ...ntEntityStorageSchemaConverterTestBase.php | 2 +- .../Update/WorkspacesUpdateTest.php | 6 +- .../WebDriverTestBase.php | 32 ----- .../BrowserTestBaseLegacyTest.php | 27 ---- .../Drupal/KernelTests/KernelTestBase.php | 91 ------------- .../PhpUnit6/FileFieldTestBaseTrait.php | 57 -------- .../PhpUnit6/TestCompatibilityTrait.php | 42 ------ .../PhpUnit7/FileFieldTestBaseTrait.php | 12 -- .../PhpUnit7/TestCompatibilityTrait.php | 42 ------ core/tests/Drupal/Tests/BrowserTestBase.php | 17 --- .../Assert/KernelAssertLegacyTraitTest.php | 31 ----- .../Tests/Core/Test/KernelTestBaseTest.php | 34 ----- .../Tests/PhpunitCompatibilityTrait.php | 127 ------------------ .../Tests/PhpunitCompatibilityTraitTest.php | 42 ------ core/tests/Drupal/Tests/UnitTestCase.php | 35 ----- .../Tests/UnitTestCaseDeprecationTest.php | 22 --- 18 files changed, 5 insertions(+), 625 deletions(-) delete mode 100644 core/tests/Drupal/FunctionalTests/BrowserTestBaseLegacyTest.php delete mode 100644 core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit6/FileFieldTestBaseTrait.php delete mode 100644 core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit6/TestCompatibilityTrait.php delete mode 100644 core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit7/FileFieldTestBaseTrait.php delete mode 100644 core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit7/TestCompatibilityTrait.php delete mode 100644 core/tests/Drupal/Tests/Core/Assert/KernelAssertLegacyTraitTest.php delete mode 100644 core/tests/Drupal/Tests/Core/Test/KernelTestBaseTest.php delete mode 100644 core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php delete mode 100644 core/tests/Drupal/Tests/PhpunitCompatibilityTraitTest.php delete mode 100644 core/tests/Drupal/Tests/UnitTestCaseDeprecationTest.php diff --git a/core/modules/file/tests/src/Functional/FileFieldTestBase.php b/core/modules/file/tests/src/Functional/FileFieldTestBase.php index 05f084ee347..ec855367925 100644 --- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\file\Functional; use Drupal\Component\Render\FormattableMarkup; -use Drupal\TestTools\PhpUnitCompatibility\RunnerVersion; use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldConfig; use Drupal\file\FileInterface; @@ -11,13 +10,6 @@ use Drupal\Tests\BrowserTestBase; use Drupal\file\Entity\File; use Drupal\Tests\TestFileCreationTrait; -// In order to manage different method signatures between PHPUnit versions, we -// dynamically load a compatibility trait dependent on the PHPUnit runner -// version. -if (!trait_exists(PhpunitVersionDependentFileFieldTestBaseTrait::class, FALSE)) { - class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit" . RunnerVersion::getMajor() . "\FileFieldTestBaseTrait", PhpunitVersionDependentFileFieldTestBaseTrait::class); -} - /** * Provides methods specifically for testing File module's field handling. */ @@ -27,7 +19,6 @@ abstract class FileFieldTestBase extends BrowserTestBase { use TestFileCreationTrait { getTestFiles as drupalGetTestFiles; } - use PhpunitVersionDependentFileFieldTestBaseTrait; /** * {@inheritdoc} diff --git a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php index 84bb7cae3b0..151bfb3ce61 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php @@ -107,7 +107,7 @@ class ContentEntityTest extends KernelTestBase { $this->installSchema('user', 'users_data'); $this->installSchema('file', 'file_usage'); $this->installSchema('node', ['node_access']); - $this->installConfig($this->modules); + $this->installConfig(static::$modules); ConfigurableLanguage::createFromLangcode('fr')->save(); diff --git a/core/modules/system/tests/src/Functional/Entity/Update/SqlContentEntityStorageSchemaConverterTestBase.php b/core/modules/system/tests/src/Functional/Entity/Update/SqlContentEntityStorageSchemaConverterTestBase.php index 33f2ca5cd18..f6084d23fe5 100644 --- a/core/modules/system/tests/src/Functional/Entity/Update/SqlContentEntityStorageSchemaConverterTestBase.php +++ b/core/modules/system/tests/src/Functional/Entity/Update/SqlContentEntityStorageSchemaConverterTestBase.php @@ -124,7 +124,7 @@ abstract class SqlContentEntityStorageSchemaConverterTestBase extends UpdatePath // Check that the correct initial value was provided for the // 'revision_translation_affected' field. - $this->assertTrue($revision->revision_translation_affected->value); + $this->assertTrue((bool) $revision->revision_translation_affected->value); $translation = $revision->getTranslation('ro'); diff --git a/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php b/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php index a518434163e..6d970ccc114 100644 --- a/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php +++ b/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php @@ -55,15 +55,15 @@ class WorkspacesUpdateTest extends UpdatePathTestBase { // Check that the 'workspace' field has been installed for an entity type // that was workspace-supported before Drupal 8.7.0. - $this->assertTrue($entity_definition_update_manager->getFieldStorageDefinition('workspace', 'node')); + $this->assertNotEmpty($entity_definition_update_manager->getFieldStorageDefinition('workspace', 'node')); // Check that the 'workspace' field has been installed for an entity type // which became workspace-supported as part of an entity schema update. - $this->assertTrue($entity_definition_update_manager->getFieldStorageDefinition('workspace', 'taxonomy_term')); + $this->assertNotEmpty($entity_definition_update_manager->getFieldStorageDefinition('workspace', 'taxonomy_term')); // Check that the 'workspace' field has been installed for an entity type // that has been added in an update function. - $this->assertTrue($entity_definition_update_manager->getFieldStorageDefinition('workspace', 'path_alias')); + $this->assertNotEmpty($entity_definition_update_manager->getFieldStorageDefinition('workspace', 'path_alias')); // Check that the 'workspace' revision metadata field has been created only // in the revision table. diff --git a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php index 7703e7e31f3..c855fca22c0 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php @@ -113,38 +113,6 @@ abstract class WebDriverTestBase extends BrowserTestBase { return parent::getMinkDriverArgs(); } - /** - * Asserts that the element with the given CSS selector is visible. - * - * @param string $css_selector - * The CSS selector identifying the element to check. - * @param string $message - * Optional message to show alongside the assertion. - * - * @deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. Use - * \Behat\Mink\Element\NodeElement::isVisible() instead. - */ - protected function assertElementVisible($css_selector, $message = '') { - $this->assertTrue($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message); - @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.1.0 and will be removed in 9.0.0. Use \Behat\Mink\Element\NodeElement::isVisible() instead.', E_USER_DEPRECATED); - } - - /** - * Asserts that the element with the given CSS selector is not visible. - * - * @param string $css_selector - * The CSS selector identifying the element to check. - * @param string $message - * Optional message to show alongside the assertion. - * - * @deprecated in drupal:8.1.0 and is removed from drupal:9.0.0. Use - * \Behat\Mink\Element\NodeElement::isVisible() instead. - */ - protected function assertElementNotVisible($css_selector, $message = '') { - $this->assertFalse($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message); - @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.1.0 and will be removed in 9.0.0. Use \Behat\Mink\Element\NodeElement::isVisible() instead.', E_USER_DEPRECATED); - } - /** * Waits for the given time or until the given JS condition becomes TRUE. * diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseLegacyTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseLegacyTest.php deleted file mode 100644 index 9834feefed1..00000000000 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseLegacyTest.php +++ /dev/null @@ -1,27 +0,0 @@ -getSession()->getResponseHeaders() instead. See https://www.drupal.org/node/3067207 - */ - public function testDrupalGetHeaders() { - $this->assertSame( - $this->getSession()->getResponseHeaders(), - $this->drupalGetHeaders() - ); - } - -} diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index 32914a58b39..17a6703ca71 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -19,7 +19,6 @@ use Drupal\Core\Site\Settings; use Drupal\Core\Test\TestDatabase; use Drupal\Tests\AssertHelperTrait; use Drupal\Tests\ConfigTestTrait; -use Drupal\Tests\PhpunitCompatibilityTrait; use Drupal\Tests\RandomGeneratorTrait; use Drupal\Tests\TestRequirementsTrait; use Drupal\TestTools\Comparator\MarkupInterfaceComparator; @@ -81,7 +80,6 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa use RandomGeneratorTrait; use ConfigTestTrait; use TestRequirementsTrait; - use PhpunitCompatibilityTrait; /** * {@inheritdoc} @@ -709,11 +707,6 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa foreach ($tables as $table) { $schema = drupal_get_module_schema($module, $table); if (empty($schema)) { - // BC layer to avoid some contrib tests to fail. - if ($module == 'system') { - @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/node/3003360.', E_USER_DEPRECATED); - continue; - } throw new \LogicException("$module module does not define a schema for table '$table'."); } $this->container->get('database')->schema()->createTable($table, $schema); @@ -781,12 +774,6 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa * If a module is not enabled after enabling it. */ protected function enableModules(array $modules) { - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - if ($trace[1]['function'] === 'setUp') { - trigger_error('KernelTestBase::enableModules() should not be called from setUp(). Use the $modules property instead.', E_USER_DEPRECATED); - } - unset($trace); - // Perform an ExtensionDiscovery scan as this function may receive a // profile that is not the current profile, and we don't yet have a cached // way to receive inactive profile information. @@ -913,10 +900,6 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa * \Drupal\Core\Site\Settings::get() to perform custom merges. */ protected function setSetting($name, $value) { - if ($name === 'install_profile') { - @trigger_error('Use \Drupal\KernelTests\KernelTestBase::setInstallProfile() to set the install profile in kernel tests. See https://www.drupal.org/node/2538996', E_USER_DEPRECATED); - $this->setInstallProfile($value); - } $settings = Settings::getInstance() ? Settings::getAll() : []; $settings[$name] = $value; new Settings($settings); @@ -1001,80 +984,6 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa ]); } - /** - * Returns whether the current test method is running in a separate process. - * - * Note that KernelTestBase will run in a separate process by default. - * - * @return bool - * - * @see \Drupal\KernelTests\KernelTestBase::$runTestInSeparateProcess - * @see https://github.com/sebastianbergmann/phpunit/pull/1350 - * - * @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. - * KernelTestBase tests are always run in isolated processes. - */ - protected function isTestInIsolation() { - @trigger_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated in Drupal 8.4.x, for removal before the Drupal 9.0.0 release. KernelTestBase tests are always run in isolated processes.', E_USER_DEPRECATED); - return function_exists('__phpunit_run_isolated_test'); - } - - /** - * BC: Automatically resolve former KernelTestBase class properties. - * - * Test authors should follow the provided instructions and adjust their tests - * accordingly. - * - * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. - */ - public function __get($name) { - if (in_array($name, [ - 'public_files_directory', - 'private_files_directory', - 'temp_files_directory', - 'translation_files_directory', - ])) { - // @comment it in again. - trigger_error(sprintf("KernelTestBase::\$%s no longer exists. Use the regular API method to retrieve it instead (e.g., Settings).", $name), E_USER_DEPRECATED); - switch ($name) { - case 'public_files_directory': - return Settings::get('file_public_path', \Drupal::service('site.path') . '/files'); - - case 'private_files_directory': - return Settings::get('file_private_path'); - - case 'temp_files_directory': - return \Drupal::service('file_system')->getTempDirectory(); - - case 'translation_files_directory': - return Settings::get('file_public_path', \Drupal::service('site.path') . '/translations'); - } - } - - $denied = [ - // @see \Drupal\simpletest\TestBase - 'testId', - 'timeLimit', - 'results', - 'assertions', - 'skipClasses', - 'verbose', - 'verboseId', - 'verboseClassName', - 'verboseDirectory', - 'verboseDirectoryUrl', - 'dieOnFail', - 'kernel', - // @see \Drupal\simpletest\TestBase::prepareEnvironment() - 'generatedTestFiles', - // Properties from the old KernelTestBase class that has been removed. - 'keyValueFactory', - ]; - if (in_array($name, $denied) || strpos($name, 'original') === 0) { - throw new \RuntimeException(sprintf('TestBase::$%s property no longer exists', $name)); - } - } - /** * Prevents serializing any properties. * diff --git a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit6/FileFieldTestBaseTrait.php b/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit6/FileFieldTestBaseTrait.php deleted file mode 100644 index 212485f90ca..00000000000 --- a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit6/FileFieldTestBaseTrait.php +++ /dev/null @@ -1,57 +0,0 @@ -getFileUri(); - } - $message = isset($message) ? $message : new FormattableMarkup('File %file exists on the disk.', ['%file' => $file]); - parent::assertFileExists($file, $message); - } - - /** - * Asserts that a file does not exist on disk. - * - * Overrides PHPUnit\Framework\Assert::assertFileNotExists() to also work - * with file entities. - * - * @param \Drupal\File\FileInterface|string $file - * Either the file entity or the file URI. - * @param string $message - * (optional) A message to display with the assertion. - * - * @see https://www.drupal.org/node/3057326 - */ - public static function assertFileNotExists($file, $message = NULL) { - if ($file instanceof FileInterface) { - @trigger_error('Passing a File entity as $file argument to FileFieldTestBase::assertFileNotExists is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Instead, pass the File entity URI via File::getFileUri(). See https://www.drupal.org/node/3057326', E_USER_DEPRECATED); - $file = $file->getFileUri(); - } - $message = isset($message) ? $message : new FormattableMarkup('File %file exists on the disk.', ['%file' => $file]); - parent::assertFileNotExists($file, $message); - } - -} diff --git a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit6/TestCompatibilityTrait.php b/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit6/TestCompatibilityTrait.php deleted file mode 100644 index e6d99e402ab..00000000000 --- a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit6/TestCompatibilityTrait.php +++ /dev/null @@ -1,42 +0,0 @@ -container->get('config.factory')->getEditable($name); } - /** - * Returns all response headers. - * - * @return array - * The HTTP headers values. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. - * Use $this->getSession()->getResponseHeaders() instead. - * - * @see https://www.drupal.org/node/3067207 - */ - protected function drupalGetHeaders() { - @trigger_error('Drupal\Tests\BrowserTestBase::drupalGetHeaders() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use $this->getSession()->getResponseHeaders() instead. See https://www.drupal.org/node/3067207', E_USER_DEPRECATED); - return $this->getSession()->getResponseHeaders(); - } - /** * Gets the value of an HTTP response header. * diff --git a/core/tests/Drupal/Tests/Core/Assert/KernelAssertLegacyTraitTest.php b/core/tests/Drupal/Tests/Core/Assert/KernelAssertLegacyTraitTest.php deleted file mode 100644 index 497bd342317..00000000000 --- a/core/tests/Drupal/Tests/Core/Assert/KernelAssertLegacyTraitTest.php +++ /dev/null @@ -1,31 +0,0 @@ -assertTrue(1); - } - - /** - * @expectedDeprecation Support for asserting against non-boolean values in ::assertFalse is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use a different assert method, for example, ::assertEmpty(). See https://www.drupal.org/node/3082086 - */ - public function testAssertFalse() { - $this->assertFalse(0); - } - -} diff --git a/core/tests/Drupal/Tests/Core/Test/KernelTestBaseTest.php b/core/tests/Drupal/Tests/Core/Test/KernelTestBaseTest.php deleted file mode 100644 index 837db3ab0a4..00000000000 --- a/core/tests/Drupal/Tests/Core/Test/KernelTestBaseTest.php +++ /dev/null @@ -1,34 +0,0 @@ -getMockBuilder(KernelTestBase::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - - $is_isolated = new \ReflectionMethod($kernel_test, 'isTestInIsolation'); - $is_isolated->setAccessible(TRUE); - - // Assert that the return value is a bool, because this unit test might or - // might not be running in process isolation. - $this->assertInternalType('bool', $is_isolated->invoke($kernel_test)); - } - -} diff --git a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php deleted file mode 100644 index 8b52d8707e1..00000000000 --- a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php +++ /dev/null @@ -1,127 +0,0 @@ -getMockBuilder($originalClassName) - ->setMethods($methods) - ->setConstructorArgs($arguments) - ->setMockClassName($mockClassName) - ->setProxyTarget($proxyTarget); - if ($callOriginalConstructor) { - $mock->enableOriginalConstructor(); - } - else { - $mock->disableOriginalConstructor(); - } - if ($callOriginalClone) { - $mock->enableOriginalClone(); - } - else { - $mock->disableOriginalClone(); - } - if ($callAutoload) { - $mock->enableAutoload(); - } - else { - $mock->disableAutoload(); - } - if ($cloneArguments) { - $mock->enableArgumentCloning(); - } - else { - $mock->disableArgumentCloning(); - } - if ($callOriginalMethods) { - $mock->enableProxyingToOriginalMethods(); - } - else { - $mock->disableProxyingToOriginalMethods(); - } - return $mock->getMock(); - } - - /** - * Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. - * - * @param mixed $class - * The expected exception class. - * @param string $message - * The expected exception message. - * @param int $exception_code - * The expected exception code. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. - * Backward compatibility for PHPUnit 4 will no longer be supported. - * - * @see https://www.drupal.org/node/3056869 - */ - public function setExpectedException($class, $message = '', $exception_code = NULL) { - @trigger_error('\Drupal\Tests\PhpunitCompatibilityTrait:setExpectedException() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Backward compatibility for PHPUnit 4 will no longer be supported. See https://www.drupal.org/node/3056869', E_USER_DEPRECATED); - $this->expectException($class); - if (!empty($message)) { - $this->expectExceptionMessage($message); - } - if ($exception_code !== NULL) { - $this->expectExceptionCode($exception_code); - } - } - -} diff --git a/core/tests/Drupal/Tests/PhpunitCompatibilityTraitTest.php b/core/tests/Drupal/Tests/PhpunitCompatibilityTraitTest.php deleted file mode 100644 index 03a25656ebe..00000000000 --- a/core/tests/Drupal/Tests/PhpunitCompatibilityTraitTest.php +++ /dev/null @@ -1,42 +0,0 @@ -assertInstanceOf('\Drupal\Tests\MockTestClassInterface', $this->getMock(MockTestClassInterface::class)); - } - - /** - * Tests that setExpectedException is available. - * - * @covers ::setExpectedException - * @group legacy - * @expectedDeprecation \Drupal\Tests\PhpunitCompatibilityTrait:setExpectedException() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Backward compatibility for PHPUnit 4 will no longer be supported. See https://www.drupal.org/node/3056869 - */ - public function testSetExpectedException() { - $expectedMessage = "Expected message"; - $expectedCode = 100; - $this->setExpectedException(\Exception::class, $expectedMessage, $expectedCode); - throw new \Exception($expectedMessage, $expectedCode); - } - -} - -interface MockTestClassInterface { - -} diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 2ca8ecfa104..f6cfaf4cbe5 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -18,8 +18,6 @@ use PHPUnit\Framework\TestCase; */ abstract class UnitTestCase extends TestCase { - use PhpunitCompatibilityTrait; - /** * The random generator. * @@ -185,39 +183,6 @@ abstract class UnitTestCase extends TestCase { return $config_storage; } - /** - * Mocks a block with a block plugin. - * - * @param string $machine_name - * The machine name of the block plugin. - * - * @return \Drupal\block\BlockInterface|\PHPUnit\Framework\MockObject\MockObject - * The mocked block. - * - * @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Unit test - * base classes should not have dependencies on extensions. Set up mocks in - * individual tests. - * - * @see https://www.drupal.org/node/2896072 - */ - protected function getBlockMockWithMachineName($machine_name) { - $plugin = $this->getMockBuilder('Drupal\Core\Block\BlockBase') - ->disableOriginalConstructor() - ->getMock(); - $plugin->expects($this->any()) - ->method('getMachineNameSuggestion') - ->will($this->returnValue($machine_name)); - - $block = $this->getMockBuilder('Drupal\block\Entity\Block') - ->disableOriginalConstructor() - ->getMock(); - $block->expects($this->any()) - ->method('getPlugin') - ->will($this->returnValue($plugin)); - @trigger_error(__METHOD__ . ' is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Unit test base classes should not have dependencies on extensions. Set up mocks in individual tests.', E_USER_DEPRECATED); - return $block; - } - /** * Returns a stub translation manager that just returns the passed string. * diff --git a/core/tests/Drupal/Tests/UnitTestCaseDeprecationTest.php b/core/tests/Drupal/Tests/UnitTestCaseDeprecationTest.php deleted file mode 100644 index 8ecb70ca2cf..00000000000 --- a/core/tests/Drupal/Tests/UnitTestCaseDeprecationTest.php +++ /dev/null @@ -1,22 +0,0 @@ -getBlockMockWithMachineName('test_name'); - $this->assertEquals('test_name', $block_mock->getPlugin()->getMachineNameSuggestion()); - } - -}