Skip to content

Commit

Permalink
[PhpUnitBridge] cs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Feb 6, 2020
1 parent 58cdd76 commit 1a98c63
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 44 deletions.
2 changes: 1 addition & 1 deletion ClockMock.php
Expand Up @@ -94,7 +94,7 @@ public static function register($class)
{
$self = \get_called_class();

$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
if (0 < strpos($class, '\\Tests\\')) {
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
Expand Down
16 changes: 8 additions & 8 deletions DnsMock.php
Expand Up @@ -16,8 +16,8 @@
*/
class DnsMock
{
private static $hosts = array();
private static $dnsTypes = array(
private static $hosts = [];
private static $dnsTypes = [
'A' => DNS_A,
'MX' => DNS_MX,
'NS' => DNS_NS,
Expand All @@ -30,7 +30,7 @@ class DnsMock
'NAPTR' => DNS_NAPTR,
'TXT' => DNS_TXT,
'HINFO' => DNS_HINFO,
);
];

/**
* Configures the mock values for DNS queries.
Expand Down Expand Up @@ -68,7 +68,7 @@ public static function getmxrr($hostname, &$mxhosts, &$weight = null)
if (!self::$hosts) {
return \getmxrr($hostname, $mxhosts, $weight);
}
$mxhosts = $weight = array();
$mxhosts = $weight = [];

if (isset(self::$hosts[$hostname])) {
foreach (self::$hosts[$hostname] as $record) {
Expand Down Expand Up @@ -125,7 +125,7 @@ public static function gethostbynamel($hostname)
$ips = false;

if (isset(self::$hosts[$hostname])) {
$ips = array();
$ips = [];

foreach (self::$hosts[$hostname] as $record) {
if ('A' === $record['type']) {
Expand All @@ -149,11 +149,11 @@ public static function dns_get_record($hostname, $type = DNS_ANY, &$authns = nul
if (DNS_ANY === $type) {
$type = DNS_ALL;
}
$records = array();
$records = [];

foreach (self::$hosts[$hostname] as $record) {
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);
}
}
}
Expand All @@ -165,7 +165,7 @@ public static function register($class)
{
$self = \get_called_class();

$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
if (0 < strpos($class, '\\Tests\\')) {
$ns = str_replace('\\Tests\\', '\\', $class);
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
Expand Down
2 changes: 1 addition & 1 deletion Legacy/CommandForV5.php
Expand Up @@ -23,7 +23,7 @@ class CommandForV5 extends \PHPUnit_TextUI_Command
*/
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;

Expand Down
14 changes: 7 additions & 7 deletions Legacy/CoverageListenerTrait.php
Expand Up @@ -32,7 +32,7 @@ public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFo
{
$this->sutFqcnResolver = $sutFqcnResolver;
$this->warningOnSutNotFound = $warningOnSutNotFound;
$this->warnings = array();
$this->warnings = [];
}

public function startTest($test)
Expand All @@ -43,7 +43,7 @@ public function startTest($test)

$annotations = $test->getAnnotations();

$ignoredAnnotations = array('covers', 'coversDefaultClass', 'coversNothing');
$ignoredAnnotations = ['covers', 'coversDefaultClass', 'coversNothing'];

foreach ($ignoredAnnotations as $annotation) {
if (isset($annotations['class'][$annotation]) || isset($annotations['method'][$annotation])) {
Expand All @@ -70,11 +70,11 @@ public function startTest($test)
$r->setAccessible(true);

$cache = $r->getValue();
$cache = array_replace_recursive($cache, array(
\get_class($test) => array(
'covers' => \is_array($sutFqcn) ? $sutFqcn : array($sutFqcn),
),
));
$cache = array_replace_recursive($cache, [
\get_class($test) => [
'covers' => \is_array($sutFqcn) ? $sutFqcn : [$sutFqcn],
],
]);
$r->setValue(Test::class, $cache);
}

Expand Down
2 changes: 1 addition & 1 deletion Legacy/SymfonyTestsListenerForV5.php
Expand Up @@ -22,7 +22,7 @@ class SymfonyTestsListenerForV5 extends \PHPUnit_Framework_BaseTestListener
{
private $trait;

public function __construct(array $mockedNamespaces = array())
public function __construct(array $mockedNamespaces = [])
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}
Expand Down
3 changes: 1 addition & 2 deletions Legacy/SymfonyTestsListenerForV6.php
Expand Up @@ -14,7 +14,6 @@
use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;

/**
* Collects and replays skipped tests.
Expand All @@ -27,7 +26,7 @@ class SymfonyTestsListenerForV6 extends BaseTestListener
{
private $trait;

public function __construct(array $mockedNamespaces = array())
public function __construct(array $mockedNamespaces = [])
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}
Expand Down
3 changes: 1 addition & 2 deletions Legacy/SymfonyTestsListenerForV7.php
Expand Up @@ -15,7 +15,6 @@
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;

/**
* Collects and replays skipped tests.
Expand All @@ -30,7 +29,7 @@ class SymfonyTestsListenerForV7 implements TestListener

private $trait;

public function __construct(array $mockedNamespaces = array())
public function __construct(array $mockedNamespaces = [])
{
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
}
Expand Down
34 changes: 17 additions & 17 deletions Legacy/SymfonyTestsListenerTrait.php
Expand Up @@ -35,26 +35,26 @@ class SymfonyTestsListenerTrait
private static $globallyEnabled = false;
private $state = -1;
private $skippedFile = false;
private $wasSkipped = array();
private $isSkipped = array();
private $expectedDeprecations = array();
private $gatheredDeprecations = array();
private $wasSkipped = [];
private $isSkipped = [];
private $expectedDeprecations = [];
private $gatheredDeprecations = [];
private $previousErrorHandler;
private $error;
private $runsInSeparateProcess = false;

/**
* @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;

$enableDebugClassLoader = class_exists(DebugClassLoader::class) || class_exists(LegacyDebugClassLoader::class);

foreach ($mockedNamespaces as $type => $namespaces) {
if (!\is_array($namespaces)) {
$namespaces = array($namespaces);
$namespaces = [$namespaces];
}
if ('time-sensitive' === $type) {
foreach ($namespaces as $ns) {
Expand Down Expand Up @@ -140,11 +140,11 @@ public function startTestSuite($suite)

if (!$this->wasSkipped = require $this->skippedFile) {
echo "All tests already ran successfully.\n";
$suite->setTests(array());
$suite->setTests([]);
}
}
}
$testSuites = array($suite);
$testSuites = [$suite];
for ($i = 0; isset($testSuites[$i]); ++$i) {
foreach ($testSuites[$i]->tests() as $test) {
if ($test instanceof TestSuite) {
Expand All @@ -163,7 +163,7 @@ public function startTestSuite($suite)
}
}
} elseif (2 === $this->state) {
$skipped = array();
$skipped = [];
foreach ($suite->tests() as $test) {
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)
|| isset($this->wasSkipped[$suiteName]['*'])
Expand Down Expand Up @@ -228,7 +228,7 @@ public function startTest($test)
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);

$this->expectedDeprecations = $annotations['method']['expectedDeprecation'];
$this->previousErrorHandler = set_error_handler(array($this, 'handleError'));
$this->previousErrorHandler = set_error_handler([$this, 'handleError']);
}
}
}
Expand All @@ -251,8 +251,8 @@ public function endTest($test, $time)
$deprecations = file_get_contents($this->runsInSeparateProcess);
unlink($this->runsInSeparateProcess);
putenv('SYMFONY_DEPRECATIONS_SERIALIZE');
foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) {
$error = serialize(array('deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => isset($deprecation[2]) ? $deprecation[2] : null));
foreach ($deprecations ? unserialize($deprecations) : [] as $deprecation) {
$error = serialize(['deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => isset($deprecation[2]) ? $deprecation[2] : null]);
if ($deprecation[0]) {
// unsilenced on purpose
trigger_error($error, E_USER_DEPRECATED);
Expand All @@ -264,13 +264,13 @@ public function endTest($test, $time)
}

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));
}

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 {
$prefix = "@expectedDeprecation:\n";
$test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", $this->expectedDeprecations)."\n%A", $prefix.' '.implode("\n ", $this->gatheredDeprecations)."\n");
Expand All @@ -279,20 +279,20 @@ public function endTest($test, $time)
}
}

$this->expectedDeprecations = $this->gatheredDeprecations = array();
$this->expectedDeprecations = $this->gatheredDeprecations = [];
$this->previousErrorHandler = null;
}
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
if (\in_array('time-sensitive', $groups, true)) {
ClockMock::withClockMock(false);
}
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) {
$h = $this->previousErrorHandler;
Expand Down
8 changes: 3 additions & 5 deletions Tests/DeprecationErrorHandler/DeprecationTest.php
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler;

use Composer\Autoload\ClassLoader;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
Expand Down Expand Up @@ -46,7 +45,6 @@ private static function getVendorDir()
touch($vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php');
touch($vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php');


return self::$vendorDir;
}

Expand Down Expand Up @@ -106,12 +104,12 @@ public function mutedProvider()
yield 'not from phpunit, and not a whitelisted message' => [
false,
\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' => [
false,
\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' => [
false,
Expand Down Expand Up @@ -146,7 +144,7 @@ public function testItTakesMutesDeprecationFromPhpUnitFiles()
['file' => 'should_not_matter.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());
}
Expand Down

0 comments on commit 1a98c63

Please sign in to comment.