Skip to content
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
13 changes: 13 additions & 0 deletions tests/Rules/ForbiddenNodeRule/Fixture/EmptyCall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\ForbiddenNodeRule\Fixture;

final class EmptyCall
{
public function run()
{
return empty($value);
}
}
47 changes: 47 additions & 0 deletions tests/Rules/ForbiddenNodeRule/ForbiddenNodeRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\ForbiddenNodeRule;

use Iterator;
use Override;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use Symplify\PHPStanRules\Rules\ForbiddenNodeRule;

final class ForbiddenNodeRuleTest extends RuleTestCase
{
/**
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
{
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
}

/**
* @return Iterator<(array<int, array<int, array<int, int>>>|array<int, array<int, array<int, string>>>|array<int, string>)>
*/
public static function provideData(): Iterator
{
$errorMessage = sprintf(ForbiddenNodeRule::ERROR_MESSAGE, 'empty($value)');
yield [__DIR__ . '/Fixture/EmptyCall.php', [[$errorMessage, 11]]];
}

/**
* @return string[]
*/
#[Override]
public static function getAdditionalConfigFiles(): array
{
return [__DIR__ . '/config/configured_rule.neon'];
}

protected function getRule(): Rule
{
return self::getContainer()->getByType(ForbiddenNodeRule::class);
}
}
13 changes: 13 additions & 0 deletions tests/Rules/ForbiddenNodeRule/config/configured_rule.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
includes:
- ../../../config/included_services.neon

services:
-
class: Symplify\PHPStanRules\Rules\ForbiddenNodeRule
tags: [phpstan.rules.rule]
arguments:
forbiddenNodes:
- PhpParser\Node\Expr\Empty_
- PhpParser\Node\Expr\ErrorSuppress
-
class: PhpParser\PrettyPrinter\Standard
Loading