Fix getExpectedUnauthorizedEntityAccessCacheability PHPStan-0 issues

Created on 23 August 2024, 3 months ago

Problem/Motivation

PHPStan baseline is currently skipping multiple Call to an undefined method errors, #3291519: [Meta] Fix 'Call to an undefined method' PHPStan L0 errors .

Proposed resolution

Fix the error about getExpectedUnauthorizedEntityAccessCacheability.

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
REST 

Last updated about 17 hours ago

Created by

🇳🇿New Zealand quietone

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @quietone
  • Status changed to Needs review 3 months ago
  • 🇳🇿New Zealand quietone

    Not sure the solution for the last one.

  • Status changed to RTBC 3 months ago
  • 🇺🇸United States smustgrave

    Seems straight forward and failure appears to be random block one.

  • 🇮🇹Italy mondrake 🇮🇹
  • Status changed to Needs work 2 months ago
  • 🇬🇧United Kingdom catch

    Two questions on the MR.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 651s
    #301560
  • 🇳🇿New Zealand quietone

    If we can continue to use this solution then the remaining instance, in UserRegistrationRestTest, can be fixed.

  • Pipeline finished with Success
    about 1 month ago
    Total: 456s
    #301895
  • Pipeline finished with Failed
    about 1 month ago
    Total: 114s
    #303146
  • 🇺🇸United States smustgrave

    Actually since these aren't doing anything do we need the parameter to be based? Surprised now a phpstan rule that picks up unused parameter

  • Pipeline finished with Failed
    about 1 month ago
    Total: 708s
    #303151
  • 🇳🇿New Zealand quietone

    What is the work to do here? If there is work to be done from #10, can you be more specific? I do not understand the question in #10.

  • 🇺🇸United States smustgrave

    I meant why add bool $is_authenticated?

    NW for the rebase though.

  • First commit to issue fork.
  • Pipeline finished with Failed
    about 1 month ago
    Total: 105s
    #306750
  • Pipeline finished with Failed
    about 1 month ago
    Total: 102s
    #306753
  • 🇳🇿New Zealand quietone

    rebased and rebuilt the phpstan baseline.

  • 🇺🇸United States smustgrave

    So seems now we are trading 1 phpstan error for another. Does it need to return something (even empty string)

  • 🇳🇿New Zealand quietone

    So, void no longer work here. How about adding a return of \Drupal\Core\Cache\CacheableMetadata which is what is expected by the parent method, \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::getExpectedUnauthorizedEntityAccessCacheability/

  • 🇺🇸United States smustgrave

    Works for me!

  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Pipeline finished with Success
    3 days ago
    Total: 554s
    #336941
  • 🇳🇿New Zealand quietone

    Rebase with conflicts in the baseline, which I then rebuilt.

  • 🇦🇺Australia mstrelan

    I think this fix is just covering up a code smell. The method getExpectedUnauthorizedEntityAccessCacheability exists in \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase but not in \Drupal\Tests\rest\Functional\ResourceTestBase, yet the test trait that calls this method is added to classes that don't extend from EntityResourceTestBase. If we're saying this method needs to exist in all child classes then we might as well just add it to the base, but that makes it clear that it doesn't belong there. Ideally it should be refactored out of the shared trait, or failing that we should check if $this instanceof EntityResourceTestBase before calling that function.

Production build 0.71.5 2024