-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1b66dd
commit bd4325a
Showing
9 changed files
with
375 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* Dariusz Rumiński <dariusz.ruminski@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpCsFixer\Tests\Console\Command; | ||
|
||
use PhpCsFixer\Console\Application; | ||
use PhpCsFixer\Console\Command\DocumentationCommand; | ||
use PhpCsFixer\Tests\TestCase; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \PhpCsFixer\Console\Command\DocumentationCommand | ||
*/ | ||
final class DocumentationCommandTest extends TestCase | ||
{ | ||
public function testGeneratingDocumentation(): void | ||
{ | ||
$filesystem = $this->createFilesystemDouble(); | ||
|
||
$application = new Application(); | ||
$application->add(new DocumentationCommand($filesystem)); | ||
|
||
$command = $application->find('documentation'); | ||
$commandTester = new CommandTester($command); | ||
|
||
$commandTester->execute( | ||
[ | ||
'command' => $command->getName(), | ||
], | ||
[ | ||
'interactive' => false, | ||
'decorated' => false, | ||
'verbosity' => OutputInterface::VERBOSITY_DEBUG, | ||
], | ||
); | ||
|
||
self::assertStringContainsString( | ||
'Docs updated.', | ||
$commandTester->getDisplay(), | ||
); | ||
} | ||
|
||
private function createFilesystemDouble(): Filesystem | ||
{ | ||
return new class() extends Filesystem { | ||
public function dumpFile(string $filename, $content): void {} | ||
|
||
/** @phpstan-ignore-next-line */ | ||
public function remove($files): void {} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* Dariusz Rumiński <dariusz.ruminski@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpCsFixer\Tests\Documentation; | ||
|
||
use PhpCsFixer\Documentation\DocumentationLocator; | ||
use PhpCsFixer\Fixer\Casing\ConstantCaseFixer; | ||
use PhpCsFixer\Tests\TestCase; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \PhpCsFixer\Documentation\DocumentationLocator | ||
*/ | ||
final class DocumentationLocatorTest extends TestCase | ||
{ | ||
public function testFixersDocumentationDirectoryPath(): void | ||
{ | ||
self::assertSame( | ||
realpath(__DIR__.'/../..').'/doc/rules', | ||
(new DocumentationLocator())->getFixersDocumentationDirectoryPath() | ||
); | ||
} | ||
|
||
public function testFixersDocumentationIndexFilePath(): void | ||
{ | ||
self::assertSame( | ||
realpath(__DIR__.'/../..').'/doc/rules/index.rst', | ||
(new DocumentationLocator())->getFixersDocumentationIndexFilePath() | ||
); | ||
} | ||
|
||
public function testFixerDocumentationFilePath(): void | ||
{ | ||
self::assertSame( | ||
realpath(__DIR__.'/../..').'/doc/rules/casing/constant_case.rst', | ||
(new DocumentationLocator())->getFixerDocumentationFilePath(new ConstantCaseFixer()) | ||
); | ||
} | ||
|
||
public function testFixerDocumentationFileRelativePath(): void | ||
{ | ||
self::assertSame( | ||
'casing/constant_case.rst', | ||
(new DocumentationLocator())->getFixerDocumentationFileRelativePath(new ConstantCaseFixer()) | ||
); | ||
} | ||
|
||
public function testRuleSetsDocumentationDirectoryPath(): void | ||
{ | ||
self::assertSame( | ||
realpath(__DIR__.'/../..').'/doc/ruleSets', | ||
(new DocumentationLocator())->getRuleSetsDocumentationDirectoryPath() | ||
); | ||
} | ||
|
||
public function testRuleSetsDocumentationIndexFilePath(): void | ||
{ | ||
self::assertSame( | ||
realpath(__DIR__.'/../..').'/doc/ruleSets/index.rst', | ||
(new DocumentationLocator())->getRuleSetsDocumentationIndexFilePath() | ||
); | ||
} | ||
|
||
public function testRuleSetsDocumentationFilePath(): void | ||
{ | ||
self::assertSame( | ||
realpath(__DIR__.'/../..').'/doc/ruleSets/PhpCsFixerRisky.rst', | ||
(new DocumentationLocator())->getRuleSetsDocumentationFilePath('@PhpCsFixer:risky') | ||
); | ||
} | ||
|
||
public function testUsageFilePath(): void | ||
{ | ||
self::assertSame( | ||
realpath(__DIR__.'/../..').'/doc/usage.rst', | ||
(new DocumentationLocator())->getUsageFilePath() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of PHP CS Fixer. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* Dariusz Rumiński <dariusz.ruminski@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace PhpCsFixer\Tests\Documentation; | ||
|
||
use PhpCsFixer\Documentation\DocumentationLocator; | ||
use PhpCsFixer\Documentation\FixerDocumentGenerator; | ||
use PhpCsFixer\Fixer\Basic\BracesFixer; | ||
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer; | ||
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer; | ||
use PhpCsFixer\Fixer\FixerInterface; | ||
use PhpCsFixer\Fixer\LanguageConstruct\ClassKeywordFixer; | ||
use PhpCsFixer\Fixer\Strict\StrictParamFixer; | ||
use PhpCsFixer\FixerFactory; | ||
use PhpCsFixer\Tests\TestCase; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \PhpCsFixer\Documentation\FixerDocumentGenerator | ||
*/ | ||
final class FixerDocumentGeneratorTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideGenerateRuleSetsDocumentationCases | ||
*/ | ||
public function testGenerateRuleSetsDocumentation(FixerInterface $fixer): void | ||
{ | ||
$locator = new DocumentationLocator(); | ||
$generator = new FixerDocumentGenerator($locator); | ||
|
||
self::assertSame( | ||
file_get_contents($locator->getFixerDocumentationFilePath($fixer)), | ||
$generator->generateFixerDocumentation($fixer), | ||
); | ||
} | ||
|
||
/** | ||
* @return iterable<array{FixerInterface}> | ||
*/ | ||
public static function provideGenerateRuleSetsDocumentationCases(): iterable | ||
{ | ||
yield [new BracesFixer()]; | ||
|
||
yield [new ClassKeywordFixer()]; | ||
|
||
yield [new HeaderCommentFixer()]; | ||
|
||
yield [new StrictParamFixer()]; | ||
|
||
yield [new VisibilityRequiredFixer()]; | ||
} | ||
|
||
public function testGenerateFixersDocumentationIndex(): void | ||
{ | ||
$locator = new DocumentationLocator(); | ||
$generator = new FixerDocumentGenerator($locator); | ||
|
||
$fixerFactory = new FixerFactory(); | ||
$fixerFactory->registerBuiltInFixers(); | ||
$fixers = $fixerFactory->getFixers(); | ||
|
||
self::assertSame( | ||
file_get_contents($locator->getFixersDocumentationIndexFilePath()), | ||
$generator->generateFixersDocumentationIndex($fixers), | ||
); | ||
} | ||
} |
Oops, something went wrong.