29
0
mirror of https://github.com/joomla/joomla-cms.git synced 2024-06-20 11:05:08 +00:00

Implement a deprecation message handler for the unit test library

Based on Symfony's PhpUnit bridge, this handler will catch E_USER_DEPRECATED and E_DEPRECATED messages triggered while running the unit test suite and display them at the end of the test output.  This removes the need to silence deprecation messages in the unit test bootstrap and gives contributors an idea of deprecated code uses either in the core PHP platform or libraries.

Implementing this exposed a call to a non-static method in a static manner which only affects the unit test suite, this is also corrected.
This commit is contained in:
Michael Babker 2015-06-13 21:58:09 -04:00
parent 52197b772f
commit f3fafab417
7 changed files with 485 additions and 89 deletions

View File

@ -18,9 +18,9 @@ services:
before_script:
# - composer update
# Install PHPCS to validate code standards
- composer require squizlabs/php_codesniffer 1.5.6
- composer require --dev squizlabs/php_codesniffer 1.5.6
# Install Cache_Lite for testing
- composer require pear/cache_lite 1.7.16
- composer require --dev pear/cache_lite 1.7.16
# Set up databases for testing
- mysql -e 'create database joomla_ut;'
- mysql joomla_ut < tests/unit/schema/mysql.sql
@ -34,7 +34,7 @@ before_script:
- sh -c "if [ '$TRAVIS_PHP_VERSION' != '7.0' ]; then phpenv config-add build/travis/phpenv/redis.ini; fi"
script:
- phpunit --configuration travisci-phpunit.xml
- libraries/vendor/bin/phpunit --configuration travisci-phpunit.xml
- sh -c "if [ '$TRAVIS_PHP_VERSION' != '7.0' ]; then libraries/vendor/bin/phpcs --report=full --extensions=php -p --standard=build/phpcs/Joomla .; fi"
branches:

View File

@ -24,7 +24,7 @@
"symfony/yaml": "2.*"
},
"require-dev": {
"phpunit/phpunit": "4.1.*",
"phpunit/phpunit": "4.*",
"phpunit/dbunit": "~1.3"
}
}

367
composer.lock generated
View File

