pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: The `toHaveSuspiciousCharacters` method identifies Cyrillic characters as suspicious

Open andrey-helldar opened this issue 4 months ago • 2 comments

What Happened

In our project we use annotations to generate the OpenApi file and specify the description using Cyrillic.

When calling the architectural test arch()->preset()->php() it returns an error:

Expecting 'app\Enums\AlertTypeEnum.php' to not include suspicious characters.
at app\Enums\AlertTypeEnum.php:11
at vendor\pestphp\pest-plugin-arch\src\Expectations\Targeted.php:46
at vendor\pestphp\pest-plugin-arch\src\Blueprint.php:137
at vendor\pestphp\pest-plugin-arch\src\Expectations\Targeted.php:43
at vendor\pestphp\pest-plugin-arch\src\SingleArchExpectation.php:162
at vendor\pestphp\pest-plugin-arch\src\SingleArchExpectation.php:146

Enum class:

<?php

declare(strict_types=1);

namespace App\Enums;

use OpenApi\Attributes as OA;

#[OA\Schema(
    schema: AlertTypeEnum::class,
    description: 'Тип алерта', // this line
    type: 'string',
    enum: AlertTypeEnum::class,
)]
enum AlertTypeEnum: string
{
    case Ok      = 'OK';
    case Warning = 'WARNING';
    case Error   = 'ERROR';
}

How to Reproduce

Create any file and add annotation with Cyrillic. For example:

<?php

declare(strict_types=1);

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand('test', 'Привет')]
class TestCommand extends Command
{
    public function handle(): void {}
}

And now just run the check:

arch()->preset()->php();

Result:

Expecting 'app\Console\Commands\TestCommand.php' to not include suspicious characters.
at app\Console\Commands\TestCommand.php:10
at vendor\pestphp\pest-plugin-arch\src\Expectations\Targeted.php:46
at vendor\pestphp\pest-plugin-arch\src\Blueprint.php:137
at vendor\pestphp\pest-plugin-arch\src\Expectations\Targeted.php:43
at vendor\pestphp\pest-plugin-arch\src\SingleArchExpectation.php:162
at vendor\pestphp\pest-plugin-arch\src\SingleArchExpectation.php:146

Sample Repository

No response

Pest Version

4.0.3

PHP Version

8.4.11

Operation System

Windows

Notes

No response

andrey-helldar avatar Aug 26 '25 19:08 andrey-helldar

And when line contains at least one latin character with cyrillics this line is correctly identified and shown in output. But if line contains only cyrillic characters (a comment for example) it is resolved as line 0.

alexey-m-ukolov avatar Sep 09 '25 10:09 alexey-m-ukolov

We also use Seeders with some hardcoded names and addresses in Russian and they are also reported. Now we had to ignore these seeders when calling the PHP preset and create a custom preset for these seeders that replicates the PHP preset bud don't use toHaveSuspiciousCharacters expectation. It would be nice to either:

  • have this expectation as a separate preset, not included into the PHP preset,
  • or to have at least an option to ignore lines with // @pest-ignore-suspicious-characters or blocks with // @pest-ignore-suspicious-characters-start & // @pest-ignore-suspicious-characters-end

plakhin avatar Oct 01 '25 15:10 plakhin