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

[TASK] Use recommended naming for config #21

Merged
merged 1 commit into from
Apr 8, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,24 @@ private function copyPhpCsFixerConfig(bool $force, string $typePrefix): bool
{
$errors = false;

if (!$force && file_exists($this->rootPath . '/.php_cs') && !file_exists($this->rootPath . '/.php-cs-fixer.php')) {
rename($this->rootPath . '/.php_cs', $this->rootPath . '/.php-cs-fixer.php');
echo "Found deprecated .php_cs file and renamed it to .php-cs-fixer.php.\n";
if (!$force && file_exists($this->rootPath . '/.php_cs') && !file_exists($this->rootPath . '/.php-cs-fixer.dist.php')) {
rename($this->rootPath . '/.php_cs', $this->rootPath . '/.php-cs-fixer.dist.php');
echo "Found deprecated .php_cs file and renamed it to .php-cs-fixer.dist.php.\n";
}

if (!$force && file_exists($this->rootPath . '/.php-cs-fixer.php') && !file_exists($this->rootPath . '/.php-cs-fixer.dist.php')) {
rename($this->rootPath . '/.php-cs-fixer.php', $this->rootPath . '/.php-cs-fixer.dist.php');
echo "Found .php-cs-fixer.php file and renamed it to .php-cs-fixer.dist.php.\n";
}

if (
!$force
&& (file_exists($this->rootPath . '/.php_cs') || file_exists($this->rootPath . '/.php-cs-fixer.php'))
&& (file_exists($this->rootPath . '/.php_cs') || file_exists($this->rootPath . '/.php-cs-fixer.dist.php'))
) {
echo "A .php-cs-fixer.php file already exists in your main folder, but the -f option was not set. Nothing copied.\n";
echo "A .php-cs-fixer.dist.php file already exists in your main folder, but the -f option was not set. Nothing copied.\n";
$errors = true;
} else {
copy($this->templatesPath . '/' . $typePrefix . '_php-cs-fixer.dist.php', $this->rootPath . '/.php-cs-fixer.php');
copy($this->templatesPath . '/' . $typePrefix . '_php-cs-fixer.dist.php', $this->rootPath . '/.php-cs-fixer.dist.php');

if (file_exists($this->rootPath . '/.php_cs')) {
unlink($this->rootPath . '/.php_cs');
Expand Down
64 changes: 52 additions & 12 deletions tests/Unit/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ public function testForExtensionScenarios(
public function scenariosProvider(): \Generator
{
$editorconfigWarning = "A .editorconfig file already exists in your main folder, but the -f option was not set. Nothing copied.\n";
$phpcsInformation = "Found deprecated .php_cs file and renamed it to .php-cs-fixer.php.\n";
$phpcsWarning = "A .php-cs-fixer.php file already exists in your main folder, but the -f option was not set. Nothing copied.\n";
$phpcsFoundDeprecatedInformation = "Found deprecated .php_cs file and renamed it to .php-cs-fixer.dist.php.\n";
$phpcsFoundInformation = "Found .php-cs-fixer.php file and renamed it to .php-cs-fixer.dist.php.\n";
$phpcsWarning = "A .php-cs-fixer.dist.php file already exists in your main folder, but the -f option was not set. Nothing copied.\n";

yield 'all files are created' => [
'existingFiles' => [],
Expand All @@ -119,13 +120,15 @@ public function scenariosProvider(): \Generator
'expectedOutput' => '',
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.dist.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.php' => false,
'.php_cs' => false,
],
];
yield 'files are not overwritten' => [
'existingFiles' => [
'.editorconfig' => 'FIX:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
'.php-cs-fixer.php' => 'FIX:php-cs-fixer.dist.php',
'.php_cs' => 'FIX:php-cs-fixer.dist.php',
],
Expand All @@ -134,6 +137,7 @@ public function scenariosProvider(): \Generator
'expectedOutput' => $editorconfigWarning . $phpcsWarning,
'expectedFiles' => [
'.editorconfig' => 'FIX:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
'.php-cs-fixer.php' => 'FIX:php-cs-fixer.dist.php',
'.php_cs' => 'FIX:php-cs-fixer.dist.php',
],
Expand All @@ -147,20 +151,36 @@ public function scenariosProvider(): \Generator
'expectedOutput' => $editorconfigWarning,
'expectedFiles' => [
'.editorconfig' => 'FIX:editorconfig.dist',
'.php-cs-fixer.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.dist.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.php' => false,
'.php_cs' => false,
],
];
yield 'php-cs-fixer.php is not overwritten' => [
yield 'php-cs-fixer.dist.php is not overwritten' => [
'existingFiles' => [
'.php-cs-fixer.php' => 'FIX:php-cs-fixer.dist.php',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
],
'force' => false,
'expectedResult' => 1,
'expectedOutput' => $phpcsWarning,
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
'.php-cs-fixer.php' => false,
'.php_cs' => false,
],
];
yield 'php-cs-fixer.php is not overwritten' => [
'existingFiles' => [
'.php-cs-fixer.php' => 'FIX:php-cs-fixer.dist.php',
],
'force' => false,
'expectedResult' => 1,
'expectedOutput' => $phpcsFoundInformation . $phpcsWarning,
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
'.php-cs-fixer.php' => false,
'.php_cs' => false,
],
];
Expand All @@ -170,16 +190,18 @@ public function scenariosProvider(): \Generator
],
'force' => false,
'expectedResult' => 1,
'expectedOutput' => $phpcsInformation . $phpcsWarning,
'expectedOutput' => $phpcsFoundDeprecatedInformation . $phpcsWarning,
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.php' => 'FIX:php-cs-fixer.dist.php',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
'.php-cs-fixer.php' => false,
'.php_cs' => false,
],
];
yield 'all files are overwritten' => [
'existingFiles' => [
'.editorconfig' => 'FIX:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
'.php-cs-fixer.php' => 'FIX:php-cs-fixer.dist.php',
'.php_cs' => 'FIX:php-cs-fixer.dist.php',
],
Expand All @@ -188,7 +210,8 @@ public function scenariosProvider(): \Generator
'expectedOutput' => '',
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.dist.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.php' => 'FIX:php-cs-fixer.dist.php',
'.php_cs' => false,
],
];
Expand All @@ -201,11 +224,26 @@ public function scenariosProvider(): \Generator
'expectedOutput' => '',
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.dist.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.php' => false,
'.php_cs' => false,
],
];
yield 'php-cs-fixer.dist.php is overwritten' => [
'existingFiles' => [
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
],
'force' => true,
'expectedResult' => 0,
'expectedOutput' => '',
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.php' => false,
'.php_cs' => false,
],
];
yield 'php-cs-fixer.php is preserved' => [
'existingFiles' => [
'.php-cs-fixer.php' => 'FIX:php-cs-fixer.dist.php',
],
Expand All @@ -214,7 +252,8 @@ public function scenariosProvider(): \Generator
'expectedOutput' => '',
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.dist.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.php' => 'FIX:php-cs-fixer.dist.php',
'.php_cs' => false,
],
];
Expand All @@ -227,7 +266,8 @@ public function scenariosProvider(): \Generator
'expectedOutput' => '',
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.dist.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
'.php-cs-fixer.php' => false,
'.php_cs' => false,
],
];
Expand Down