Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX: unify tests for casing fixers #7558

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameters:
-
message: '#^Method PhpCsFixer\\Tests\\.+::provide.+Cases\(\) return type has no value type specified in iterable type iterable\.$#'
path: tests
count: 1102
count: 1096

-
message: '#Call to static method .+ with .+ will always evaluate to true.$#'
Expand Down
84 changes: 51 additions & 33 deletions tests/Fixer/Casing/ConstantCaseFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@
final class ConstantCaseFixerTest extends AbstractFixerTestCase
{
/**
* @param array<string, mixed> $configuration
*
* @dataProvider provideFixCases
*/
public function testFix(string $expected, ?string $input = null): void
public function testFix(string $expected, ?string $input = null, array $configuration = []): void
{
$this->fixer->configure($configuration);
$this->doTest($expected, $input);
}

/**
* @return iterable<array{string, 1?: null|string, 2?: array{syntax?: string}}>
*/
public static function provideFixCases(): iterable
{
yield [
Expand Down Expand Up @@ -112,69 +118,81 @@ class Foo
::test();'];

yield ['<?php class Foo { public function Bar() { $this->False = 1; $this->True = 2; $this->Null = 3; } }'];
}

/**
* @dataProvider provideFixToLowerCases
*/
public function testFixToLower(string $expected, ?string $input = null): void
{
$this->fixer->configure(['case' => 'lower']);
$this->doTest($expected, $input);
}

public static function provideFixToLowerCases(): iterable
{
foreach (['true', 'false', 'null'] as $case) {
yield [
sprintf('<?php $x = %s;', $case),
sprintf('<?php $x = %s;', strtoupper($case)),
['case' => 'lower'],
];

yield [
sprintf('<?php $x = %s;', $case),
sprintf('<?php $x = %s;', ucfirst($case)),
['case' => 'lower'],
];

yield [sprintf('<?php $x = new %s;', ucfirst($case))];
yield [
sprintf('<?php $x = new %s;', ucfirst($case)),
null,
['case' => 'lower'],
];

yield [sprintf('<?php $x = new %s;', strtoupper($case))];
yield [
sprintf('<?php $x = new %s;', strtoupper($case)),
null,
['case' => 'lower'],
];

yield [sprintf('<?php $x = "%s story";', $case)];
yield [
sprintf('<?php $x = "%s story";', $case),
null,
['case' => 'lower'],
];

yield [sprintf('<?php $x = "%s";', $case)];
yield [
sprintf('<?php $x = "%s";', $case),
null,
['case' => 'lower'],
];
}
}

/**
* @dataProvider provideFixToUpperCases
*/
public function testFixToUpper(string $expected, ?string $input = null): void
{
$this->fixer->configure(['case' => 'upper']);
$this->doTest($expected, $input);
}

public static function provideFixToUpperCases(): iterable
{
foreach (['true', 'false', 'null'] as $case) {
yield [
sprintf('<?php $x = %s;', strtoupper($case)),
sprintf('<?php $x = %s;', $case),
['case' => 'upper'],
];

yield [
sprintf('<?php $x = %s;', strtoupper($case)),
sprintf('<?php $x = %s;', ucfirst($case)),
['case' => 'upper'],
];

yield [sprintf('<?php $x = new %s;', ucfirst($case))];
yield [
sprintf('<?php $x = new %s;', ucfirst($case)),
null,
['case' => 'upper'],
];

yield [sprintf('<?php $x = new %s;', strtoupper($case))];
yield [
sprintf('<?php $x = new %s;', strtoupper($case)),
null,
['case' => 'upper'],
];

yield [sprintf('<?php $x = "%s story";', $case)];
yield [
sprintf('<?php $x = "%s story";', $case),
null,
['case' => 'upper'],
];

yield [sprintf('<?php $x = "%s";', $case)];
yield [
sprintf('<?php $x = "%s";', $case),
null,
['case' => 'upper'],
];
}
}

Expand Down
5 changes: 1 addition & 4 deletions tests/Fixer/Casing/LowercaseKeywordsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ public static function provideFixCases(): iterable
'<?php $fn = fn() => true;',
'<?php $fn = FN() => true;',
];
}

public function testHaltCompiler(): void
{
$this->doTest('<?php __HALT_COMPILER();');
yield ['<?php __HALT_COMPILER();'];
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Fixer/Casing/MagicConstantCasingFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public static function provideFixCases(): iterable
/**
* @requires PHP <8.0
*
* @dataProvider provideFix74Cases
* @dataProvider provideFixPre80Cases
*/
public function testFix74(string $expected, ?string $input = null): void
public function testFixPre80(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}

public static function provideFix74Cases(): iterable
public static function provideFixPre80Cases(): iterable
{
yield [
'<?php
Expand Down
13 changes: 1 addition & 12 deletions tests/Fixer/Casing/MagicMethodCasingFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class MagicMethodCasingFixerTest extends AbstractFixerTestCase
/**
* @dataProvider provideFixCases
*/
public function testFix(string $expected, string $input): void
public function testFix(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}
Expand Down Expand Up @@ -263,18 +263,7 @@ function __ISSET($bar){} // do not fix
'<?php $foo->__invoke(1, );',
'<?php $foo->__INVOKE(1, );',
];
}

/**
* @dataProvider provideDoNotFixCases
*/
public function testDoNotFix(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}

public static function provideDoNotFixCases(): iterable
{
yield [
'<?php
__Tostring();',
Expand Down