Skip to content

Commit 1b21647

Browse files
feature symfony#18232 [Bridge\PhpUnit] Add "disabled" mode to SYMFONY_DEPRECATIONS_HELPER (nicolas-grekas)
This PR was merged into the 3.1-dev branch. Discussion ---------- [Bridge\PhpUnit] Add "disabled" mode to SYMFONY_DEPRECATIONS_HELPER | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#18222 | License | MIT | Doc PR | - See https://github.com/symfony/symfony/pull/18232/files?w=1 Because we keep adding features to the bridge, so that one could want some features but not the deprecations helper. In weak mode, this PR also disables colors. Fetching the SYMFONY_DEPRECATIONS_HELPER env var is also done lazily to workaround old phpunit versions affected by sebastianbergmann/phpunit#1216 Commits ------- 64fe539 [Bridge\PhpUnit] Add "disabled" mode to SYMFONY_DEPRECATIONS_HELPER
2 parents a4af637 + 64fe539 commit 1b21647

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ services:
3737
- redis-server
3838

3939
before_install:
40+
- mkdir /tmp/slapd
41+
- slapd -f src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf -h ldap://localhost:3389 &
4042
# Matrix lines for intermediate PHP versions are skipped for pull requests
4143
- if [[ ! $deps && ! $TRAVIS_PHP_VERSION = ${MIN_PHP%.*} && $TRAVIS_PHP_VERSION != hhvm && $TRAVIS_PULL_REQUEST != false ]]; then deps=skip; fi;
4244
# A sigchild-enabled-PHP is used to test the Process component on the lowest PHP matrix line
@@ -57,9 +59,6 @@ before_install:
5759
- if [[ $deps != skip && $TRAVIS_REPO_SLUG = symfony/symfony ]]; then cp .composer/* ~/.composer/; composer global install; fi;
5860
- if [[ $deps != skip ]]; then ./phpunit install; fi;
5961
- export PHPUNIT=$(readlink -f ./phpunit)
60-
- mkdir /tmp/slapd
61-
- slapd -f src/Symfony/Component/Ldap/Tests/Fixtures/conf/slapd.conf -h ldap://localhost:3389 &
62-
- sleep 3
6362
- ldapadd -h localhost:3389 -D cn=admin,dc=symfony,dc=com -w symfony -f src/Symfony/Component/Ldap/Tests/Fixtures/data/base.ldif
6463
- ldapadd -h localhost:3389 -D cn=admin,dc=symfony,dc=com -w symfony -f src/Symfony/Component/Ldap/Tests/Fixtures/data/fixtures.ldif
6564

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
class DeprecationErrorHandler
2020
{
2121
const MODE_WEAK = 'weak';
22+
const MODE_DISABLED = 'disabled';
2223

2324
private static $isRegistered = false;
2425

@@ -67,11 +68,10 @@ public static function register($mode = 0)
6768
'other' => array(),
6869
);
6970
$deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations, $getMode) {
70-
if (E_USER_DEPRECATED !== $type) {
71+
if (E_USER_DEPRECATED !== $type || DeprecationErrorHandler::MODE_DISABLED === $mode = $getMode()) {
7172
return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
7273
}
7374

74-
$mode = $getMode();
7575
$trace = debug_backtrace(true);
7676
$group = 'other';
7777

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Test DeprecationErrorHandler in weak mode
3+
--FILE--
4+
<?php
5+
6+
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
7+
putenv('ANSICON');
8+
putenv('ConEmuANSI');
9+
putenv('TERM');
10+
11+
$vendor = __DIR__;
12+
while (!file_exists($vendor.'/vendor')) {
13+
$vendor = dirname($vendor);
14+
}
15+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
16+
require PHPUNIT_COMPOSER_INSTALL;
17+
require_once __DIR__.'/../../bootstrap.php';
18+
19+
echo (int) set_error_handler('var_dump');
20+
echo (int) class_exists('Symfony\Bridge\PhpUnit\DeprecationErrorHandler', false);
21+
22+
?>
23+
--EXPECTF--
24+
00

src/Symfony/Bridge/PhpUnit/Tests/DnsMockTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
use Symfony\Bridge\PhpUnit\DnsMock;
1515

16-
require_once __DIR__.'/../DnsMock.php';
17-
1816
class DnsMockTest extends \PHPUnit_Framework_TestCase
1917
{
2018
protected function tearDown()

src/Symfony/Bridge/PhpUnit/bootstrap.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424
AnnotationRegistry::registerLoader('class_exists');
2525
}
2626

27-
DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER'));
27+
if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) {
28+
DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER'));
29+
}

0 commit comments

Comments
 (0)