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

Test calling and disallowing a function when its disallowedParam is array|string|null #165

Merged
merged 1 commit into from
Mar 19, 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
14 changes: 14 additions & 0 deletions tests/Calls/FunctionCallsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ protected function getRule(): Rule
1 => Blade::class,
],
],
[
'function' => '\Foo\Bar\Waldo\config()',
'allowIn' => [
'../src/disallowed-allow/*.php',
'../src/*-allow/*.*',
],
'disallowParams' => [
1 => 'string-key',
],
],
]
);
}
Expand Down Expand Up @@ -287,6 +297,10 @@ public function testRule(): void
'Calling Foo\Bar\Waldo\mocky() is forbidden, mocking Blade is not allowed.',
83,
],
[
'Calling Foo\Bar\Waldo\config() is forbidden, because reasons',
91,
],
]);
// Based on the configuration above, no errors in this file:
$this->analyse([__DIR__ . '/../src/disallowed-allow/functionCalls.php'], [
Expand Down
8 changes: 8 additions & 0 deletions tests/libs/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ function waldo(string $name = '', string $value = '', int $expires = 0, string $
function mocky(string $className): void
{
}


/**
* @param array|string|null $key
*/
function config($key = null)
{
}
5 changes: 5 additions & 0 deletions tests/src/disallowed-allow/functionCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@

// not disallowed
hash((new stdClass())->property . 'foo', 'NAH');

// not disallowed param
\Foo\Bar\Waldo\config(['key' => 'string']);
// allowed by path
\Foo\Bar\Waldo\config('string-key');
5 changes: 5 additions & 0 deletions tests/src/disallowed/functionCalls.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,8 @@

// not disallowed
hash((new stdClass())->property . 'foo', 'NAH');

spaze marked this conversation as resolved.
Show resolved Hide resolved
// not disallowed param
\Foo\Bar\Waldo\config(['key' => 'string']);
// disallowed param
\Foo\Bar\Waldo\config('string-key');