Commit 71a80e78 authored by alexpott's avatar alexpott

Issue #3094151 by mondrake, swatichouhan012, dhirendra.mishra, ravi.shankar,...

Issue #3094151 by mondrake, swatichouhan012, dhirendra.mishra, ravi.shankar, longwave, alexpott: ExpectDeprecationTrait is not compatible with PHPUnit 8
parent 05a8d205
......@@ -208,8 +208,8 @@ public function testFileRemoval() {
*/
public function testAssertFileExistsDeprecation() {
if (RunnerVersion::getMajor() == 6) {
$this->expectDeprecation('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');
$this->expectDeprecation('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');
$this->addExpectedDeprecationMessage('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');
$this->addExpectedDeprecationMessage('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');
}
else {
$this->markTestSkipped('This test does not work in PHPUnit 7+ since assertFileExists only accepts string arguments for $file');
......
......@@ -109,7 +109,7 @@ protected function setUp() {
'd6_node_translation',
]);
$this->executeMigration(\Drupal::service('plugin.manager.migration')->createStubMigration($this->stubMigration));
$this->expectDeprecation('UrlAlias is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the entity:path_alias destination instead. See https://www.drupal.org/node/3013865');
$this->addExpectedDeprecationMessage('UrlAlias is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the entity:path_alias destination instead. See https://www.drupal.org/node/3013865');
}
}
......@@ -104,7 +104,7 @@ protected function setUp() {
'd7_node_translation',
]);
$this->executeMigration(\Drupal::service('plugin.manager.migration')->createStubMigration($this->stubMigration));
$this->expectDeprecation('UrlAlias is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the entity:path_alias destination instead. See https://www.drupal.org/node/3013865');
$this->addExpectedDeprecationMessage('UrlAlias is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the entity:path_alias destination instead. See https://www.drupal.org/node/3013865');
}
}
......@@ -25,7 +25,7 @@ public function testFormatSpecificGetBcRoute() {
// new and old sites, but trigger deprecation notices.
$bc_route = Url::fromRoute('rest.entity.' . static::$entityTypeId . '.GET.' . static::$format, $url->getRouteParameters(), $url->getOptions());
$bc_route->setUrlGenerator($this->container->get('url_generator'));
$this->expectDeprecation(sprintf("The 'rest.entity.entity_test.GET.%s' route is deprecated since version 8.5.x and will be removed in 9.0.0. Use the 'rest.entity.entity_test.GET' route instead.", static::$format));
$this->addExpectedDeprecationMessage(sprintf("The 'rest.entity.entity_test.GET.%s' route is deprecated since version 8.5.x and will be removed in 9.0.0. Use the 'rest.entity.entity_test.GET' route instead.", static::$format));
$this->assertSame($url->toString(TRUE)->getGeneratedUrl(), $bc_route->toString(TRUE)->getGeneratedUrl());
}
......
......@@ -74,7 +74,7 @@ public function testMakeRevisionable() {
$this->updateEntityTypeToRevisionable();
}
$this->expectDeprecation('\Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter is deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::updateFieldableEntityType() instead. See https://www.drupal.org/node/3029997.');
$this->addExpectedDeprecationMessage('\Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter is deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::updateFieldableEntityType() instead. See https://www.drupal.org/node/3029997.');
$this->runUpdates();
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_test_update */
......
......@@ -75,7 +75,7 @@ public function testGetContextValue() {
// It should be possible to access the context via the $contexts property,
// but it should trigger a deprecation notice.
$this->expectDeprecation('The $contexts property is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use methods of \Drupal\Component\Plugin\ContextAwarePluginInterface instead. See https://www.drupal.org/project/drupal/issues/3080631 for more information.');
$this->addExpectedDeprecationMessage('The $contexts property is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use methods of \Drupal\Component\Plugin\ContextAwarePluginInterface instead. See https://www.drupal.org/project/drupal/issues/3080631 for more information.');
$this->assertSame('Alpha', $this->plugin->contexts['nato_letter']->getContextValue());
}
......@@ -97,7 +97,7 @@ public function testSetContextValue() {
// Assert that setContextValue() did NOT update the deprecated $contexts
// property.
$this->expectDeprecation('The $contexts property is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use methods of \Drupal\Component\Plugin\ContextAwarePluginInterface instead. See https://www.drupal.org/project/drupal/issues/3080631 for more information.');
$this->addExpectedDeprecationMessage('The $contexts property is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use methods of \Drupal\Component\Plugin\ContextAwarePluginInterface instead. See https://www.drupal.org/project/drupal/issues/3080631 for more information.');
$this->assertArrayNotHasKey('foo', $this->plugin->contexts);
}
......
......@@ -479,7 +479,7 @@ public function testAccess() {
*/
public function testLabel() {
$this->expectDeprecation('Entity type ' . $this->entityTypeId . ' defines a label callback. Support for that is deprecated in drupal:8.0.0 and will be removed in drupal:9.0.0. Override the EntityInterface::label() method instead. See https://www.drupal.org/node/3050794');
$this->addExpectedDeprecationMessage('Entity type ' . $this->entityTypeId . ' defines a label callback. Support for that is deprecated in drupal:8.0.0 and will be removed in drupal:9.0.0. Override the EntityInterface::label() method instead. See https://www.drupal.org/node/3050794');
// Make a mock with one method that we use as the entity's label callback.
// We check that it is called, and that the entity's label is the callback's
......
......@@ -175,7 +175,7 @@ public function testBundle() {
*/
public function testLabel() {
$this->expectDeprecation('Entity type ' . $this->entityTypeId . ' defines a label callback. Support for that is deprecated in drupal:8.0.0 and will be removed in drupal:9.0.0. Override the EntityInterface::label() method instead. See https://www.drupal.org/node/3050794');
$this->addExpectedDeprecationMessage('Entity type ' . $this->entityTypeId . ' defines a label callback. Support for that is deprecated in drupal:8.0.0 and will be removed in drupal:9.0.0. Override the EntityInterface::label() method instead. See https://www.drupal.org/node/3050794');
// Make a mock with one method that we use as the entity's uri_callback. We
// check that it is called, and that the entity's label is the callback's
......
......@@ -168,7 +168,7 @@ public function testConfigDirectoriesBcLayer($settings_file_content, $directory,
->setContent($settings_file_content);
if ($expect_deprecation) {
$this->expectDeprecation('$config_directories[\'sync\'] has moved to $settings[\'config_sync_directory\']. See https://www.drupal.org/node/3018145.');
$this->addExpectedDeprecationMessage('$config_directories[\'sync\'] has moved to $settings[\'config_sync_directory\']. See https://www.drupal.org/node/3018145.');
}
Settings::initialize(vfsStream::url('root'), 'sites', $class_loader);
......
......@@ -14,23 +14,36 @@ class ExpectDeprecationTest extends UnitTestCase {
use ExpectDeprecationTrait;
/**
* @covers ::expectDeprecation
* @covers ::addExpectedDeprecationMessage
*/
public function testExpectDeprecation() {
$this->expectDeprecation('Test deprecation');
$this->addExpectedDeprecationMessage('Test deprecation');
@trigger_error('Test deprecation', E_USER_DEPRECATED);
}
/**
* @covers ::expectDeprecation
* @covers ::addExpectedDeprecationMessage
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testExpectDeprecationInIsolation() {
$this->expectDeprecation('Test isolated deprecation');
$this->expectDeprecation('Test isolated deprecation2');
$this->addExpectedDeprecationMessage('Test isolated deprecation');
$this->addExpectedDeprecationMessage('Test isolated deprecation2');
@trigger_error('Test isolated deprecation', E_USER_DEPRECATED);
@trigger_error('Test isolated deprecation2', E_USER_DEPRECATED);
}
/**
* @covers ::expectDeprecation
*
* @todo the expectedDeprecation annotation does not work if tests are marked
* skipped.
* @see https://github.com/symfony/symfony/pull/25757
*/
public function testDeprecatedExpectDeprecation() {
$this->addExpectedDeprecationMessage('ExpectDeprecationTrait::expectDeprecation is deprecated in drupal:8.8.4 and is removed from drupal:9.0.0. Use ::addExpectedDeprecationMessage() instead. See https://www.drupal.org/node/3106024');
$this->expectDeprecation('Test deprecated expectDeprecation');
@trigger_error('Test deprecated expectDeprecation', E_USER_DEPRECATED);
}
}
......@@ -25,10 +25,28 @@ trait ExpectDeprecationTrait {
* @param string $message
* The expected deprecation message.
*/
protected function expectDeprecation($message) {
protected function addExpectedDeprecationMessage($message) {
$this->expectedDeprecations([$message]);
}
/**
* Sets an expected deprecation message.
*
* @param string $message
* The expected deprecation message.
*
* @deprecated in drupal:8.8.4 and is removed from drupal:9.0.0. Use
* ::addExpectedDeprecationMessage() instead.
*
* @see https://www.drupal.org/node/3106024
*/
protected function expectDeprecation($message) {
if (strpos($message, 'ExpectDeprecationTrait::expectDeprecation') === FALSE) {
@trigger_error('ExpectDeprecationTrait::expectDeprecation is deprecated in drupal:8.8.4 and is removed from drupal:9.0.0. Use ::addExpectedDeprecationMessage() instead. See https://www.drupal.org/node/3106024', E_USER_DEPRECATED);
}
$this->addExpectedDeprecationMessage($message);
}
/**
* Sets expected deprecation messages.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment