Issue #2878248 by Mile23, dawehner: DrupalStandardsListener improper handling of @trigger_error() deprecation
parent
16c5a8fa21
commit
1160fbbec4
|
@ -0,0 +1,6 @@
|
|||
name: 'Deprecation test'
|
||||
type: module
|
||||
description: 'Support module for testing deprecation behaviors.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\deprecation_test\Deprecation;
|
||||
|
||||
@trigger_error(__NAMESPACE__ . '\FixtureDeprecatedClass 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 FixtureDeprecatedClass {
|
||||
|
||||
/**
|
||||
* Returns a known value.
|
||||
*
|
||||
* @return string
|
||||
* A known return value.
|
||||
*/
|
||||
public function testFunction() {
|
||||
return 'test';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\Core\Listeners;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Test deprecation error handling by DrupalStandardsListener.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Note that this test is annotated as covering
|
||||
* \Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass::testFunction(),
|
||||
* but the reason the test exists is to cover
|
||||
* \Drupal\Tests\Listeners\DrupalStandardsListener::endTest(). We never
|
||||
* actually instantiate
|
||||
* \Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass because that
|
||||
* would trigger another deprecation error.
|
||||
*
|
||||
* @group Listeners
|
||||
*
|
||||
* @coversDefaultClass \Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass
|
||||
*/
|
||||
class DrupalStandardsListenerDeprecationTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Exercise DrupalStandardsListener's coverage validation.
|
||||
*
|
||||
* @covers ::testFunction
|
||||
*/
|
||||
public function testDeprecation() {
|
||||
// Meaningless assertion so this test is not risky.
|
||||
$this->assertTrue(TRUE);
|
||||
}
|
||||
|
||||
}
|
|
@ -142,6 +142,16 @@ class DrupalStandardsListener extends BaseTestListener {
|
|||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* We must mark this method as belonging to the special legacy group because
|
||||
* it might trigger an E_USER_DEPRECATED error during coverage annotation
|
||||
* validation. The legacy group allows symfony/phpunit-bridge to keep the
|
||||
* deprecation notice as a warning instead of an error, which would fail the
|
||||
* test.
|
||||
*
|
||||
* @group legacy
|
||||
*
|
||||
* @see http://symfony.com/doc/current/components/phpunit_bridge.html#mark-tests-as-legacy
|
||||
*/
|
||||
public function endTest(\PHPUnit_Framework_Test $test, $time) {
|
||||
// \PHPUnit_Framework_Test does not have any useful methods of its own for
|
||||
|
|
Loading…
Reference in New Issue