@ -1,10 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "a305fbfdb073d809dbff32a3210e110f",
"hash": "850180786c5c3bacf8fe5e157664d0e6",
"packages": [
{
"name": "ircmaxell/password-compat",
@ -737,6 +737,169 @@
}
],
"packages-dev": [
{
"name": "doctrine/instantiator",
"version": "1.0.4",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "f976e5de371104877ebc89bd8fecb0019ed9c119"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119",
"reference": "f976e5de371104877ebc89bd8fecb0019ed9c119",
"shasum": ""
},
"require": {
"php": ">=5.3,<8.0-DEV"
},
"require-dev": {
"athletic/athletic": "~0.1.8",
"ext-pdo": "*",
"ext-phar": "*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "2.0.*@ALPHA"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-0": {
"Doctrine\\Instantiator\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com",
"homepage": "http://ocramius.github.com/"
}
],
"description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
"homepage": "https://github.com/doctrine/instantiator",
"keywords": [
"constructor",
"instantiate"
],
"time": "2014-10-13 12:58:55"
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "2.0.4",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8",
"reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"suggest": {
"dflydev/markdown": "~1.0",
"erusev/parsedown": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-0": {
"phpDocumentor": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mike van Riel",
"email": "mike.vanriel@naenius.com"
}
],
"time": "2015-02-03 12:10:50"
},
{
"name": "phpspec/prophecy",
"version": "v1.4.1",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373",
"reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
"phpdocumentor/reflection-docblock": "~2.0",
"sebastian/comparator": "~1.1"
},
"require-dev": {
"phpspec/phpspec": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"psr-0": {
"Prophecy\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Konstantin Kudryashov",
"email": "ever.zet@gmail.com",
"homepage": "http://everzet.com"
},
{
"name": "Marcello Duarte",
"email": "marcello.duarte@gmail.com"
}
],
"description": "Highly opinionated mocking framework for PHP 5.3+",
"homepage": "https://github.com/phpspec/prophecy",
"keywords": [
"Double",
"Dummy",
"fake",
"mock",
"spy",
"stub"
],
"time": "2015-04-27 22:15:08"
},
{
"name": "phpunit/dbunit",
"version": "1.3.1",
@ -798,16 +961,16 @@
},
{
"name": "phpunit/php-code-coverage",
"version": "2.0.15",
"version": "2.1.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "34cc484af1ca149188d0d9e91412191e398e0b67"
"reference": "be2286cb8c7e1773eded49d9719219e6f74f9e3e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/34cc484af1ca149188d0d9e91412191e398e0b67",
"reference": "34cc484af1ca149188d0d9e91412191e398e0b67",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be2286cb8c7e1773eded49d9719219e6f74f9e3e",
"reference": "be2286cb8c7e1773eded49d9719219e6f74f9e3e",
"shasum": ""
},
"require": {
@ -830,7 +993,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "2.1.x-dev"
}
},
"autoload": {
@ -856,35 +1019,37 @@
"testing",
"xunit"
],
"time": "2015-01-24 10:06:35"
"time": "2015-06-09 13:05:42"
},
{
"name": "phpunit/php-file-iterator",
"version": "1.3.4",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "acd690379117b042d1c8af1fafd61bde001bf6bb"
"reference": "a923bb15680d0089e2316f7a4af8f437046e96bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb",
"reference": "acd690379117b042d1c8af1fafd61bde001bf6bb",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb",
"reference": "a923bb15680d0089e2316f7a4af8f437046e96bb",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"classmap": [
"File/"
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
@ -901,7 +1066,7 @@
"filesystem",
"iterator"
],
"time": "2013-10-10 15:34:57"
"time": "2015-04-02 05:19:05"
},
{
"name": "phpunit/php-text-template",
@ -949,16 +1114,16 @@
},
{
"name": "phpunit/php-timer",
"version": "1.0.5",
"version": "1.0.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git",
"reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c"
"reference": "83fe1bdc5d47658b727595c14da140da92b3d66d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
"reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d",
"reference": "83fe1bdc5d47658b727595c14da140da92b3d66d",
"shasum": ""
},
"require": {
@ -967,13 +1132,10 @@
"type": "library",
"autoload": {
"classmap": [
"PHP/"
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
@ -989,20 +1151,20 @@
"keywords": [
"timer"
],
"time": "2013-08-02 07:42:54"
"time": "2015-06-13 07:35:30"
},
{
"name": "phpunit/php-token-stream",
"version": "1.4.0",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74"
"reference": "db63be1159c81df649cd0260e30249a586d4129e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db32c18eba00b121c145575fcbcd4d4d24e6db74",
"reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db63be1159c81df649cd0260e30249a586d4129e",
"reference": "db63be1159c81df649cd0260e30249a586d4129e",
"shasum": ""
},
"require": {
@ -1038,20 +1200,20 @@
"keywords": [
"tokenizer"
],
"time": "2015-01-17 09:51:32"
"time": "2015-06-12 07:34:24"
},
{
"name": "phpunit/phpunit",
"version": "4.1.6",
"version": "4.7.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "241116219bb7e3b8111a36ffd8f37546888738d6"
"reference": "41fea1e84ed84d373f5ac099a1276c4358c90708"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/241116219bb7e3b8111a36ffd8f37546888738d6",
"reference": "241116219bb7e3b8111a36ffd8f37546888738d6",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/41fea1e84ed84d373f5ac099a1276c4358c90708",
"reference": "41fea1e84ed84d373f5ac099a1276c4358c90708",
"shasum": ""
},
"require": {
@ -1061,17 +1223,19 @@
"ext-reflection": "*",
"ext-spl": "*",
"php": ">=5.3.3",
"phpunit/php-code-coverage": "~2.0",
"phpunit/php-file-iterator": "~1.3.1",
"phpspec/prophecy": "~1.3,>=1.3.1",
"phpunit/php-code-coverage": "~2.1",
"phpunit/php-file-iterator": "~1.4",
"phpunit/php-text-template": "~1.2",
"phpunit/php-timer": "~1.0.2",
"phpunit/phpunit-mock-objects": "2.1.5",
"sebastian/comparator": "~1.0",
"sebastian/diff": "~1.1",
"sebastian/environment": "~1.0",
"sebastian/exporter": "~1.0",
"phpunit/php-timer": "~1.0",
"phpunit/phpunit-mock-objects": "~2.3",
"sebastian/comparator": "~1.1",
"sebastian/diff": "~1.2",
"sebastian/environment": "~1.2",
"sebastian/exporter": "~1.2",
"sebastian/global-state": "~1.0",
"sebastian/version": "~1.0",
"symfony/yaml": "~2.0"
"symfony/yaml": "~2.1|~3.0"
},
"suggest": {
"phpunit/php-invoker": "~1.1"
@ -1082,7 +1246,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.1.x-dev"
"dev-master": "4.7.x-dev"
}
},
"autoload": {
@ -1091,10 +1255,6 @@
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"",
"../../symfony/yaml/"
],
"license": [
"BSD-3-Clause"
],
@ -1106,34 +1266,35 @@
}
],
"description": "The PHP Unit Testing framework.",
"homepage": "http://www.phpunit.de/",
"homepage": "https://phpunit.de/",
"keywords": [
"phpunit",
"testing",
"xunit"
],
"time": "2014-08-17 08:07:02"
"time": "2015-06-11 16:20:25"
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "2.1.5",
"version": "2.3.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "7878b9c41edb3afab92b85edf5f0981014a2713a"
"reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/7878b9c41edb3afab92b85edf5f0981014a2713a",
"reference": "7878b9c41edb3afab92b85edf5f0981014a2713a",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/92408bb1968a81b3217a6fdf6c1a198da83caa35",
"reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35",
"shasum": ""
},
"require": {
"doctrine/instantiator": "~1.0,>=1.0.2",
"php": ">=5.3.3",
"phpunit/php-text-template": "~1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.1"
"phpunit/phpunit": "~4.4"
},
"suggest": {
"ext-soap": "*"
@ -1141,7 +1302,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
"dev-master": "2.3.x-dev"
}
},
"autoload": {
@ -1150,9 +1311,6 @@
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
@ -1169,7 +1327,7 @@
"mock",
"xunit"
],
"time": "2014-06-12 07:22:15"
"time": "2015-06-11 15:55:48"
},
{
"name": "sebastian/comparator",
@ -1237,16 +1395,16 @@
},
{
"name": "sebastian/diff",
"version": "1.2.0",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "5843509fed39dee4b356a306401e9dd1a931fec7"
"reference": "863df9687835c62aa423a22412d26fa2ebde3fd3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7",
"reference": "5843509fed39dee4b356a306401e9dd1a931fec7",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3",
"reference": "863df9687835c62aa423a22412d26fa2ebde3fd3",
"shasum": ""
},
"require": {
@ -1258,7 +1416,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2-dev"
"dev-master": "1.3-dev"
}
},
"autoload": {
@ -1285,32 +1443,32 @@
"keywords": [
"diff"
],
"time": "2014-08-15 10:29:00"
"time": "2015-02-22 15:13:53"
},
{
"name": "sebastian/environment",
"version": "1.2.1",
"version": "1.2.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
"reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7"
"reference": "5a8c7d31914337b69923db26c4221b81ff5a196e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6e6c71d918088c251b181ba8b3088af4ac336dd7",
"reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e",
"reference": "5a8c7d31914337b69923db26c4221b81ff5a196e",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.3"
"phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.3.x-dev"
}
},
"autoload": {
@ -1335,7 +1493,7 @@
"environment",
"hhvm"
],
"time": "2014-10-25 08:00:45"
"time": "2015-01-01 10:01:08"
},
{
"name": "sebastian/exporter",
@ -1403,6 +1561,57 @@
],
"time": "2015-01-27 07:23:06"
},
{
"name": "sebastian/global-state",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/global-state.git",
"reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01",
"reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"suggest": {
"ext-uopz": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Snapshotting of global state",
"homepage": "http://www.github.com/sebastianbergmann/global-state",
"keywords": [
"global state"
],
"time": "2014-10-06 09:23:50"
},
{
"name": "sebastian/recursion-context",
"version": "1.0.0",
@ -1458,16 +1667,16 @@
},
{
"name": "sebastian/version",
"version": "1.0.4",
"version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/version.git",
"reference": "a77d9123f8e809db3fbdea15038c27a95da4058b"
"reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/version/zipball/a77d9123f8e809db3fbdea15038c27a95da4058b",
"reference": "a77d9123f8e809db3fbdea15038c27a95da4058b",
"url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4",
"reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4",
"shasum": ""
},
"type": "library",
@ -1489,7 +1698,7 @@
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2014-12-15 14:25:24"
"time": "2015-02-24 06:35:25"
}
],
"aliases": [],

