Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Dec 16, 2020
2 parents 5cbd5e7 + 6f0e10c commit d655f53
Show file tree
Hide file tree
Showing 30 changed files with 129 additions and 81 deletions.
1 change: 1 addition & 0 deletions .composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"symbol-whitelist" : [
"LegacyPHPUnit\\TestCase",
"PhpCsFixer\\PhpunitConstraintIsIdenticalString\\Constraint\\IsIdenticalString",
"PhpCsFixer\\Tests\\Test\\Constraint\\SameStringsConstraint",
"PhpCsFixer\\Tests\\Test\\IsIdenticalConstraint",
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
"php-cs-fixer/accessible-object": "^1.0",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1",
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.1",
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.13 || ^9.4.4 <9.5",
"phpunitgoodpractices/polyfill": "^1.5",
"phpunitgoodpractices/traits": "^1.9.1",
"sanmai/phpunit-legacy-adapter": "^6.4 || ^8.2.1",
"symfony/phpunit-bridge": "^5.1",
"symfony/yaml": "^3.0 || ^4.0 || ^5.0"
},
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ parameters:
- '/^Return typehint of method PhpCsFixer\\Tests\\Test\\.+::createIsIdenticalStringConstraint\(\) has invalid type PHPUnit_Framework_Constraint_IsIdentical\.$/'
- '/^Class (Symfony\\Contracts\\EventDispatcher\\Event|Symfony\\Component\\EventDispatcher\\Event) not found.$/'
- '/^Constant T_NAME_(RELATIVE|FULLY_QUALIFIED|QUALIFIED) not found\.$/'
- '/Instantiated class .*TraversableContains is abstract/'
- '/assertInstanceOf\(\) expects class-string.*, string given/'
-
message: '/^Unsafe usage of new static\(\)\.$/'
path: src/Config.php
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
enforceTimeLimit="true"
processIsolation="false"
stopOnFailure="false"
timeoutForSmallTests="2"
verbose="true"
>
<testsuites>
Expand Down
8 changes: 4 additions & 4 deletions tests/AbstractFunctionReferenceFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ final class AbstractFunctionReferenceFixerTest extends TestCase
{
private $fixer;

protected function setUp()
protected function doSetUp()
{
$this->fixer = new FunctionReferenceTestFixer();

parent::setUp();
parent::doSetUp();
}

protected function tearDown()
protected function doTearDown()
{
$this->fixer = null;

parent::tearDown();
parent::doTearDown();
}

/**
Expand Down
23 changes: 18 additions & 5 deletions tests/AutoReview/CiConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,27 @@ public function testDeploymentJobsRunOnLatestStablePhpThatIsSupportedByTool()
}
}

private static function assertUpcomingPhpVersionIsCoveredByCiJob($lastSupportedVersion, array $ciVersions)
private static function ensureTraversableContainsIsAvailable()
{
if (!class_exists(TraversableContains::class)) {
static::markTestSkipped('TraversableContains not available.');
}

try {
new TraversableContains('');
} catch (\Error $e) {
if (false === strpos($e->getMessage(), 'Cannot instantiate abstract class')) {
throw $e;
}

static::markTestSkipped('TraversableContains not available.');
}
}

private static function assertUpcomingPhpVersionIsCoveredByCiJob($lastSupportedVersion, array $ciVersions)
{
self::ensureTraversableContainsIsAvailable();

static::assertThat($ciVersions, static::logicalOr(
// if `$lastsupportedVersion` is already a snapshot version
new TraversableContains(sprintf('%.1fsnapshot', $lastSupportedVersion)),
Expand All @@ -100,9 +115,7 @@ private static function assertSupportedPhpVersionsAreCoveredByCiJobs(array $supp
static::assertContains($expectedVersion, $ciVersions);
}

if (!class_exists(TraversableContains::class)) {
static::markTestSkipped('TraversableContains not available.');
}
self::ensureTraversableContainsIsAvailable();

static::assertThat($ciVersions, static::logicalOr(
new TraversableContains($lastSupportedVersion),
Expand All @@ -117,7 +130,7 @@ private function getAllPhpVersionsUsedByCiForDeployments()
});

return array_map(function ($job) {
return (string) $job['php'];
return \is_string($job['php']) ? $job['php'] : sprintf('%.1f', $job['php']);
}, $jobs);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/AutoReview/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass) {

foreach ($publicMethods as $method) {
static::assertMatchesRegularExpression(
'/^(test|expect|provide|setUpBeforeClass$|tearDownAfterClass$)/',
'/^(test|expect|provide|doSetUpBeforeClass$|doTearDownAfterClass$)/',
$method->getName(),
sprintf('Public method "%s::%s" is not properly named.', $reflectionClass->getName(), $method->getName())
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Cache/FileHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
*/
final class FileHandlerTest extends TestCase
{
protected function tearDown()
protected function doTearDown()
{
parent::tearDown();
parent::doTearDown();

$file = $this->getFile();

Expand Down
8 changes: 4 additions & 4 deletions tests/Console/Command/SelfUpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ final class SelfUpdateCommandTest extends TestCase
*/
private $root;

protected function setUp()
protected function doSetUp()
{
parent::setUp();
parent::doSetUp();

$this->root = vfsStream::setup();

Expand All @@ -48,9 +48,9 @@ protected function setUp()
file_put_contents("{$this->root->url()}/{$this->getNewMajorVersion()}.phar", 'New major version of PHP CS Fixer.');
}

protected function tearDown()
protected function doTearDown()
{
parent::tearDown();
parent::doTearDown();

$this->root = null;

Expand Down
4 changes: 2 additions & 2 deletions tests/FileReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
*/
final class FileReaderTest extends TestCase
{
public static function tearDownAfterClass()
public static function doTearDownAfterClass()
{
parent::tearDownAfterClass();
parent::doTearDownAfterClass();

// testReadStdinCaches registers a stream wrapper for php so we can mock
// php://stdin. Restore the original stream wrapper after this class so
Expand Down
2 changes: 1 addition & 1 deletion tests/FileRemovalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class FileRemovalTest extends TestCase
*/
private static $removeFilesOnTearDown = true;

public static function tearDownAfterClass()
public static function doTearDownAfterClass()
{
if (self::$removeFilesOnTearDown) {
@unlink(sys_get_temp_dir().'/cs_fixer_foo.php');
Expand Down
5 changes: 4 additions & 1 deletion tests/Fixer/Alias/NoAliasFunctionsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public function provideFixCases()
$cases = [];

foreach (['internalSet', 'imapSet'] as $setStaticAttributeName) {
$reflectionProperty = new \ReflectionProperty(\PhpCsFixer\Fixer\Alias\NoAliasFunctionsFixer::class, $setStaticAttributeName);
$reflectionProperty->setAccessible(true);

/** @var string[] $aliases */
$aliases = static::getStaticAttribute(\PhpCsFixer\Fixer\Alias\NoAliasFunctionsFixer::class, $setStaticAttributeName);
$aliases = $reflectionProperty->getValue();

foreach ($aliases as $alias => $master) {
// valid cases
Expand Down
13 changes: 11 additions & 2 deletions tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace PhpCsFixer\Tests\Fixer\Alias;

use PhpCsFixer\AbstractFixer;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;

/**
Expand Down Expand Up @@ -281,14 +282,14 @@ public function testLegacyDefaultConfig()
{
$this->fixer->configure(null);

static::assertAttributeSame(T_PRINT, 'candidateTokenType', $this->fixer);
static::assertCandidateTokenType(T_PRINT, $this->fixer);
}

public function testDefaultConfig()
{
$this->fixer->configure([]);

static::assertAttributeSame(T_PRINT, 'candidateTokenType', $this->fixer);
static::assertCandidateTokenType(T_PRINT, $this->fixer);
}

/**
Expand Down Expand Up @@ -326,4 +327,12 @@ public function provideWrongConfigCases()
],
];
}

private static function assertCandidateTokenType($expected, AbstractFixer $fixer)
{
$reflectionProperty = new \ReflectionProperty($fixer, 'candidateTokenType');
$reflectionProperty->setAccessible(true);

static::assertSame($expected, $reflectionProperty->getValue($fixer));
}
}
10 changes: 8 additions & 2 deletions tests/Fixer/Alias/RandomApiMigrationFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,29 @@ public function testLegacyConfigure()
{
$this->fixer->configure(['rand' => 'random_int']);

$reflectionProperty = new \ReflectionProperty($this->fixer, 'configuration');
$reflectionProperty->setAccessible(true);

static::assertSame(
['replacements' => [
'rand' => ['alternativeName' => 'random_int', 'argumentCount' => [0, 2]], ],
],
static::getObjectAttribute($this->fixer, 'configuration')
$reflectionProperty->getValue($this->fixer)
);
}

public function testConfigure()
{
$this->fixer->configure(['replacements' => ['rand' => 'random_int']]);

$reflectionProperty = new \ReflectionProperty($this->fixer, 'configuration');
$reflectionProperty->setAccessible(true);

static::assertSame(
['replacements' => [
'rand' => ['alternativeName' => 'random_int', 'argumentCount' => [0, 2]], ],
],
static::getObjectAttribute($this->fixer, 'configuration')
$reflectionProperty->getValue($this->fixer)
);
}

Expand Down
16 changes: 12 additions & 4 deletions tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public function testLegacyConfigureDefaultToNull()

$fixer = new ClassDefinitionFixer();
$fixer->configure($defaultConfig);
static::assertAttributeSame($defaultConfig, 'configuration', $fixer);
static::assertConfigurationSame($defaultConfig, $fixer);

$fixer->configure(null);
static::assertAttributeSame($defaultConfig, 'configuration', $fixer);
static::assertConfigurationSame($defaultConfig, $fixer);
}

public function testConfigureDefaultToNull()
Expand All @@ -56,10 +56,10 @@ public function testConfigureDefaultToNull()

$fixer = new ClassDefinitionFixer();
$fixer->configure($defaultConfig);
static::assertAttributeSame($defaultConfig, 'configuration', $fixer);
static::assertConfigurationSame($defaultConfig, $fixer);

$fixer->configure([]);
static::assertAttributeSame($defaultConfig, 'configuration', $fixer);
static::assertConfigurationSame($defaultConfig, $fixer);
}

/**
Expand Down Expand Up @@ -698,6 +698,14 @@ public function provideMessyWhitespacesCases()
];
}

private static function assertConfigurationSame(array $expected, ClassDefinitionFixer $fixer)
{
$reflectionProperty = new \ReflectionProperty($fixer, 'configuration');
$reflectionProperty->setAccessible(true);

static::assertSame($expected, $reflectionProperty->getValue($fixer));
}

private function doTestClassyInheritanceInfo($source, $label, array $expected)
{
Tokens::clearCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ final class NoUnneededControlParenthesesFixerTest extends AbstractFixerTestCase
{
private static $defaultStatements;

public static function setUpBeforeClass()
public static function doSetUpBeforeClass()
{
parent::setUpBeforeClass();
parent::doSetUpBeforeClass();

$fixer = new NoUnneededControlParenthesesFixer();
foreach ($fixer->getConfigurationDefinition()->getOptions() as $option) {
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixer/LanguageConstruct/IsNullFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public function testCorrectConfiguration()
{
$this->fixer->configure(['use_yoda_style' => false]);

$configuration = static::getObjectAttribute($this->fixer, 'configuration');
$reflectionProperty = new \ReflectionProperty($this->fixer, 'configuration');
$reflectionProperty->setAccessible(true);

$configuration = $reflectionProperty->getValue($this->fixer);

static::assertFalse($configuration['use_yoda_style']);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Indicator/PhpUnitTestCaseIndicatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ final class PhpUnitTestCaseIndicatorTest extends TestCase
*/
private $indicator;

protected function setUp()
protected function doSetUp()
{
$this->indicator = new PhpUnitTestCaseIndicator();

parent::setUp();
parent::doSetUp();
}

protected function tearDown()
protected function doTearDown()
{
$this->indicator = null;

parent::tearDown();
parent::doTearDown();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Report/AbstractReporterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ abstract class AbstractReporterTestCase extends TestCase
*/
protected $reporter;

protected function setUp()
protected function doSetUp()
{
parent::setUp();
parent::doSetUp();

$this->reporter = $this->createReporter();
}

protected function tearDown()
protected function doTearDown()
{
parent::tearDown();
parent::doTearDown();

$this->reporter = null;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Report/CheckstyleReporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ final class CheckstyleReporterTest extends AbstractReporterTestCase
*/
private static $xsd;

public static function setUpBeforeClass()
public static function doSetUpBeforeClass()
{
self::$xsd = file_get_contents(__DIR__.'/../../doc/report-schema/checkstyle.xsd');
}

public static function tearDownAfterClass()
public static function doTearDownAfterClass()
{
self::$xsd = null;
}
Expand Down
Loading

0 comments on commit d655f53

Please sign in to comment.