contao icon indicating copy to clipboard operation
contao copied to clipboard

Test the service arguments

Open aschempp opened this issue 2 years ago • 12 comments

This is a first step at validating service parameters to make sure https://github.com/contao/contao/pull/6492 does not happen again.

aschempp avatar Nov 06 '23 17:11 aschempp

@contao/developers Is this correct as a functional test or should it be a service in the tools/ folder like our service linter?

leofeyer avatar Jan 04 '24 12:01 leofeyer

I don't think this is a tool, it runs within the applications and accesses the instantiated container objects.

aschempp avatar Jan 05 '24 07:01 aschempp

PHPStan still reports some errors. And what about the TODO on line 120? Does this need to be addressed before we merge the PR or is it a long-running task?

leofeyer avatar Jan 05 '24 11:01 leofeyer

@aschempp /ping

leofeyer avatar Mar 01 '24 17:03 leofeyer

phpstan is fixed.

And what about the TODO on line 120?

Its a long running task, something that could be investigated on later. But this PR would already catch a lot of potential issues I think.

aschempp avatar Mar 04 '24 07:03 aschempp

The code works now, but it generates a lot of unnecessary warnings about things we can't change:


  • Service was removed.
  • Argument does not allow NULL, assuming this parameter is set at runtime.
  • Cannot yet handle tagged values.

We cannot change any of this, so we shouldn‘t warn about it.


  • Cannot validate argument, because it does not have a supported type hint.

This is only helpful if we control the class. Currently it warns me about Symfony\Cmf\Component\Routing\DynamicRouter, but that's not our class, so again there's nothing we can do.

leofeyer avatar Mar 05 '24 11:03 leofeyer

So you would suggest to silently ignore the warnings (for now)? Regarding the argument validation, we could check for a namespace or something thelike?

aschempp avatar Mar 06 '24 11:03 aschempp

Yes, I‘d only warn about things that we can actually fix.

leofeyer avatar Mar 06 '24 14:03 leofeyer

Tests updated, also added tests for TaggedValue. Failing Require checker checks seem unrelated.

aschempp avatar Jul 08 '24 05:07 aschempp

There are still warnings and a lot of skipped tests.

It almost seems like the former warnings have been turned into skipped tests now.

leofeyer avatar Jul 08 '24 12:07 leofeyer

That is correct. Tests are skipped if they cannot be performed. Is that a problem?

aschempp avatar Jul 11 '24 15:07 aschempp

@ausi had the idea to simply skip tests in the dataProvider if the service does not exist 😅 should be better now.

aschempp avatar Jul 25 '24 13:07 aschempp

I have decided to rebase this onto Contao 5.3, because of our upstream discussion and because we could not correctly validate union types in PHP 7.

aschempp avatar Nov 02 '24 04:11 aschempp

Thank you @aschempp.

leofeyer avatar Dec 09 '24 15:12 leofeyer