Skip to content

Commit

Permalink
Merge pull request #27 from drupol/fix-tests-since-workflow-disable
Browse files Browse the repository at this point in the history
fix tests since lasts commits break them silently
  • Loading branch information
WengerK authored Oct 1, 2024
2 parents 365f48e + 0a81ac2 commit 78fed0a
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:

strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2']
phpcsfixer-version: ['3.35.*', '3.*', '*']
php-versions: ['8.0', '8.1', '8.2', '8.3']
phpcsfixer-version: ['3.*', '*']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- replace deprecated rule 'escape_implicit_backslashes' by 'string_implicit_backslashes'

### Removed
- drop support for php-cs-fixer 3.35.x by removing tests on this version

### Added
- add running tests on PHP 8.3
- add rule declare_equal_normalize to support declare(strict_types=1) without spaces around equal for Drupal8

## [2.1.0] - 2023-10-23
### Added
Expand Down
4 changes: 3 additions & 1 deletion config/drupal8/phpcsfixer.rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ parameters:
array_syntax:
syntax: short
declare_equal_normalize: true
declare_strict_types: true
declare_strict_types: false
blank_lines_before_namespace: false
fully_qualified_strict_types:
leading_backslash_in_global_namespace: false
2 changes: 1 addition & 1 deletion src/Fixer/BlankLineBeforeEndOfClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function applyFix(SplFileInfo $file, Tokens $tokens): void
$tokens[$endCurlyBraceIndex] = new Token(
[
T_WHITESPACE,
$padding . $this->tokens[$endCurlyBraceIndex]->getContent(),
$padding . $this->tokens[$endCurlyBraceIndex]->getContent(),
]
);
}
Expand Down
42 changes: 42 additions & 0 deletions tests/Integration/Scenario5Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace drupol\PhpCsFixerConfigsDrupal\Tests\Integration;

use drupol\PhpCsFixerConfigsDrupal\Config\Drupal8;
use drupol\PhpCsFixerConfigsDrupal\Tests\IntegrationTestCase;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet\RuleSet;

/**
* @author Kevin Wenger <[email protected]>
*
* Covers the PHP-CS-Fixer rules declare_strict_types & declare_equal_normalize
*
* @internal
*/
final class Scenario5Test extends IntegrationTestCase
{
protected function getScenarioPath(): string
{
return __DIR__ . '/fixtures/scenario5';
}

public function testDrupal8Config(): void
{
$drupal8 = new Drupal8();
$rules = $drupal8->getRules();
$ruleset = new RuleSet($rules);

$factory = (new FixerFactory())
->registerBuiltInFixers()
->registerCustomFixers($drupal8->getCustomFixers())
->useRuleSet($ruleset);

$fixers = [];
foreach ($factory->getFixers() as $fixer) {
$fixers[$fixer->getName()] = $fixer;
}

$this->doTest($fixers);
}
}
42 changes: 42 additions & 0 deletions tests/Integration/Scenario6Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace drupol\PhpCsFixerConfigsDrupal\Tests\Integration;

use drupol\PhpCsFixerConfigsDrupal\Config\Drupal8;
use drupol\PhpCsFixerConfigsDrupal\Tests\IntegrationTestCase;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet\RuleSet;

/**
* @author Kevin Wenger <[email protected]>
*
* Covers the PHP-CS-Fixer rules leading_backslash_in_global_namespace
*
* @internal
*/
final class Scenario6Test extends IntegrationTestCase
{
protected function getScenarioPath(): string
{
return __DIR__ . '/fixtures/scenario6';
}

public function testDrupal8Config(): void
{
$drupal8 = new Drupal8();
$rules = $drupal8->getRules();
$ruleset = new RuleSet($rules);

$factory = (new FixerFactory())
->registerBuiltInFixers()
->registerCustomFixers($drupal8->getCustomFixers())
->useRuleSet($ruleset);

$fixers = [];
foreach ($factory->getFixers() as $fixer) {
$fixers[$fixer->getName()] = $fixer;
}

$this->doTest($fixers);
}
}
2 changes: 1 addition & 1 deletion tests/Integration/fixtures/scenario0/bad.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
function sample(? string $str): ? string {}

// Cover single_space_after_construct (default).
throw new \Exception();
throw new Exception();
// Cover single_space_after_construct (yield_from).
yield from baz();

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/fixtures/scenario0/good.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function foo(array $arg) {
function sample(?string $str): ?string {}

// Cover single_space_after_construct (default).
throw new \Exception();
throw new Exception();
// Cover single_space_after_construct (yield_from).
yield from baz();

Expand Down
8 changes: 8 additions & 0 deletions tests/Integration/fixtures/scenario5/bad.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare( strict_types = 1 );
class Bar {

public $id;

}
8 changes: 8 additions & 0 deletions tests/Integration/fixtures/scenario5/good.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);
class Bar {

public $id;

}
3 changes: 3 additions & 0 deletions tests/Integration/fixtures/scenario6/bad.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

throw new \Exception();
3 changes: 3 additions & 0 deletions tests/Integration/fixtures/scenario6/good.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

throw new Exception();
2 changes: 1 addition & 1 deletion tests/Unit/Config/Drupal7Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function testConfigDefault(): void
'mute_deprecation_error' => true,
'noise_remaining_usages' => true,
],
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => false,
'explicit_string_variable' => true,
'final_class' => false,
Expand Down Expand Up @@ -436,7 +437,6 @@ public function testConfigDefault(): void
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => true,
'string_implicit_backslashes' => true,
'string_length_to_empty' => true,
'string_line_ending' => true,
'switch_case_semicolon_to_colon' => true,
Expand Down
8 changes: 5 additions & 3 deletions tests/Unit/Config/Drupal8Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function testConfigDefault(): void
'date_time_immutable' => false,
'declare_equal_normalize' => true,
'declare_parentheses' => true,
'declare_strict_types' => true,
'declare_strict_types' => false,
'dir_constant' => true,
'doctrine_annotation_array_assignment' => [
'operator' => ':',
Expand Down Expand Up @@ -139,6 +139,7 @@ public function testConfigDefault(): void
'mute_deprecation_error' => true,
'noise_remaining_usages' => true,
],
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => false,
'explicit_string_variable' => true,
'final_class' => false,
Expand All @@ -147,7 +148,9 @@ public function testConfigDefault(): void
'fopen_flag_order' => true,
'fopen_flags' => true,
'full_opening_tag' => true,
'fully_qualified_strict_types' => true,
'fully_qualified_strict_types' => [
'leading_backslash_in_global_namespace' => false,
],
'function_declaration' => [
'closure_function_spacing' => 'one',
],
Expand Down Expand Up @@ -434,7 +437,6 @@ public function testConfigDefault(): void
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => true,
'string_implicit_backslashes' => true,
'string_length_to_empty' => true,
'string_line_ending' => true,
'switch_case_semicolon_to_colon' => true,
Expand Down

0 comments on commit 78fed0a

Please sign in to comment.