Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra test to ensure FQCN::class is disallowed properly #161

Merged
merged 1 commit into from
Jan 9, 2023
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
16 changes: 16 additions & 0 deletions tests/Calls/FunctionCallsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory;
use Spaze\PHPStan\Rules\Disallowed\DisallowedHelper;
use Spaze\PHPStan\Rules\Disallowed\IsAllowedFileHelper;
use Waldo\Quux\Blade;

class FunctionCallsTest extends RuleTestCase
{
Expand Down Expand Up @@ -171,6 +172,17 @@ protected function getRule(): Rule
2,
],
],
[
'function' => 'mocky()',
'message' => 'mocking Blade is not allowed.',
'allowIn' => [
'../src/disallowed-allowed/*.php',
'../src/*-allow/*.*',
],
'disallowParams' => [
1 => Blade::class,
],
],
]
);
}
Expand Down Expand Up @@ -267,6 +279,10 @@ public function testRule(): void
'Calling array_filter() is forbidden, callback parameter must be given.',
74,
],
[
'Calling mocky() is forbidden, mocking Blade is not allowed.',
81,
],
]);
// Based on the configuration above, no errors in this file:
$this->analyse([__DIR__ . '/../src/disallowed-allow/functionCalls.php'], [
Expand Down
4 changes: 4 additions & 0 deletions tests/libs/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ function baz(string $name = '', string $value = '', int $expires = 0, string $pa
function waldo(string $name = '', string $value = '', int $expires = 0, string $path = ''): bool
{
}

function mocky(string $className): void
{
}
4 changes: 4 additions & 0 deletions tests/src/disallowed-allow/functionCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@
array_filter(['1', '2'], function () {
return true;
});

// allowed when not FQCN to Blade class
mocky(\Fiction\Pulp\Royale::class);
mocky(\Waldo\Quux\Blade::class);
4 changes: 4 additions & 0 deletions tests/src/disallowed/functionCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@
array_filter(['1', '2'], function () {
return true;
});

// allowed when not FQCN to Blade class
mocky(\Fiction\Pulp\Royale::class);
mocky(\Waldo\Quux\Blade::class);