Skip to content

Commit d9be18e

Browse files
committed
Test default preset with not allowed risky rules
1 parent a5d3dc1 commit d9be18e

4 files changed

Lines changed: 63 additions & 21 deletions

File tree

tests/Acceptance/BuilderTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Spiral\CodeStyle\Tests\Acceptance;
6+
7+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
8+
9+
final class BuilderTest extends TestCase
10+
{
11+
#[DoesNotPerformAssertions]
12+
public function testDisableRisky(): void
13+
{
14+
$config = \realpath(__DIR__ . '/Stub/config-no-risky.php');
15+
$command = "php vendor/bin/php-cs-fixer fix --dry-run --config=$config";
16+
17+
\exec($command, $output, $status);
18+
19+
\in_array($status, [0, 8]) or $this->fail(\sprintf(
20+
"php-cs-fixer failed: %s. \n %s\n\n%s",
21+
$status,
22+
\implode('\n ', $this->describeFailCommand($status)),
23+
\implode("\n", $output),
24+
));
25+
}
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once './vendor/autoload.php';
6+
7+
return \Spiral\CodeStyle\Builder::create()
8+
->include(__FILE__)
9+
->allowRisky(false)
10+
->build();

tests/Acceptance/StyleTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,8 @@
44

55
namespace Spiral\CodeStyle\Tests\Acceptance;
66

7-
use PHPUnit\Framework\TestCase;
8-
97
final class StyleTest extends TestCase
108
{
11-
private const CS_STATUSES = [
12-
1 => 'General error (or PHP minimal requirement not matched).',
13-
4 => 'Some files have invalid syntax (only in dry-run mode).',
14-
8 => 'Some files need fixing (only in dry-run mode).',
15-
16 => 'Configuration error of the application.',
16-
32 => 'Configuration error of a Fixer.',
17-
64 => 'Exception raised within the application.',
18-
];
19-
209
public function testStyled(): void
2110
{
2211
$dir = \realpath(__DIR__ . '/Stub/Styled');
@@ -58,14 +47,4 @@ public function testStyled(): void
5847
)),
5948
));
6049
}
61-
62-
private function describeFailCommand(int $code): array
63-
{
64-
$result = [];
65-
foreach (self::CS_STATUSES as $mask => $description) {
66-
$code & $mask and $result[] = $description;
67-
}
68-
69-
return $result;
70-
}
7150
}

tests/Acceptance/TestCase.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Spiral\CodeStyle\Tests\Acceptance;
6+
7+
abstract class TestCase extends \PHPUnit\Framework\TestCase
8+
{
9+
private const CS_STATUSES = [
10+
1 => 'General error (or PHP minimal requirement not matched).',
11+
4 => 'Some files have invalid syntax (only in dry-run mode).',
12+
8 => 'Some files need fixing (only in dry-run mode).',
13+
16 => 'Configuration error of the application.',
14+
32 => 'Configuration error of a Fixer.',
15+
64 => 'Exception raised within the application.',
16+
];
17+
18+
protected function describeFailCommand(int $code): array
19+
{
20+
$result = [];
21+
foreach (self::CS_STATUSES as $mask => $description) {
22+
$code & $mask and $result[] = $description;
23+
}
24+
25+
return $result;
26+
}
27+
}

0 commit comments

Comments
 (0)