Skip to content

Commit

Permalink
Added tests but they are failing
Browse files Browse the repository at this point in the history
  • Loading branch information
CrochetFeve0251 committed Jan 10, 2025
1 parent 97c1c8d commit bb82f34
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function processNode(Node $node, Scope $scope): array
'Missing docblock for wpm_apply_filters_typed call.'
)->identifier('docblock.missing')->build();

return [];
return $this->errors;
}

$this->validateDocBlock($resolvedPhpDoc);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace WP_Rocket\Tests\phpstan\tests\Rules;

use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use PHPStan\Type\FileTypeMapper;
use WP_Rocket\Tests\phpstan\Rules\ApplyFiltersTypedDynamicFunctionReturnTypeExtension;

class ApplyFiltersTypedDynamicFunctionReturnTypeExtensionTest extends RuleTestCase {

protected function getRule(): Rule {
return new ApplyFiltersTypedDynamicFunctionReturnTypeExtension($this->getContainer()->getByType(FileTypeMapper::class), $this->getContainer()->getByType(RuleLevelHelper::class));
}

public function testShouldRaiseError() {
$this->analyse([__DIR__ . '/../data/ApplyFiltersTypedDynamicFunctionReturnTypeExtension/not-valid.php'], [
[
'Missing docblock for wpm_apply_filters_typed call.',
3,
],
[
'Expected 2 @param tags, found 0.',
8,
],
[
'Expected 2 @param tags, found 1.',
13,
],
]);
}

public function testShouldNotRaiseError() {
$this->analyse([__DIR__ . '/../data/ApplyFiltersTypedDynamicFunctionReturnTypeExtension/valid.php'], []);
}

public static function getAdditionalConfigFiles(): array
{
// path to your project's phpstan.neon, or extension.neon in case of custom extension packages
// this is only necessary if your custom rule relies on some extra configuration and other extensions
return [__DIR__ . '/../data/ApplyFiltersTypedDynamicFunctionReturnTypeExtension/extension.neon'];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- ../../../../../vendor/szepeviktor/phpstan-wordpress/extension.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

wpm_apply_filters_typed('test', 100);

/**
*
*/
wpm_apply_filters_typed('test', 100);

/**
* @param string $number test.
*/
wpm_apply_filters_typed('test', 100);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
/**
* @param string $name test.
* @param string $number test.
*/
wpm_apply_filters_typed('test', 100);

0 comments on commit bb82f34

Please sign in to comment.