Review main Merged

73245[TASK] Remove broken test from ServiceProviderCompilationPassTest

Benjamin Franzke CR +2 V +2 Easy +0 −38 updated 01/31/22, 12:07

Commit message

PHPStan static analysis revealed that the method
exceptionForInvalidFactories() did not contain a proper test
setup, which went undetected as the expected TypeError
was thrown for the invalid test setup.

This could have been fixed but the test actually only
tried to assert whether a callable type declaration is set,
in order to test whether a PHP error is thrown when an
invalid factory is provided. This is useless as such
factory will result in an error once called anyway.

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Christian Kuhn +1
    • Benni Mack +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Christian Kuhn +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 2

Review log 1722

  1. Benjamin Franzke uploaded patch set 1 01/31/22, 09:58

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

  3. Benjamin Franzke uploaded patch set 2 01/31/22, 10:01

  4. Benjamin Franzke uploaded patch set 3 01/31/22, 10:05

  5. Christian Kuhn commented on patch set 3 01/31/22, 10:13

    ServiceProviderCompilationPassTest.php:223

    note we in general try to rather rely on 'exception type' plus 'exception code' if possible instead of 'exception message' since it's better to not rely on a string literal. this works for all core exceptions and only fails when libs like symfony or doctrine don't follow this typo3 specific approach and we still want to test for specific library exceptions.
  6. core-ci voted on patch set 2 V +1 01/31/22, 10:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22785

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

  8. Benjamin Franzke commented on patch set 3 01/31/22, 10:20

    ServiceProviderCompilationPassTest.php:223 Reply

    Yup, this basically checks whether wrong factories are catched due to proper type declarations. Therefore it's the php parser that throws the TypeError which is asserted here. Otherwise we could add an `is_callable()` check in https://github.com/TYPO3/typo3/blob/main/typo3/sysext/core/Classes/DependencyInjection/ServiceProviderCompilationPass.php#L90 …and throw an own exception, but I somehow liked `registerService()` automatically asserts the type thanks to PHP type declarations. but I'm not sure what's the best approach here.
  9. Benjamin Franzke commented on patch set 3 01/31/22, 10:26

    ServiceProviderCompilationPassTest.php:223 Reply

    Oh, and btw, PHPStan in currently fine with not adding a `is_callable()` check because the interface defines `@return callable[]`: https://github.com/TYPO3/typo3/blob/main/typo3/sysext/core/Classes/DependencyInjection/ServiceProviderInterface.php#L34
  10. Christian Kuhn commented on patch set 3 01/31/22, 10:29

    ServiceProviderCompilationPassTest.php:223 Reply

    i think we can keep the current approach. using language constructs is usually better than rolling own stuff. question is only if we want to test for this at all since there is little additional value in testing a language construct that is (hopefully) tested in the language already.
  11. Christian Kuhn commented on patch set 3 01/31/22, 10:33

    ServiceProviderCompilationPassTest.php:223 Reply

    as far as i can see, the only value of the test is that it basically checks if there is a 'callable' type hint in our implementation. unsure if that is worth it.
  12. Benjamin Franzke commented on patch set 3 01/31/22, 10:37

    ServiceProviderCompilationPassTest.php:223 Reply

    your analysis is right, that is the only check that is done in that test method, yea. I'm also unsure if that is worth it. :\
  13. Christian Kuhn commented on patch set 3 01/31/22, 10:39

    ServiceProviderCompilationPassTest.php:223 Reply

    imho: drop the test ;) but that's my personal taste in those cases. you decide, i can live and will vote both.
  14. Benjamin Franzke uploaded patch set 4 01/31/22, 10:57

  15. Benjamin Franzke commented on patch set 4 01/31/22, 10:57

    ServiceProviderCompilationPassTest.php:223 Reply

    removed.
  16. core-ci voted on patch set 4 V -1 01/31/22, 10:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22789

  17. Benjamin Franzke uploaded patch set 5 01/31/22, 11:03

  18. core-ci voted on patch set 5 V +1 01/31/22, 11:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/22792

  19. Christian Kuhn voted on patch set 5 V +1 CR +1 01/31/22, 11:24

  20. Benni Mack voted on patch set 5 V +1 CR +1 01/31/22, 12:01

  21. Benjamin Franzke voted on patch set 5 V +2 CR +2 01/31/22, 12:07

  22. Benjamin Franzke merged patch set 6 01/31/22, 12:07