Review main Merged

73238[BUGFIX] Fix some incorrect usages of Prophecy

Oliver Klee CR +2 V +2 Expert +276 −880 updated 02/01/22, 16:51

Commit message

With the following changes, we can get rid of a whole bunch
of warnings from the PHPStan baseline:

1. Now that we are using the Prophecy plugin for PHPStan,
   we don't need type annotations for prophecies anymore.
2. Prophecies are not instances of the prophesized classes.
   So we need to fix/remove type annotations that incorrectly
   state this, and also move accesses on properties from the
   prophecies to the revelations.
3. Revelations are not instances of ObjectProphecy. They
   implement ProphecySubjectInterface, but that usually is
   of no relevance to our test classes. So we can simplify
   the type annotations and usually convert those to native
   type annotations.
4. Have PHPStan ignore false positive related to class aliasing
   (that probably is outside of what PHPStan can do).
5. Drop extraneous arguments to Argument::any().

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Stefan Bürk +1
    • core-ci +1 CI

Issues 1

Files 79

Show 59 more files

Review log 2028

Show 23 earlier messages
  1. Oliver Klee uploaded patch set 1 01/31/22, 00:53

  2. core-ci voted on patch set 1 V -1 01/31/22, 00:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22766

  3. Oliver Klee uploaded patch set 2 01/31/22, 01:01

  1. core-ci voted on patch set 2 V +1 01/31/22, 01:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22767

  2. Oliver Klee uploaded patch set 3 01/31/22, 22:45

  3. core-ci voted on patch set 3 V -1 01/31/22, 22:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22833

  4. Oliver Klee uploaded patch set 4 01/31/22, 22:49

  5. Oliver Klee uploaded patch set 5 01/31/22, 22:50

  6. core-ci voted on patch set 4 V -1 01/31/22, 22:52 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22835

  7. core-ci voted on patch set 5 V -1 01/31/22, 22:53 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22836

  8. Oliver Klee uploaded patch set 6 01/31/22, 22:57

  9. Oliver Klee commented on patch set 6 01/31/22, 23:47

    The jobs in the pipeline are green, but the result does not seem to get reported back: https://git.typo3.org/typo3/CI/cms/-/pipelines/22837
  10. core-ci voted on patch set 6 V -1 02/01/22, 00:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22837

  11. Christian Kuhn rebased onto patch set 7 02/01/22, 00:29

  12. core-ci voted on patch set 6 V +1 02/01/22, 00:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22837

  13. Christian Kuhn commented on patch set 7 02/01/22, 00:32

    great written commit message!
  14. core-ci voted on patch set 7 V +1 02/01/22, 00:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22845

  15. Stefan Bürk commented on patch set 7 V +1 CR +1 02/01/22, 00:49

    Nice patch, thanks for this work.
  16. Christian Kuhn voted on patch set 7 V +2 CR +2 02/01/22, 00:51

  17. Christian Kuhn merged patch set 8 02/01/22, 00:51

  18. Benjamin Franzke commented on patch set 8 02/01/22, 07:25

    FluidTemplateContentObjectTest.php:64

    I understand that this notation is not correct, and has therefore been removed. BUT, is there any way to get templated annotations like: @var ObjectProphecy<ContentObjectRenderer> we really loose information due to these removals…
  19. Benjamin Franzke commented on patch set 8 02/01/22, 07:31

  20. Oliver Klee commented on patch set 8 02/01/22, 09:39

    FluidTemplateContentObjectTest.php:64 Reply

    As the Prophecy plugin for PHPStan has this information internally, we are not losing this information at least as far as PHPStan is concerned. I'm sure about this for local variables; I'm not 100% sure about this for properties (i.e., whether the native type annotation overrules what the Prophecy plugin knows). My best guest is that if the information was lost, we'd see this in the form of a PHPStan warning.
  21. Oliver Klee commented on patch set 8 02/01/22, 10:44

    FluidTemplateContentObjectTest.php:64 Reply

    Addendum: 1) guest -> guess 2) Yes, it does (as PHPStan does not complain when methods are called on the prophecy).
  22. Benjamin Franzke commented on patch set 8 02/01/22, 14:31

    FluidTemplateContentObjectTest.php:64 Reply

    Well, PHPStan doesn't complain because it does allow *everything* to be called on an untyped revealed prophecy (it basically is considered mixed at that point). Can simply be verified by adding invalid call to a separate method, phpstan will not be able to derive a type and therefore the call is not considered invalid (as everything is allowed on mixed): $this->contentObjectRendererProphecy->reveal()->thisIsAnInvalidCall(); But once you add `@var ObjectProphecy<ContentObjectRenderer>` as annotation, it wail correctly complain: 129 Call to an undefined method TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::thisIsAnInvalidCall(). So either we revert this change or re-add these annotations in a separate change.
  23. Benjamin Franzke commented on patch set 8 02/01/22, 15:56

    FluidTemplateContentObjectTest.php:64 Reply

    Here is a patch that re-adds the information using generics: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73259
  24. Oliver Klee commented on patch set 8 02/01/22, 16:29

    Thanks, Benjamin!
  25. Stefan Bürk commented on patch set 8 02/01/22, 16:51

    FluidTemplateContentObjectTest.php:64 Reply

    I would say we can close this comment chain in favor of Banjamin follow up patch. Got the point after reviewing the linked patch/review.