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

fix: FilterTestTrait::getFilterCaller() does not support Filter classes as array #8058

Merged
merged 3 commits into from
Oct 21, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Oct 18, 2023

Description
The $aliases values can be an array.
See https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html#aliases

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 18, 2023
@kenjis kenjis merged commit 4c09ca3 into codeigniter4:develop Oct 21, 2023
61 checks passed
@kenjis kenjis deleted the fix-filters-var-type branch October 21, 2023 23:31
}

// Get an instance
$filter = new $filter();
$filterClasses = (array) $filterClasses;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduced a scenario where $filterClasses may note be set (if a FQCN was passed as $filter causing it to error out.

Test code:

    public function testLoginPass()
    {
        session()->set('uid', '54321fedcba');

        $caller = $this->getFilterCaller(LoginFilter::class, 'before');
        $result = $caller();

        $this->assertNull($result);
    }

Result:

2) FiltersTest::testNotAuthenticated with data set #0 ('App\Filters\LoginFilter')
ErrorException: Undefined variable $filterClasses

/home/runner/work/web/web/vendor/codeigniter4/framework/system/Test/FilterTestTrait.php:138
/home/runner/work/web/web/tests/misc/FiltersTest.php:60

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry!
Why can't static analysis detect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sent #8195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants