Merge branch '4.4' into 5.0
* 4.4: [PhpUnitBridge] cs fix
This commit is contained in:
commit
2e27c4fdf4
@ -94,7 +94,7 @@ class ClockMock
|
|||||||
{
|
{
|
||||||
$self = \get_called_class();
|
$self = \get_called_class();
|
||||||
|
|
||||||
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
|
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
|
||||||
if (0 < strpos($class, '\\Tests\\')) {
|
if (0 < strpos($class, '\\Tests\\')) {
|
||||||
$ns = str_replace('\\Tests\\', '\\', $class);
|
$ns = str_replace('\\Tests\\', '\\', $class);
|
||||||
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
|
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
|
||||||
|
@ -16,8 +16,8 @@ namespace Symfony\Bridge\PhpUnit;
|
|||||||
*/
|
*/
|
||||||
class DnsMock
|
class DnsMock
|
||||||
{
|
{
|
||||||
private static $hosts = array();
|
private static $hosts = [];
|
||||||
private static $dnsTypes = array(
|
private static $dnsTypes = [
|
||||||
'A' => DNS_A,
|
'A' => DNS_A,
|
||||||
'MX' => DNS_MX,
|
'MX' => DNS_MX,
|
||||||
'NS' => DNS_NS,
|
'NS' => DNS_NS,
|
||||||
@ -30,7 +30,7 @@ class DnsMock
|
|||||||
'NAPTR' => DNS_NAPTR,
|
'NAPTR' => DNS_NAPTR,
|
||||||
'TXT' => DNS_TXT,
|
'TXT' => DNS_TXT,
|
||||||
'HINFO' => DNS_HINFO,
|
'HINFO' => DNS_HINFO,
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the mock values for DNS queries.
|
* Configures the mock values for DNS queries.
|
||||||
@ -68,7 +68,7 @@ class DnsMock
|
|||||||
if (!self::$hosts) {
|
if (!self::$hosts) {
|
||||||
return \getmxrr($hostname, $mxhosts, $weight);
|
return \getmxrr($hostname, $mxhosts, $weight);
|
||||||
}
|
}
|
||||||
$mxhosts = $weight = array();
|
$mxhosts = $weight = [];
|
||||||
|
|
||||||
if (isset(self::$hosts[$hostname])) {
|
if (isset(self::$hosts[$hostname])) {
|
||||||
foreach (self::$hosts[$hostname] as $record) {
|
foreach (self::$hosts[$hostname] as $record) {
|
||||||
@ -125,7 +125,7 @@ class DnsMock
|
|||||||
$ips = false;
|
$ips = false;
|
||||||
|
|
||||||
if (isset(self::$hosts[$hostname])) {
|
if (isset(self::$hosts[$hostname])) {
|
||||||
$ips = array();
|
$ips = [];
|
||||||
|
|
||||||
foreach (self::$hosts[$hostname] as $record) {
|
foreach (self::$hosts[$hostname] as $record) {
|
||||||
if ('A' === $record['type']) {
|
if ('A' === $record['type']) {
|
||||||
@ -149,11 +149,11 @@ class DnsMock
|
|||||||
if (DNS_ANY === $type) {
|
if (DNS_ANY === $type) {
|
||||||
$type = DNS_ALL;
|
$type = DNS_ALL;
|
||||||
}
|
}
|
||||||
$records = array();
|
$records = [];
|
||||||
|
|
||||||
foreach (self::$hosts[$hostname] as $record) {
|
foreach (self::$hosts[$hostname] as $record) {
|
||||||
if (isset(self::$dnsTypes[$record['type']]) && (self::$dnsTypes[$record['type']] & $type)) {
|
if (isset(self::$dnsTypes[$record['type']]) && (self::$dnsTypes[$record['type']] & $type)) {
|
||||||
$records[] = array_merge(array('host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']), $record);
|
$records[] = array_merge(['host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']], $record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ class DnsMock
|
|||||||
{
|
{
|
||||||
$self = \get_called_class();
|
$self = \get_called_class();
|
||||||
|
|
||||||
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
|
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
|
||||||
if (0 < strpos($class, '\\Tests\\')) {
|
if (0 < strpos($class, '\\Tests\\')) {
|
||||||
$ns = str_replace('\\Tests\\', '\\', $class);
|
$ns = str_replace('\\Tests\\', '\\', $class);
|
||||||
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
|
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
|
||||||
|
@ -23,7 +23,7 @@ class CommandForV5 extends \PHPUnit_TextUI_Command
|
|||||||
*/
|
*/
|
||||||
protected function createRunner()
|
protected function createRunner()
|
||||||
{
|
{
|
||||||
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : array();
|
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : [];
|
||||||
|
|
||||||
$registeredLocally = false;
|
$registeredLocally = false;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class CoverageListenerTrait
|
|||||||
{
|
{
|
||||||
$this->sutFqcnResolver = $sutFqcnResolver;
|
$this->sutFqcnResolver = $sutFqcnResolver;
|
||||||
$this->warningOnSutNotFound = $warningOnSutNotFound;
|
$this->warningOnSutNotFound = $warningOnSutNotFound;
|
||||||
$this->warnings = array();
|
$this->warnings = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function startTest($test)
|
public function startTest($test)
|
||||||
@ -43,7 +43,7 @@ class CoverageListenerTrait
|
|||||||
|
|
||||||
$annotations = $test->getAnnotations();
|
$annotations = $test->getAnnotations();
|
||||||
|
|
||||||
$ignoredAnnotations = array('covers', 'coversDefaultClass', 'coversNothing');
|
$ignoredAnnotations = ['covers', 'coversDefaultClass', 'coversNothing'];
|
||||||
|
|
||||||
foreach ($ignoredAnnotations as $annotation) {
|
foreach ($ignoredAnnotations as $annotation) {
|
||||||
if (isset($annotations['class'][$annotation]) || isset($annotations['method'][$annotation])) {
|
if (isset($annotations['class'][$annotation]) || isset($annotations['method'][$annotation])) {
|
||||||
@ -70,11 +70,11 @@ class CoverageListenerTrait
|
|||||||
$r->setAccessible(true);
|
$r->setAccessible(true);
|
||||||
|
|
||||||
$cache = $r->getValue();
|
$cache = $r->getValue();
|
||||||
$cache = array_replace_recursive($cache, array(
|
$cache = array_replace_recursive($cache, [
|
||||||
\get_class($test) => array(
|
\get_class($test) => [
|
||||||
'covers' => \is_array($sutFqcn) ? $sutFqcn : array($sutFqcn),
|
'covers' => \is_array($sutFqcn) ? $sutFqcn : [$sutFqcn],
|
||||||
),
|
],
|
||||||
));
|
]);
|
||||||
$r->setValue(Test::class, $cache);
|
$r->setValue(Test::class, $cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class SymfonyTestsListenerForV5 extends \PHPUnit_Framework_BaseTestListener
|
|||||||
{
|
{
|
||||||
private $trait;
|
private $trait;
|
||||||
|
|
||||||
public function __construct(array $mockedNamespaces = array())
|
public function __construct(array $mockedNamespaces = [])
|
||||||
{
|
{
|
||||||
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
|
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ namespace Symfony\Bridge\PhpUnit\Legacy;
|
|||||||
use PHPUnit\Framework\BaseTestListener;
|
use PHPUnit\Framework\BaseTestListener;
|
||||||
use PHPUnit\Framework\Test;
|
use PHPUnit\Framework\Test;
|
||||||
use PHPUnit\Framework\TestSuite;
|
use PHPUnit\Framework\TestSuite;
|
||||||
use PHPUnit\Framework\Warning;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects and replays skipped tests.
|
* Collects and replays skipped tests.
|
||||||
@ -27,7 +26,7 @@ class SymfonyTestsListenerForV6 extends BaseTestListener
|
|||||||
{
|
{
|
||||||
private $trait;
|
private $trait;
|
||||||
|
|
||||||
public function __construct(array $mockedNamespaces = array())
|
public function __construct(array $mockedNamespaces = [])
|
||||||
{
|
{
|
||||||
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
|
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ use PHPUnit\Framework\Test;
|
|||||||
use PHPUnit\Framework\TestListener;
|
use PHPUnit\Framework\TestListener;
|
||||||
use PHPUnit\Framework\TestListenerDefaultImplementation;
|
use PHPUnit\Framework\TestListenerDefaultImplementation;
|
||||||
use PHPUnit\Framework\TestSuite;
|
use PHPUnit\Framework\TestSuite;
|
||||||
use PHPUnit\Framework\Warning;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects and replays skipped tests.
|
* Collects and replays skipped tests.
|
||||||
@ -30,7 +29,7 @@ class SymfonyTestsListenerForV7 implements TestListener
|
|||||||
|
|
||||||
private $trait;
|
private $trait;
|
||||||
|
|
||||||
public function __construct(array $mockedNamespaces = array())
|
public function __construct(array $mockedNamespaces = [])
|
||||||
{
|
{
|
||||||
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
|
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@ class SymfonyTestsListenerTrait
|
|||||||
private static $globallyEnabled = false;
|
private static $globallyEnabled = false;
|
||||||
private $state = -1;
|
private $state = -1;
|
||||||
private $skippedFile = false;
|
private $skippedFile = false;
|
||||||
private $wasSkipped = array();
|
private $wasSkipped = [];
|
||||||
private $isSkipped = array();
|
private $isSkipped = [];
|
||||||
private $expectedDeprecations = array();
|
private $expectedDeprecations = [];
|
||||||
private $gatheredDeprecations = array();
|
private $gatheredDeprecations = [];
|
||||||
private $previousErrorHandler;
|
private $previousErrorHandler;
|
||||||
private $error;
|
private $error;
|
||||||
private $runsInSeparateProcess = false;
|
private $runsInSeparateProcess = false;
|
||||||
@ -46,7 +46,7 @@ class SymfonyTestsListenerTrait
|
|||||||
/**
|
/**
|
||||||
* @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive)
|
* @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive)
|
||||||
*/
|
*/
|
||||||
public function __construct(array $mockedNamespaces = array())
|
public function __construct(array $mockedNamespaces = [])
|
||||||
{
|
{
|
||||||
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait'] = 2;
|
Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait'] = 2;
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class SymfonyTestsListenerTrait
|
|||||||
|
|
||||||
foreach ($mockedNamespaces as $type => $namespaces) {
|
foreach ($mockedNamespaces as $type => $namespaces) {
|
||||||
if (!\is_array($namespaces)) {
|
if (!\is_array($namespaces)) {
|
||||||
$namespaces = array($namespaces);
|
$namespaces = [$namespaces];
|
||||||
}
|
}
|
||||||
if ('time-sensitive' === $type) {
|
if ('time-sensitive' === $type) {
|
||||||
foreach ($namespaces as $ns) {
|
foreach ($namespaces as $ns) {
|
||||||
@ -140,11 +140,11 @@ class SymfonyTestsListenerTrait
|
|||||||
|
|
||||||
if (!$this->wasSkipped = require $this->skippedFile) {
|
if (!$this->wasSkipped = require $this->skippedFile) {
|
||||||
echo "All tests already ran successfully.\n";
|
echo "All tests already ran successfully.\n";
|
||||||
$suite->setTests(array());
|
$suite->setTests([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$testSuites = array($suite);
|
$testSuites = [$suite];
|
||||||
for ($i = 0; isset($testSuites[$i]); ++$i) {
|
for ($i = 0; isset($testSuites[$i]); ++$i) {
|
||||||
foreach ($testSuites[$i]->tests() as $test) {
|
foreach ($testSuites[$i]->tests() as $test) {
|
||||||
if ($test instanceof TestSuite) {
|
if ($test instanceof TestSuite) {
|
||||||
@ -163,7 +163,7 @@ class SymfonyTestsListenerTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (2 === $this->state) {
|
} elseif (2 === $this->state) {
|
||||||
$skipped = array();
|
$skipped = [];
|
||||||
foreach ($suite->tests() as $test) {
|
foreach ($suite->tests() as $test) {
|
||||||
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)
|
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)
|
||||||
|| isset($this->wasSkipped[$suiteName]['*'])
|
|| isset($this->wasSkipped[$suiteName]['*'])
|
||||||
@ -228,7 +228,7 @@ class SymfonyTestsListenerTrait
|
|||||||
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
|
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
|
||||||
|
|
||||||
$this->expectedDeprecations = $annotations['method']['expectedDeprecation'];
|
$this->expectedDeprecations = $annotations['method']['expectedDeprecation'];
|
||||||
$this->previousErrorHandler = set_error_handler(array($this, 'handleError'));
|
$this->previousErrorHandler = set_error_handler([$this, 'handleError']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,8 +251,8 @@ class SymfonyTestsListenerTrait
|
|||||||
$deprecations = file_get_contents($this->runsInSeparateProcess);
|
$deprecations = file_get_contents($this->runsInSeparateProcess);
|
||||||
unlink($this->runsInSeparateProcess);
|
unlink($this->runsInSeparateProcess);
|
||||||
putenv('SYMFONY_DEPRECATIONS_SERIALIZE');
|
putenv('SYMFONY_DEPRECATIONS_SERIALIZE');
|
||||||
foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) {
|
foreach ($deprecations ? unserialize($deprecations) : [] as $deprecation) {
|
||||||
$error = serialize(array('deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => isset($deprecation[2]) ? $deprecation[2] : null));
|
$error = serialize(['deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => isset($deprecation[2]) ? $deprecation[2] : null]);
|
||||||
if ($deprecation[0]) {
|
if ($deprecation[0]) {
|
||||||
// unsilenced on purpose
|
// unsilenced on purpose
|
||||||
trigger_error($error, E_USER_DEPRECATED);
|
trigger_error($error, E_USER_DEPRECATED);
|
||||||
@ -264,13 +264,13 @@ class SymfonyTestsListenerTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->expectedDeprecations) {
|
if ($this->expectedDeprecations) {
|
||||||
if (!\in_array($test->getStatus(), array(BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE), true)) {
|
if (!\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE], true)) {
|
||||||
$test->addToAssertionCount(\count($this->expectedDeprecations));
|
$test->addToAssertionCount(\count($this->expectedDeprecations));
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
|
|
||||||
if (!$errored && !\in_array($test->getStatus(), array(BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE, BaseTestRunner::STATUS_FAILURE, BaseTestRunner::STATUS_ERROR), true)) {
|
if (!$errored && !\in_array($test->getStatus(), [BaseTestRunner::STATUS_SKIPPED, BaseTestRunner::STATUS_INCOMPLETE, BaseTestRunner::STATUS_FAILURE, BaseTestRunner::STATUS_ERROR], true)) {
|
||||||
try {
|
try {
|
||||||
$prefix = "@expectedDeprecation:\n";
|
$prefix = "@expectedDeprecation:\n";
|
||||||
$test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", $this->expectedDeprecations)."\n%A", $prefix.' '.implode("\n ", $this->gatheredDeprecations)."\n");
|
$test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", $this->expectedDeprecations)."\n%A", $prefix.' '.implode("\n ", $this->gatheredDeprecations)."\n");
|
||||||
@ -279,7 +279,7 @@ class SymfonyTestsListenerTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->expectedDeprecations = $this->gatheredDeprecations = array();
|
$this->expectedDeprecations = $this->gatheredDeprecations = [];
|
||||||
$this->previousErrorHandler = null;
|
$this->previousErrorHandler = null;
|
||||||
}
|
}
|
||||||
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
|
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
|
||||||
@ -287,12 +287,12 @@ class SymfonyTestsListenerTrait
|
|||||||
ClockMock::withClockMock(false);
|
ClockMock::withClockMock(false);
|
||||||
}
|
}
|
||||||
if (\in_array('dns-sensitive', $groups, true)) {
|
if (\in_array('dns-sensitive', $groups, true)) {
|
||||||
DnsMock::withMockedHosts(array());
|
DnsMock::withMockedHosts([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleError($type, $msg, $file, $line, $context = array())
|
public function handleError($type, $msg, $file, $line, $context = [])
|
||||||
{
|
{
|
||||||
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
|
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
|
||||||
$h = $this->previousErrorHandler;
|
$h = $this->previousErrorHandler;
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler;
|
namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler;
|
||||||
|
|
||||||
use Composer\Autoload\ClassLoader;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
|
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
|
||||||
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
|
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
|
||||||
@ -46,7 +45,6 @@ class DeprecationTest extends TestCase
|
|||||||
touch($vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php');
|
touch($vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php');
|
||||||
touch($vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php');
|
touch($vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php');
|
||||||
|
|
||||||
|
|
||||||
return self::$vendorDir;
|
return self::$vendorDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,12 +104,12 @@ class DeprecationTest extends TestCase
|
|||||||
yield 'not from phpunit, and not a whitelisted message' => [
|
yield 'not from phpunit, and not a whitelisted message' => [
|
||||||
false,
|
false,
|
||||||
\My\Source\Code::class,
|
\My\Source\Code::class,
|
||||||
'Self deprecating humor is deprecated by itself'
|
'Self deprecating humor is deprecated by itself',
|
||||||
];
|
];
|
||||||
yield 'from phpunit, but not a whitelisted message' => [
|
yield 'from phpunit, but not a whitelisted message' => [
|
||||||
false,
|
false,
|
||||||
\PHPUnit\Random\Piece\Of\Code::class,
|
\PHPUnit\Random\Piece\Of\Code::class,
|
||||||
'Self deprecating humor is deprecated by itself'
|
'Self deprecating humor is deprecated by itself',
|
||||||
];
|
];
|
||||||
yield 'whitelisted message, but not from phpunit' => [
|
yield 'whitelisted message, but not from phpunit' => [
|
||||||
false,
|
false,
|
||||||
@ -146,7 +144,7 @@ class DeprecationTest extends TestCase
|
|||||||
['file' => 'should_not_matter.php'],
|
['file' => 'should_not_matter.php'],
|
||||||
['file' => 'should_not_matter_either.php'],
|
['file' => 'should_not_matter_either.php'],
|
||||||
],
|
],
|
||||||
'random_path' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'phpunit' . \DIRECTORY_SEPARATOR . 'whatever.php'
|
'random_path'.\DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR.'whatever.php'
|
||||||
);
|
);
|
||||||
$this->assertTrue($deprecation->isMuted());
|
$this->assertTrue($deprecation->isMuted());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user