Issue #3097892 by mondrake, longwave, Berdir: Remove all @deprecated code in test base classes

merge-requests/2419/head
Lee Rowlands 2020-01-23 08:03:36 +10:00
parent 75df2611dc
commit 62afe77683
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
18 changed files with 5 additions and 625 deletions

View File

@ -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}

View File

@ -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();

View File

@ -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');

View File

@ -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.

View File

@ -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.
*

View File

@ -1,27 +0,0 @@
<?php
namespace Drupal\FunctionalTests;
use Drupal\Tests\BrowserTestBase;
/**
* Tests BrowserTestBase legacy functionality.
*
* @group browsertestbase
* @group legacy
*/
class BrowserTestBaseLegacyTest extends BrowserTestBase {
/**
* Test ::drupalGetHeaders().
*
* @expectedDeprecation 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
*/
public function testDrupalGetHeaders() {
$this->assertSame(
$this->getSession()->getResponseHeaders(),
$this->drupalGetHeaders()
);
}
}

View File

@ -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.
*

View File

@ -1,57 +0,0 @@
<?php
namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit6;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\file\FileInterface;
/**
* Makes Drupal's test API forward compatible with multiple versions of PHPUnit.
*/
trait FileFieldTestBaseTrait {
/**
* Asserts that a file exists physically on disk.
*
* Overrides PHPUnit\Framework\Assert::assertFileExists() 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 assertFileExists($file, $message = NULL) {
if ($file instanceof FileInterface) {
@trigger_error('Passing a File entity as $file argument to FileFieldTestBase::assertFileExists 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::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);
}
}

View File

@ -1,42 +0,0 @@
<?php
namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit6;
/**
* Makes Drupal's test API forward compatible with multiple versions of PHPUnit.
*/
trait TestCompatibilityTrait {
/**
* @todo deprecate this method override in
* https://www.drupal.org/project/drupal/issues/2742585
*
* @see \Drupal\simpletest\TestBase::assertTrue()
*/
public static function assertTrue($actual, $message = '') {
if (is_bool($actual)) {
parent::assertTrue($actual, $message);
}
else {
@trigger_error('Support for asserting against non-boolean values in ::assertTrue is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use a different assert method, for example, ::assertNotEmpty(). See https://www.drupal.org/node/3082086', E_USER_DEPRECATED);
parent::assertNotEmpty($actual, $message);
}
}
/**
* @todo deprecate this method override in
* https://www.drupal.org/project/drupal/issues/2742585
*
* @see \Drupal\simpletest\TestBase::assertFalse()
*/
public static function assertFalse($actual, $message = '') {
if (is_bool($actual)) {
parent::assertFalse($actual, $message);
}
else {
@trigger_error('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', E_USER_DEPRECATED);
parent::assertEmpty($actual, $message);
}
}
}

View File

@ -1,12 +0,0 @@
<?php
namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit7;
/**
* Makes Drupal's test API forward compatible with multiple versions of PHPUnit.
*/
trait FileFieldTestBaseTrait {
// @todo remove in Drupal 9.
}

View File

@ -1,42 +0,0 @@
<?php
namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit7;
/**
* Makes Drupal's test API forward compatible with multiple versions of PHPUnit.
*/
trait TestCompatibilityTrait {
/**
* @todo deprecate this method override in
* https://www.drupal.org/project/drupal/issues/2742585
*
* @see \Drupal\simpletest\TestBase::assertTrue()
*/
public static function assertTrue($actual, string $message = ''): void {
if (is_bool($actual)) {
parent::assertTrue($actual, $message);
}
else {
@trigger_error('Support for asserting against non-boolean values in ::assertTrue is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use a different assert method, for example, ::assertNotEmpty(). See https://www.drupal.org/node/3082086', E_USER_DEPRECATED);
parent::assertNotEmpty($actual, $message);
}
}
/**
* @todo deprecate this method override in
* https://www.drupal.org/project/drupal/issues/2742585
*
* @see \Drupal\simpletest\TestBase::assertFalse()
*/
public static function assertFalse($actual, string $message = ''): void {
if (is_bool($actual)) {
parent::assertFalse($actual, $message);
}
else {
@trigger_error('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', E_USER_DEPRECATED);
parent::assertEmpty($actual, $message);
}
}
}

View File

@ -63,7 +63,6 @@ abstract class BrowserTestBase extends TestCase {
createUser as drupalCreateUser;
}
use XdebugRequestTrait;
use PhpunitCompatibilityTrait;
/**
* The database prefix of this test run.
@ -645,22 +644,6 @@ abstract class BrowserTestBase extends TestCase {
return $this->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.
*

View File

@ -1,31 +0,0 @@
<?php
namespace Drupal\Tests\Core\Assert;
use Drupal\KernelTests\AssertLegacyTrait;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\KernelTests\AssertLegacyTrait
* @group Assert
* @group legacy
*/
class KernelAssertLegacyTraitTest extends UnitTestCase {
use AssertLegacyTrait;
/**
* @expectedDeprecation Support for asserting against non-boolean values in ::assertTrue is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use a different assert method, for example, ::assertNotEmpty(). See https://www.drupal.org/node/3082086
*/
public function testAssertTrue() {
$this->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);
}
}

