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] Apply Rector changes #58

Merged
merged 1 commit into from
Aug 13, 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
9 changes: 5 additions & 4 deletions src/CsFixerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ public function __construct(string $name = 'TYPO3')

public static function create(): self
{
$config = new static();
$config
$static = new static();
$static
->setRiskyAllowed(true)
->setRules(self::$typo3Rules)
;

$finder = $config->getFinder();
$finder = $static->getFinder();
$finder->exclude(['vendor', 'typo3temp', 'var', '.build']);

return $config;
return $static;
}

/**
Expand All @@ -130,6 +130,7 @@ public function setHeader(
if (!$replaceAll) {
$header = str_replace('{header}', $header, self::$defaultHeader);
}

$rules = $this->getRules();
$rules['header_comment'] = [
'header' => $header,
Expand Down
2 changes: 1 addition & 1 deletion src/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace TYPO3\CodingStandards;

class Setup
final class Setup
{
/**
* @var string
Expand Down
26 changes: 13 additions & 13 deletions tests/Unit/CsFixerConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@

use TYPO3\CodingStandards\CsFixerConfig;

class CsFixerConfigTest extends TestCase
final class CsFixerConfigTest extends TestCase
{
public function testCreateReturnsCorrectClass(): void
{
/** @var object $config */
$config = CsFixerConfig::create();
self::assertInstanceOf(CsFixerConfig::class, $config);
self::assertTrue($config->getRiskyAllowed());
self::assertCount(51, $config->getRules());
/** @var object $csFixerConfig */
$csFixerConfig = CsFixerConfig::create();
self::assertInstanceOf(CsFixerConfig::class, $csFixerConfig);
self::assertTrue($csFixerConfig->getRiskyAllowed());
self::assertCount(51, $csFixerConfig->getRules());
}

public function testAddRules(): void
{
$subject = new CsFixerConfig();
$subject->addRules(['test_config' => 'value']);
$csFixerConfig = new CsFixerConfig();
$csFixerConfig->addRules(['test_config' => 'value']);

self::assertArrayHasKey('test_config', $subject->getRules());
self::assertArrayHasKey('test_config', $csFixerConfig->getRules());
}

public function testSetHeaderSetHeaderOnly(): void
{
$subject = new CsFixerConfig();
$subject->setHeader('test_header');
$csFixerConfig = new CsFixerConfig();
$csFixerConfig->setHeader('test_header');

self::assertArrayHasKey('header_comment', $subject->getRules());
self::assertStringContainsString('test_header', $subject->getRules()['header_comment']['header']);
self::assertArrayHasKey('header_comment', $csFixerConfig->getRules());
self::assertStringContainsString('test_header', $csFixerConfig->getRules()['header_comment']['header']);
}
}
49 changes: 31 additions & 18 deletions tests/Unit/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,28 @@

use TYPO3\CodingStandards\Setup;

class SetupTest extends TestCase
final class SetupTest extends TestCase
{
/**
* @var string
*/
private const EDITORCONFIG_WARNING = "A .editorconfig file already exists in your main folder, but the -f option was not set. Nothing copied.\n";

/**
* @var string
*/
private const PHPCS_FOUND_DEPRECATED_INFORMATION = "Found deprecated .php_cs file and renamed it to .php-cs-fixer.dist.php.\n";

/**
* @var string
*/
private const PHPCS_FOUND_INFORMATION = "Found .php-cs-fixer.php file and renamed it to .php-cs-fixer.dist.php.\n";

/**
* @var string
*/
private const PHPCS_WARNING = "A .php-cs-fixer.dist.php file already exists in your main folder, but the -f option was not set. Nothing copied.\n";

/**
* @param array<string, string> $replacePairs
*/
Expand All @@ -45,7 +65,7 @@ private function assertScenario(
array $expectedFiles
): void {
$testPath = $this->getTestPath();
$subject = new Setup($testPath);
$setup = new Setup($testPath);

// create pre existing files
foreach ($existingFiles as $target => $source) {
Expand All @@ -54,19 +74,17 @@ private function assertScenario(

// call the subject's method
$methodName = 'for' . ucfirst($testType);
self::assertSame($expectedResult, $subject->$methodName($force)); // @phpstan-ignore-line
self::assertSame($expectedResult, $setup->$methodName($force)); // @phpstan-ignore-line
self::expectOutputString($expectedOutput);

// assert files
foreach ($expectedFiles as $file => $template) {
if ($template === false) {
self::assertFileNotExists($testPath . '/' . $file);
} elseif (is_string($template)) {
self::assertFileEquals($this->getFilename($template, ['{$typePrefix}' => $testType]), $testPath . '/' . $file);
} else {
if (is_string($template)) {
self::assertFileEquals($this->getFilename($template, ['{$typePrefix}' => $testType]), $testPath . '/' . $file);
} else {
self::assertFileExists($testPath . '/' . $file);
}
self::assertFileExists($testPath . '/' . $file);
}
}
}
Expand Down Expand Up @@ -108,11 +126,6 @@ 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";
$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' => [],
'force' => false,
Expand All @@ -134,7 +147,7 @@ public function scenariosProvider(): \Generator
],
'force' => false,
'expectedResult' => 1,
'expectedOutput' => $editorconfigWarning . $phpcsWarning,
'expectedOutput' => self::EDITORCONFIG_WARNING . self::PHPCS_WARNING,
'expectedFiles' => [
'.editorconfig' => 'FIX:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
Expand All @@ -148,7 +161,7 @@ public function scenariosProvider(): \Generator
],
'force' => false,
'expectedResult' => 1,
'expectedOutput' => $editorconfigWarning,
'expectedOutput' => self::EDITORCONFIG_WARNING,
'expectedFiles' => [
'.editorconfig' => 'FIX:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'TPL:{$typePrefix}_php-cs-fixer.dist.php',
Expand All @@ -162,7 +175,7 @@ public function scenariosProvider(): \Generator
],
'force' => false,
'expectedResult' => 1,
'expectedOutput' => $phpcsWarning,
'expectedOutput' => self::PHPCS_WARNING,
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
Expand All @@ -176,7 +189,7 @@ public function scenariosProvider(): \Generator
],
'force' => false,
'expectedResult' => 1,
'expectedOutput' => $phpcsFoundInformation . $phpcsWarning,
'expectedOutput' => self::PHPCS_FOUND_INFORMATION . self::PHPCS_WARNING,
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
Expand All @@ -190,7 +203,7 @@ public function scenariosProvider(): \Generator
],
'force' => false,
'expectedResult' => 1,
'expectedOutput' => $phpcsFoundDeprecatedInformation . $phpcsWarning,
'expectedOutput' => self::PHPCS_FOUND_DEPRECATED_INFORMATION . self::PHPCS_WARNING,
'expectedFiles' => [
'.editorconfig' => 'TPL:editorconfig.dist',
'.php-cs-fixer.dist.php' => 'FIX:php-cs-fixer.dist.php',
Expand Down