View File

@ -351,7 +351,7 @@ class ClassLoader
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
@ -361,7 +361,7 @@ class ClassLoader
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
@ -380,7 +380,7 @@ class ClassLoader
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
@ -390,7 +390,7 @@ class ClassLoader
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}

View File

@ -31,7 +31,7 @@ ini_set('magic_quotes_runtime', 0);
// Maximise error reporting.
ini_set('zend.ze1_compatibility_mode', '0');
error_reporting(E_ALL & ~(E_STRICT|E_USER_DEPRECATED));
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Set fixed precision value to avoid round related issues
@ -114,3 +114,6 @@ require_once JPATH_LIBRARIES . '/cms.php';
// Register the core Joomla test classes.
JLoader::registerPrefix('Test', __DIR__ . '/core');
// Register the deprecation handler
TestHelper::registerDeprecationHandler();

View File

@ -0,0 +1,184 @@
<?php
/**
* @package Joomla.Test
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
/**
* Class with general helper methods for testing
*
* @since 3.5
*/
class TestHelper
{
/**
* Internal flag to track if the deprecation handler has been registered
*
* @var boolean
* @since 3.5
*/
private static $isDeprecationHandlerRegistered = false;
/**
* Registers a message handler to catch deprecation errors
*
* This method is based on \Symfony\Bridge\PhpUnit\DeprecationErrorHandler::register()
*
* @return void
*
* @since 3.5
*/
public static function registerDeprecationHandler()
{
if (self::$isDeprecationHandlerRegistered)
{
return;
}
$deprecations = array(
'phpCount' => 0,
'userCount' => 0,
'php' => array(),
'user' => array(),
);
$deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations)
{
// Check if the type is E_DEPRECATED or E_USER_DEPRECATED
if (!in_array($type, array(E_DEPRECATED, E_USER_DEPRECATED)))
{
return PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
}
$trace = debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT : true);
$i = count($trace);
while (isset($trace[--$i]['class']) && ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_')))
{
// Nothing to do
}
$group = $type === E_USER_DEPRECATED ? 'user' : 'php';
if (isset($trace[$i]['object']) || isset($trace[$i]['class']))
{
$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
$method = $trace[$i]['function'];
$ref =& $deprecations[$group][$msg]['count'];
$ref++;
$ref =& $deprecations[$group][$msg][$class . '::' . $method];
$ref++;
}
else
{
$ref =& $deprecations[$group][$msg]['count'];
$ref++;
}
$deprecations[$group . 'Count']++;
};
$oldErrorHandler = set_error_handler($deprecationHandler);
if (null !== $oldErrorHandler)
{
restore_error_handler();
if (array('PHPUnit_Util_ErrorHandler', 'handleError') === $oldErrorHandler)
{
restore_error_handler();
self::register();
}
}
else
{
self::$isDeprecationHandlerRegistered = true;
if (self::hasColorSupport())
{
$colorize = function ($str, $red)
{
$color = $red ? '41;37' : '43;30';
return "\x1B[{$color}m{$str}\x1B[0m";
};
}
else
{
$colorize = function ($str)
{
return $str;
};
}
register_shutdown_function(function () use (&$deprecations, $deprecationHandler, $colorize)
{
$currErrorHandler = set_error_handler('var_dump');
restore_error_handler();
if ($currErrorHandler !== $deprecationHandler)
{
echo "\n", $colorize('THE ERROR HANDLER HAS CHANGED!', true), "\n";
}
$cmp = function ($a, $b)
{
return $b['count'] - $a['count'];
};
foreach (array('php', 'user') as $group)
{
if ($deprecations[$group . 'Count'])
{
echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group . 'Count']), true), "\n";
uasort($deprecations[$group], $cmp);
foreach ($deprecations[$group] as $msg => $notices)
{
echo "\n", rtrim($msg, '.'), ': ', $notices['count'], "x\n";
arsort($notices);
foreach ($notices as $method => $count)
{
if ('count' !== $method)
{
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
}
}
}
}
}
if (!empty($notices))
{
echo "\n";
}
});
}
}
/**
* Detects if the CLI output supports color codes
*
* This method is based on \Symfony\Bridge\PhpUnit\DeprecationErrorHandler::register()
*
* @return boolean
*
* @since 3.5
*/
private static function hasColorSupport()
{
if (DIRECTORY_SEPARATOR === '\\')
{
return getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON';
}
return defined('STDOUT') && function_exists('posix_isatty') && @posix_isatty(STDOUT);
}
}

View File

@ -133,7 +133,7 @@ class TestMockInput
*
* @since 3.4
*/
public function mockInputGet($name, $default = null, $filter = 'cmd')
public static function mockInputGet($name, $default = null, $filter = 'cmd')
{
return isset(self::$inputs[$name]) ? self::$inputs[$name] : $default;
}