Skip to content

Commit

Permalink
Make sure number of tests does not depend if PHP version is 7.4 or 8.0 (
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Feb 28, 2021
1 parent edf4739 commit 3b32cc9
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 85 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -8,7 +8,7 @@

[![CI Status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions)
[![Code coverage](https://img.shields.io/coveralls/github/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://coveralls.io/github/kubawerlos/php-cs-fixer-custom-fixers?branch=master)
![Tests](https://img.shields.io/badge/tests-2238-brightgreen.svg)
![Tests](https://img.shields.io/badge/tests-2244-brightgreen.svg)
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/kubawerlos/php-cs-fixer-custom-fixers/master)](https://stryker-mutator.github.io)
[![Psalm type coverage](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers/coverage.svg)](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers)

Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Expand Up @@ -5,7 +5,6 @@
cacheResult='false'
colors='true'
forceCoversAnnotation='true'
verbose='true'
>

<php>
Expand Down
16 changes: 10 additions & 6 deletions tests/Fixer/CommentedOutFunctionFixerTest.php
Expand Up @@ -235,12 +235,16 @@ public static function provideFixCases(): iterable
var_dump($y);
',
];
}

if (PHP_MAJOR_VERSION < 8) {
yield 'with comment between backslash and function call' => [
'<?php //\/* foo */var_dump/** bar */($x);',
'<?php \/* foo */var_dump/** bar */($x);',
];
}
/**
* @requires PHP ^7.2
*/
public function testWithCommentBetweenBackslashAndFunctionCall(): void
{
$this->doTest(
'<?php //\/* foo */var_dump/** bar */($x);',
'<?php \/* foo */var_dump/** bar */($x);'
);
}
}
127 changes: 73 additions & 54 deletions tests/Fixer/DataProviderReturnTypeFixerTest.php
Expand Up @@ -20,6 +20,21 @@
*/
final class DataProviderReturnTypeFixerTest extends AbstractFixerTestCase
{
private const TEMPLATE = '<?php
class FooTest extends TestCase {
/**
* @dataProvider provideFooCases
*/
public function testFoo() {}
/**
* @dataProvider provider
*/
public function testBar() {}
public function provideFooCases()%s {}
public function provider()%s {}
public function notProvider(): array {}
}';

public function testIsRisky(): void
{
self::assertTrue($this->fixer->isRisky());
Expand Down Expand Up @@ -49,63 +64,30 @@ public function provideFooCases() : iterable {}
}',
];

$template = '<?php
class FooTest extends TestCase {
/**
* @dataProvider provideFooCases
*/
public function testFoo() {}
/**
* @dataProvider provider
*/
public function testBar() {}
public function provideFooCases()%s {}
public function provider()%s {}
public function notProvider(): array {}
}';
yield 'data provider without return type' => self::mapToTemplate(
': iterable',
''
);

$cases = [
'data provider without return type' => [
': iterable',
'',
],
'data provider with array return type' => [
': iterable',
': array',
],
'data provider with return type and comment' => [
': /* TODO: add more cases */ iterable',
': /* TODO: add more cases */ array',
],
'data provider with return type namespaced class' => [
': iterable',
': Foo\Bar',
],
'data provider with iterable return type in different case' => [
': iterable',
': Iterable',
],
];
yield 'data provider with array return type' => self::mapToTemplate(
': iterable',
': array'
);

if (PHP_MAJOR_VERSION < 8) {
$cases['data provider with return type namespaced class starting with iterable'] = [
': iterable',
': iterable \ Foo',
];
$cases['data provider with return type namespaced class and comments'] = [
': iterable',
': Foo/* Some info */\/* More info */Bar',
];
}
yield 'data provider with return type and comment' => self::mapToTemplate(
': /* TODO: add more cases */ iterable',
': /* TODO: add more cases */ array'
);

foreach ($cases as $key => $case) {
yield $key => \array_map(
static function (string $code) use ($template): string {
return \sprintf($template, $code, $code);
},
$case
);
}
yield 'data provider with return type namespaced class' => self::mapToTemplate(
': iterable',
': Foo\Bar'
);

yield 'data provider with iterable return type in different case' => self::mapToTemplate(
': iterable',
': Iterable'
);

yield 'multiple data providers' => [
'<?php class FooTest extends TestCase {
Expand Down Expand Up @@ -226,4 +208,41 @@ public function provideFooCases() {}
];
}
}

/**
* @requires PHP ^7.2
*
* @dataProvider provideFix7Cases
*/
public function testFix7(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}

/**
* @return iterable<array{string, string}>
*/
public static function provideFix7Cases(): iterable
{
yield 'data provider with return type namespaced class starting with iterable' => self::mapToTemplate(
': iterable',
': iterable \ Foo'
);

yield 'data provider with return type namespaced class and comments' => self::mapToTemplate(
': iterable',
': Foo/* Some info */\/* More info */Bar'
);
}

/**
* @return array{string, string}
*/
private static function mapToTemplate(string $expected, string $actual): array
{
return [
\sprintf(self::TEMPLATE, $expected, $expected),
\sprintf(self::TEMPLATE, $actual, $actual),
];
}
}
46 changes: 30 additions & 16 deletions tests/Fixer/NoLeadingSlashInGlobalNamespaceFixerTest.php
Expand Up @@ -100,22 +100,36 @@ public static function provideFixCases(): iterable
$b = new \\Baz();
',
];
}

/**
* @requires PHP ^7.2
*
* @dataProvider provideFix7Cases
*/
public function testFix7(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}

/**
* @return iterable<array{string, string}>
*/
public static function provideFix7Cases(): iterable
{
yield [
'<?php $foo = Bar::value();',
'<?php $foo = \\ Bar::value();',
];

if (PHP_MAJOR_VERSION < 8) {
yield [
'<?php $foo = Bar::value();',
'<?php $foo = \\ Bar::value();',
];

yield [
'<?php $foo = /* comment */Bar::value();',
'<?php $foo = \\/* comment */Bar::value();',
];

yield [
'<?php $foo = /** comment */Bar::value();',
'<?php $foo = \\/** comment */Bar::value();',
];
}
yield [
'<?php $foo = /* comment */Bar::value();',
'<?php $foo = \\/* comment */Bar::value();',
];

yield [
'<?php $foo = /** comment */Bar::value();',
'<?php $foo = \\/** comment */Bar::value();',
];
}
}
16 changes: 10 additions & 6 deletions tests/Fixer/NoUselessSprintfFixerTest.php
Expand Up @@ -96,12 +96,16 @@ public static function provideFixCases(): iterable
sprintf(...$pieces);
',
];
}

if (PHP_MAJOR_VERSION < 8) {
yield [
'<?php $foo ;',
'<?php \ sprintf ( $foo ) ;',
];
}
/**
* @requires PHP ^7.2
*/
public function testWithSpaceBetweenSlashaAndFunctionName(): void
{
$this->doTest(
'<?php $foo ;',
'<?php \ sprintf ( $foo ) ;'
);
}
}
2 changes: 1 addition & 1 deletion tests/Readme/ReadmeCommandTest.php
Expand Up @@ -22,7 +22,7 @@
*
* @covers \PhpCsFixerCustomFixersDev\Readme\ReadmeCommand
*
* @requires PHP ^7.4
* @requires PHP >=7.4
*/
final class ReadmeCommandTest extends TestCase
{
Expand Down

0 comments on commit 3b32cc9

Please sign in to comment.