symplify / easy-coding-standard-tester
The Best Way to Test Sniffs and Fixers
Package info
github.com/deprecated-packages/easy-coding-standard-tester
pkg:composer/symplify/easy-coding-standard-tester
Requires
- php: >=7.3
- phpunit/phpunit: ^9.5
- symplify/easy-coding-standard: ^9.3.20
- symplify/easy-testing: ^9.3.20
- symplify/package-builder: ^9.3.20
- symplify/smart-file-system: ^9.3.20
This package is auto-updated.
Last update: 2021-06-06 16:09:35 UTC
README
Do you write your own fixer and sniffs? Would you like to test them without having to learn a lot about their internals?
This package make fixer and sniff testing with 1 single approach super easy.
Install
composer require symplify/easy-coding-standard-tester --dev
Usage
-
Extend
Symplify\EasyCodingStandardTester\Testing\AbstractCheckerTestCaseclass -
Provide files to
doTestFiles()method
namespace Your\CodingStandard\Tests\Fixer\YourFixer; use Iterator; use Symplify\EasyCodingStandardTester\Testing\AbstractCheckerTestCase; use Symplify\EasyTesting\DataProvider\StaticFixtureFinder; use Symplify\SmartFileSystem\SmartFileInfo; use Your\CondingStandard\Fixer\YourFixer; final class YourFixerTest extends AbstractCheckerTestCase { /** * @dataProvider provideData() */ public function test(SmartFileInfo $fileInfo): void { $this->doTestFileInfo($fileInfo); } public function provideData(): Iterator { return StaticFixtureFinder::yieldDirectory(__DIR__ . '/Fixture'); } /** * @dataProvider provideDataWithFileErrors() */ public function testFileErrors(SmartFileInfo $fileInfo, int $expectedErrorCount): void { $this->doTestFileInfoWithErrorCountOf($fileInfo, $expectedErrorCount); } public function provideDataWithFileErrors(): Iterator { yield [new SmartFileInfo(__DIR__ . '/Fixture/wrong.php.inc'), 1]; yield [new SmartFileInfo(__DIR__ . '/Fixture/correct.php.inc'), 0]; } protected function getCheckerClass(): string { return YourFixer::class; } }
Instead of [__DIR__ . '/wrong/wrong.php.inc', __DIR__ . '/fixed/fixed.php.inc'] you can use single file: __DIR__ . '/fixture/fixture.php.inc' in this format:
<?php $array = array(); ?> ----- <?php $array = []; ?>
In pseudo-code:
before ------ after
Report Issues
In case you are experiencing a bug or want to request a new feature head over to the Symplify monorepo issue tracker
Contribute
The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on symplify/symplify.