Issue #2933991 by alexpott, neclimdul: Deprecation tests fail when all PHPUnit tests are run via PHPUnit
parent
e538433ffc
commit
891c39b37c
|
@ -46,8 +46,7 @@ class LinkCckTest extends UnitTestCase {
|
|||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
* @expectedDeprecation CckFieldPluginBase is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.
|
||||
* @expectedDeprecation MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.
|
||||
* @expectedDeprecation LinkField is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\field\d6\LinkField instead.
|
||||
*/
|
||||
public function testProcessCckFieldValues() {
|
||||
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\deprecation_test\Deprecation;
|
||||
|
||||
@trigger_error(__NAMESPACE__ . '\DrupalStandardsListenerDeprecatedClass is deprecated.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Fixture class for use by DrupalStandardsListenerDeprecationTest.
|
||||
*
|
||||
* This class is arbitrarily deprecated in order to test the deprecation error
|
||||
* handling properties of DrupalStandardsListener.
|
||||
*
|
||||
* @see \Drupal\Tests\Core\Listeners\DrupalStandardsListenerDeprecationTest
|
||||
* @see \Drupal\Tests\Listeners\DrupalStandardsListener::endTest()
|
||||
*/
|
||||
class DrupalStandardsListenerDeprecatedClass {
|
||||
|
||||
/**
|
||||
* Returns a known value.
|
||||
*
|
||||
* @return string
|
||||
* A known return value.
|
||||
*/
|
||||
public function testFunction() {
|
||||
return 'test';
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
* DrupalStandardsListener has a dependency on composer/composer, so we can't
|
||||
* test it directly. However, we can create a test which is annotated as
|
||||
* covering a deprecated class. This way we can know whether the standards
|
||||
* listener process handles deprecation errors properly.
|
||||
* listener process ignores deprecation errors.
|
||||
*
|
||||
* Note that this test is annotated as covering
|
||||
* \Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass::testFunction(),
|
||||
|
@ -21,17 +21,14 @@ use Drupal\Tests\UnitTestCase;
|
|||
* would trigger another deprecation error.
|
||||
*
|
||||
* @group Listeners
|
||||
* @group legacy
|
||||
*
|
||||
* @coversDefaultClass \Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass
|
||||
* @coversDefaultClass \Drupal\deprecation_test\Deprecation\DrupalStandardsListenerDeprecatedClass
|
||||
*/
|
||||
class DrupalStandardsListenerDeprecationTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Exercise DrupalStandardsListener's coverage validation.
|
||||
*
|
||||
* @expectedDeprecation Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass is deprecated.
|
||||
*
|
||||
* @covers ::testFunction
|
||||
*/
|
||||
public function testDeprecation() {
|
||||
|
|
|
@ -21,8 +21,20 @@ trait DeprecationListenerTrait {
|
|||
*/
|
||||
protected function deprecationEndTest($test, $time) {
|
||||
/** @var \PHPUnit\Framework\Test $test */
|
||||
// Need to edit the file of deprecations.
|
||||
if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
|
||||
$util_test_class = class_exists('PHPUnit_Util_Test') ? 'PHPUnit_Util_Test' : 'PHPUnit\Util\Test';
|
||||
$method = $test->getName(FALSE);
|
||||
if (strpos($method, 'testLegacy') === 0
|
||||
|| strpos($method, 'provideLegacy') === 0
|
||||
|| strpos($method, 'getLegacy') === 0
|
||||
|| strpos(get_class($test), '\Legacy')
|
||||
|| in_array('legacy', $util_test_class::getGroups(get_class($test), $method), TRUE)) {
|
||||
// This is a legacy test don't skip deprecations.
|
||||
return;
|
||||
}
|
||||
|
||||
// Need to edit the file of deprecations to remove any skipped
|
||||
// deprecations.
|
||||
$deprecations = file_get_contents($file);
|
||||
$deprecations = $deprecations ? unserialize($deprecations) : [];
|
||||
$resave = FALSE;
|
||||
|
|
|
@ -143,6 +143,28 @@ trait DrupalStandardsListenerTrait {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles errors to ensure deprecation messages are not triggered.
|
||||
*
|
||||
* @param int $type
|
||||
* The severity level of the error.
|
||||
* @param string $msg
|
||||
* The error message.
|
||||
* @param $file
|
||||
* The file that caused the error.
|
||||
* @param $line
|
||||
* The line number that caused the error.
|
||||
* @param array $context
|
||||
* The error context.
|
||||
*/
|
||||
public static function errorHandler($type, $msg, $file, $line, $context = array()) {
|
||||
if ($type === E_USER_DEPRECATED) {
|
||||
return;
|
||||
}
|
||||
$error_handler = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_ErrorHandler' : 'PHPUnit\Util\ErrorHandler';
|
||||
return $error_handler::handleError($type, $msg, $file, $line, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reacts to the end of a test.
|
||||
*
|
||||
|
@ -166,7 +188,11 @@ trait DrupalStandardsListenerTrait {
|
|||
// our purpose, so we have to distinguish between the different known
|
||||
// subclasses.
|
||||
if ($test instanceof TestCase) {
|
||||
// Change the error handler to ensure deprecation messages are not
|
||||
// triggered.
|
||||
set_error_handler([$this, 'errorHandler']);
|
||||
$this->checkValidCoversForTest($test);
|
||||
restore_error_handler();
|
||||
}
|
||||
elseif ($this->isTestSuite($test)) {
|
||||
foreach ($test->getGroupDetails() as $tests) {
|
||||
|
|
Loading…
Reference in New Issue