View File

@ -1,34 +0,0 @@
<?php
namespace Drupal\Tests\Core\Test;
use Drupal\Tests\UnitTestCase;
use Drupal\KernelTests\KernelTestBase;
/**
* @group Test
* @group legacy
*
* @coversDefaultClass \Drupal\KernelTests\KernelTestBase
*/
class KernelTestBaseTest extends UnitTestCase {
/**
* @expectedDeprecation Drupal\KernelTests\KernelTestBase::isTestInIsolation() is deprecated in Drupal 8.4.x, for removal before the Drupal 9.0.0 release. KernelTestBase tests are always run in isolated processes.
*
* @covers ::isTestInIsolation
*/
public function testDeprecatedIsTestInIsolation() {
$kernel_test = $this->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));
}
}

View File

@ -1,127 +0,0 @@
<?php
namespace Drupal\Tests;
use Drupal\TestTools\PhpUnitCompatibility\RunnerVersion;
// 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(PhpunitVersionDependentTestCompatibilityTrait::class, FALSE)) {
class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit" . RunnerVersion::getMajor() . "\TestCompatibilityTrait", PhpunitVersionDependentTestCompatibilityTrait::class);
}
/**
* Makes Drupal's test API forward compatible with multiple versions of PHPUnit.
*/
trait PhpunitCompatibilityTrait {
use PhpunitVersionDependentTestCompatibilityTrait;
/**
* Returns a mock object for the specified class using the available method.
*
* The getMock method does not exist in PHPUnit 6. To provide backward
* compatibility this trait provides the getMock method and uses createMock if
* this method is available on the parent class.
*
* @param string $originalClassName
* Name of the class to mock.
* @param array|null $methods
* When provided, only methods whose names are in the array are replaced
* with a configurable test double. The behavior of the other methods is not
* changed. Providing null means that no methods will be replaced.
* @param array $arguments
* Parameters to pass to the original class' constructor.
* @param string $mockClassName
* Class name for the generated test double class.
* @param bool $callOriginalConstructor
* Can be used to disable the call to the original class' constructor.
* @param bool $callOriginalClone
* Can be used to disable the call to the original class' clone constructor.
* @param bool $callAutoload
* Can be used to disable __autoload() during the generation of the test
* double class.
* @param bool $cloneArguments
* Enables the cloning of arguments passed to mocked methods.
* @param bool $callOriginalMethods
* Enables the invocation of the original methods.
* @param object $proxyTarget
* Sets the proxy target.
*
* @see https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0
*
* @return \PHPUnit\Framework\MockObject\MockObject
*
* @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0.
* Use \Drupal\Tests\PhpunitCompatibilityTrait::createMock() instead.
*
* @see https://www.drupal.org/node/2907725
*/
public function getMock($originalClassName, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE, $cloneArguments = FALSE, $callOriginalMethods = FALSE, $proxyTarget = NULL) {
@trigger_error('\Drupal\Tests\PhpunitCompatibilityTrait::getMock() is deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use \Drupal\Tests\PhpunitCompatibilityTrait::createMock() instead. See https://www.drupal.org/node/2907725', E_USER_DEPRECATED);
$mock = $this->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);
}
}
}

View File

@ -1,42 +0,0 @@
<?php
namespace Drupal\Tests;
/**
* Tests the PHPUnit forward compatibility trait.
*
* @coversDefaultClass \Drupal\Tests\PhpunitCompatibilityTrait
* @group Tests
*/
class PhpunitCompatibilityTraitTest extends UnitTestCase {
/**
* Tests that getMock is available.
*
* @covers ::getMock
* @group legacy
* @expectedDeprecation \Drupal\Tests\PhpunitCompatibilityTrait::getMock() is deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use \Drupal\Tests\PhpunitCompatibilityTrait::createMock() instead. See https://www.drupal.org/node/2907725
*/
public function testGetMock() {
$this->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 {
}

View File

@ -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.
*

View File

@ -1,22 +0,0 @@
<?php
namespace Drupal\Tests;
/**
* @coversDefaultClass \Drupal\Tests\UnitTestCase
*
* @group Test
* @group legacy
*/
class UnitTestCaseDeprecationTest extends UnitTestCase {
/**
* @covers ::getBlockMockWithMachineName
* @expectedDeprecation Drupal\Tests\UnitTestCase::getBlockMockWithMachineName 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.
*/
public function testDeprecatedGetBlockMockWithMachineName() {
$block_mock = $this->getBlockMockWithMachineName('test_name');
$this->assertEquals('test_name', $block_mock->getPlugin()->getMachineNameSuggestion());
}
}