Commit 574f8617 authored by catch's avatar catch

Issue #3157434 by alexpott, jungle, dww, mondrake: Deprecate...

Issue #3157434 by alexpott, jungle, dww, mondrake: Deprecate \Drupal\Tests\Traits\ExpectDeprecationTrait in favour of \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait
parent c3152e5a
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "70ccf971aa2cc71e172543e89d868b90",
"content-hash": "c6355fee8b620a19067108002e315194",
"packages": [
{
"name": "asm89/stack-cors",
......@@ -183,16 +183,6 @@
"zend",
"zikula"
],
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2020-04-07T06:57:05+00:00"
},
{
......@@ -385,20 +375,6 @@
"parser",
"php"
],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer",
"type": "tidelift"
}
],
"time": "2020-05-25T17:44:05+00:00"
},
{
......@@ -1348,12 +1324,6 @@
"laminas",
"zf"
],
"funding": [
{
"url": "https://funding.communitybridge.org/projects/laminas-project",
"type": "community_bridge"
}
],
"time": "2020-05-20T16:45:56+00:00"
},
{
......@@ -4487,16 +4457,6 @@
"ssl",
"tls"
],
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2020-04-08T08:27:21+00:00"
},
{
......@@ -4762,20 +4722,6 @@
"constructor",
"instantiate"
],
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator",
"type": "tidelift"
}
],
"time": "2020-05-29T17:27:14+00:00"
},
{
......@@ -6477,16 +6423,6 @@
"parser",
"validator"
],
"funding": [
{
"url": "https://github.com/Seldaek",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/seld/jsonlint",
"type": "tidelift"
}
],
"time": "2020-04-30T19:05:18+00:00"
},
{
......@@ -7007,16 +6943,16 @@
},
{
"name": "symfony/phpunit-bridge",
"version": "v5.1.2",
"version": "v5.1.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/phpunit-bridge.git",
"reference": "de5f0fec631a0cbfe98630b053be1fad7b75aece"
"reference": "964bd57046dfa48687e1412fe5f8006adfcb9675"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/de5f0fec631a0cbfe98630b053be1fad7b75aece",
"reference": "de5f0fec631a0cbfe98630b053be1fad7b75aece",
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/964bd57046dfa48687e1412fe5f8006adfcb9675",
"reference": "964bd57046dfa48687e1412fe5f8006adfcb9675",
"shasum": ""
},
"require": {
......@@ -7068,9 +7004,6 @@
],
"description": "Symfony PHPUnit Bridge",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/phpunit-bridge/tree/v5.1.1"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
......@@ -7085,7 +7018,7 @@
"type": "tidelift"
}
],
"time": "2020-06-09T09:56:30+00:00"
"time": "2020-07-23T09:26:24+00:00"
},
{
"name": "theseer/tokenizer",
......
......@@ -24,6 +24,6 @@
"symfony/filesystem": "^4.4",
"symfony/finder": "^4.4",
"symfony/lock": "^4.4",
"symfony/phpunit-bridge": "^5.1"
"symfony/phpunit-bridge": "^5.1.3"
}
}
......@@ -57,7 +57,7 @@
"symfony/filesystem": "v4.4.10",
"symfony/finder": "v4.4.10",
"symfony/lock": "v4.4.10",
"symfony/phpunit-bridge": "v5.1.2",
"symfony/phpunit-bridge": "v5.1.3",
"theseer/tokenizer": "1.1.3",
"webmozart/assert": "1.9.0"
}
......
......@@ -4,13 +4,10 @@
use Drupal\entity_test\Entity\EntityTestMapField;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\user\Entity\User;
abstract class EntityTestMapFieldResourceTestBase extends EntityResourceTestBase {
use ExpectDeprecationTrait;
/**
* {@inheritdoc}
*/
......
......@@ -5,13 +5,11 @@
use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\user\Entity\User;
abstract class EntityTestResourceTestBase extends EntityResourceTestBase {
use EntityDefinitionTestTrait;
use ExpectDeprecationTrait;
/**
* {@inheritdoc}
......
......@@ -14,7 +14,6 @@
use Drupal\Core\TypedData\Plugin\DataType\StringData;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
/**
* @coversDefaultClass \Drupal\Core\Plugin\ContextAwarePluginBase
......@@ -23,8 +22,6 @@
*/
class ContextAwarePluginBaseTest extends KernelTestBase {
use ExpectDeprecationTrait;
/**
* The plugin instance under test.
*
......
......@@ -12,7 +12,6 @@
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Language\Language;
use Symfony\Component\Validator\Validator\ValidatorInterface;
......@@ -24,8 +23,6 @@
*/
class ContentEntityBaseUnitTest extends UnitTestCase {
use ExpectDeprecationTrait;
/**
* The bundle of the entity under test.
*
......
......@@ -10,7 +10,6 @@
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
use Drupal\Core\Language\Language;
use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\Tests\UnitTestCase;
/**
......@@ -20,8 +19,6 @@
*/
class EntityUnitTest extends UnitTestCase {
use ExpectDeprecationTrait;
/**
* The entity under test.
*
......
......@@ -3,7 +3,6 @@
namespace Drupal\Tests\Core\Render;
use Drupal\Core\Security\UntrustedCallbackException;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
/**
* @coversDefaultClass \Drupal\Core\Render\Renderer
......@@ -11,8 +10,6 @@
*/
class RendererCallbackTest extends RendererTestBase {
use ExpectDeprecationTrait;
/**
* {@inheritdoc}
*/
......
......@@ -3,9 +3,9 @@
namespace Drupal\Tests\Core\Site;
use Drupal\Core\Site\Settings;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
/**
* @coversDefaultClass \Drupal\Core\Site\Settings
......@@ -202,7 +202,7 @@ public function testFakeDeprecatedSettings(array $settings_config, string $setti
$instance_property->setValue($deprecated_settings);
if ($expect_deprecation_message) {
$this->addExpectedDeprecationMessage($deprecated_setting['message']);
$this->expectDeprecation($deprecated_setting['message']);
}
Settings::initialize(vfsStream::url('root'), 'sites', $class_loader);
......
......@@ -4,7 +4,6 @@
use Drupal\Core\Site\Settings;
use Drupal\Core\StackMiddleware\ReverseProxyMiddleware;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
......@@ -14,7 +13,6 @@
* @group StackMiddleware
*/
class ReverseProxyMiddlewareTest extends UnitTestCase {
use ExpectDeprecationTrait;
/**
* @var \Symfony\Component\HttpKernel\HttpKernelInterface|\PHPUnit\Framework\MockObject\MockObject
......
......@@ -9,12 +9,17 @@
*
* @group Test
* @group legacy
*
* Do not remove this test when \Drupal\Tests\Traits\ExpectDeprecationTrait is
* removed. Change it to use \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait
* instead to ensure Drupal has test coverage of Symfony's deprecation testing.
*/
class ExpectDeprecationTest extends UnitTestCase {
use ExpectDeprecationTrait;
/**
* @covers ::addExpectedDeprecationMessage
* @expectedDeprecation Drupal\Tests\Traits\ExpectDeprecationTrait::addExpectedDeprecationMessage() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait::expectDeprecation() instead. See https://www.drupal.org/node/3161901
*/
public function testExpectDeprecation() {
$this->addExpectedDeprecationMessage('Test deprecation');
......@@ -25,10 +30,12 @@ public function testExpectDeprecation() {
* @covers ::addExpectedDeprecationMessage
* @runInSeparateProcess
* @preserveGlobalState disabled
* @expectedDeprecation Drupal\Tests\Traits\ExpectDeprecationTrait::addExpectedDeprecationMessage() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait::expectDeprecation() instead. See https://www.drupal.org/node/3161901
* @expectedDeprecation Drupal\Tests\Traits\ExpectDeprecationTrait::expectedDeprecations() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait::expectDeprecation() instead. See https://www.drupal.org/node/3161901
*/
public function testExpectDeprecationInIsolation() {
$this->addExpectedDeprecationMessage('Test isolated deprecation');
$this->addExpectedDeprecationMessage('Test isolated deprecation2');
$this->expectedDeprecations(['Test isolated deprecation2']);
@trigger_error('Test isolated deprecation', E_USER_DEPRECATED);
@trigger_error('Test isolated deprecation2', E_USER_DEPRECATED);
}
......
......@@ -2,8 +2,6 @@
namespace Drupal\Tests\Listeners;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Test;
/**
......@@ -15,8 +13,6 @@
*/
trait DeprecationListenerTrait {
use ExpectDeprecationTrait;
/**
* The previous error handler.
*
......@@ -24,14 +20,6 @@ trait DeprecationListenerTrait {
*/
private $previousHandler;
protected function deprecationStartTest($test) {
if ($test instanceof TestCase) {
if ($this->willBeIsolated($test)) {
putenv('DRUPAL_EXPECTED_DEPRECATIONS_SERIALIZE=' . tempnam(sys_get_temp_dir(), 'exdep'));
}
}
}
/**
* Reacts to the end of a test.
*
......@@ -42,13 +30,6 @@ protected function deprecationStartTest($test) {
*/
protected function deprecationEndTest($test, $time) {
/** @var \PHPUnit\Framework\Test $test */
if ($file = getenv('DRUPAL_EXPECTED_DEPRECATIONS_SERIALIZE')) {
putenv('DRUPAL_EXPECTED_DEPRECATIONS_SERIALIZE');
$expected_deprecations = file_get_contents($file);
if ($expected_deprecations) {
$test->expectedDeprecations(unserialize($expected_deprecations));
}
}
if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
$method = $test->getName(FALSE);
if (strpos($method, 'testLegacy') === 0
......@@ -77,26 +58,6 @@ protected function deprecationEndTest($test, $time) {
}
}
/**
* Determines if a test is isolated.
*
* @param \PHPUnit\Framework\TestCase $test
* The test to check.
*
* @return bool
* TRUE if the isolated, FALSE if not.
*/
private function willBeIsolated($test) {
if ($test->isInIsolation()) {
return FALSE;
}
$r = new \ReflectionProperty($test, 'runTestInSeparateProcess');
$r->setAccessible(TRUE);
return $r->getValue($test);
}
/**
* Determines if a deprecation error should be skipped.
*
......
......@@ -81,7 +81,6 @@ public function startTest(Test $test): void {
// \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::startTest()
// that handles expected deprecations.
$this->registerErrorHandler();
$this->deprecationStartTest($test);
$this->symfonyListener->startTest($test);
// Check for missing void return typehints in concrete test classes'
// methods. If the method is inherited from a base test class, do
......
......@@ -2,17 +2,20 @@
namespace Drupal\Tests\Traits;
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait as SymfonyExpectDeprecationTrait;
/**
* Adds the ability to dynamically set expected deprecation messages in tests.
*
* @internal
*
* @todo https://www.drupal.org/project/drupal/issues/3157434 Deprecate the
* trait and its methods.
* @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
* \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead.
*
* @see https://www.drupal.org/node/3161901
*/
trait ExpectDeprecationTrait {
use SymfonyExpectDeprecationTrait;
/**
* Sets an expected deprecation message.
......@@ -21,7 +24,8 @@ trait ExpectDeprecationTrait {
* The expected deprecation message.
*/
protected function addExpectedDeprecationMessage($message) {
$this->expectedDeprecations([$message]);
@trigger_error(__METHOD__ . '() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait::expectDeprecation() instead. See https://www.drupal.org/node/3161901', E_USER_DEPRECATED);
$this->expectDeprecation($message);
}
/**
......@@ -33,29 +37,9 @@ protected function addExpectedDeprecationMessage($message) {
* @see \Symfony\Bridge\PhpUnit\Legacy\ExpectDeprecationTraitForV8_4::expectDeprecation()
*/
public function expectedDeprecations(array $messages) {
$this->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(FALSE);
// Expected deprecations set by isolated tests need to be written to a file
// so that the test running process can take account of them.
if ($file = getenv('DRUPAL_EXPECTED_DEPRECATIONS_SERIALIZE')) {
$expected_deprecations = file_get_contents($file);
if ($expected_deprecations) {
$expected_deprecations = array_merge(unserialize($expected_deprecations), $messages);
}
else {
$expected_deprecations = $messages;
}
file_put_contents($file, serialize($expected_deprecations));
}
else {
// Copy code from ExpectDeprecationTraitForV8_4::expectDeprecation().
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
}
foreach ($messages as $message) {
SymfonyTestsListenerTrait::$expectedDeprecations[] = $message;
}
@trigger_error(__METHOD__ . '() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait::expectDeprecation() instead. See https://www.drupal.org/node/3161901', E_USER_DEPRECATED);
foreach ($messages as $message) {
$this->expectDeprecation($message);
}
}
......
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