generated from ergebnis/php-cs-fixer-config-template
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Require symfony/process
- Loading branch information
1 parent
ef9bef8
commit 3f790e6
Showing
9 changed files
with
243 additions
and
2 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,151 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Test\EndToEnd\RuleSet; | ||
|
||
use PhpCsFixer\Console; | ||
use PHPUnit\Framework; | ||
use Symfony\Component\Filesystem; | ||
use Symfony\Component\Process; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class AbstractRuleSetTestCase extends Framework\TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
self::fileSystem()->mkdir(self::temporaryDirectory()); | ||
|
||
self::fileSystem()->dumpFile( | ||
self::configPath(), | ||
self::configContents(), | ||
); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
self::fileSystem()->remove(self::temporaryDirectory()); | ||
} | ||
|
||
final public function testConfigurationIsConsideredValid(): void | ||
{ | ||
$process = new Process\Process([ | ||
'vendor/bin/php-cs-fixer', | ||
'fix', | ||
\sprintf( | ||
'--config=%s', | ||
self::configPath(), | ||
), | ||
'--dry-run', | ||
]); | ||
|
||
$process->run(); | ||
|
||
$exitCode = $process->getExitCode(); | ||
|
||
self::assertNotNull($exitCode); | ||
self::assertSame(0, Console\Command\FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG & $exitCode, \sprintf( | ||
'Failed asserting that the configuration in "%s" is considered valid by friendsofphp/php-cs-fixer.', | ||
self::className(), | ||
)); | ||
} | ||
|
||
private static function fileSystem(): Filesystem\Filesystem | ||
{ | ||
return new Filesystem\Filesystem(); | ||
} | ||
|
||
private static function configPath(): string | ||
{ | ||
return \sprintf( | ||
'%s/.php-cs-fixer.php', | ||
self::temporaryDirectory(), | ||
); | ||
} | ||
|
||
private static function configContents(): string | ||
{ | ||
return \sprintf( | ||
<<<'PHP' | ||
<?php | ||
declare(strict_types=1); | ||
$config = Ergebnis\PhpCsFixer\Config\Factory::fromRuleSet(new %s('')); | ||
$config->getFinder() | ||
->exclude([ | ||
'.build/', | ||
'.github/', | ||
'.notes/', | ||
]) | ||
->ignoreDotFiles(false) | ||
->in('%s') | ||
->name('.php-cs-fixer.php'); | ||
$config->setUsingCache(false); | ||
return $config; | ||
PHP | ||
, | ||
self::className(), | ||
self::projectDirectory(), | ||
); | ||
} | ||
|
||
/** | ||
* @psalm-return class-string | ||
* | ||
* @throws \RuntimeException | ||
*/ | ||
private static function className(): string | ||
{ | ||
$className = \preg_replace( | ||
'/Test$/', | ||
'', | ||
\str_replace( | ||
'\Test\EndToEnd', | ||
'', | ||
static::class, | ||
), | ||
); | ||
|
||
if (!\is_string($className)) { | ||
throw new \RuntimeException(\sprintf( | ||
'Failed resolving class name from test class name "%s".', | ||
static::class, | ||
)); | ||
} | ||
|
||
if (!\class_exists($className)) { | ||
throw new \RuntimeException(\sprintf( | ||
'Class name "%s" resolved from test class name "%s" does not reference a class that exists.', | ||
$className, | ||
static::class, | ||
)); | ||
} | ||
|
||
return $className; | ||
} | ||
|
||
private static function projectDirectory(): string | ||
{ | ||
return __DIR__ . '/../../..'; | ||
} | ||
|
||
private static function temporaryDirectory(): string | ||
{ | ||
return __DIR__ . '/../../../.build/test'; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Test\EndToEnd\RuleSet; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @coversNothing | ||
* | ||
* @requires PHP 8.0 | ||
*/ | ||
final class Php80Test extends AbstractRuleSetTestCase | ||
{ | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Test\EndToEnd\RuleSet; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @coversNothing | ||
* | ||
* @requires PHP 8.1 | ||
*/ | ||
final class Php81Test extends AbstractRuleSetTestCase | ||
{ | ||
} |
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,30 @@ | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd" | ||
beStrictAboutChangesToGlobalState="true" | ||
beStrictAboutCoversAnnotation="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutResourceUsageDuringSmallTests="true" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
bootstrap="../../vendor/autoload.php" | ||
cacheResult="true" | ||
cacheResultFile="../../.build/phpunit/end-to-end.cache" | ||
colors="true" | ||
columns="max" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
executionOrder="random" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="EndToEnd"> | ||
<directory>.</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |