-
Notifications
You must be signed in to change notification settings - Fork 4
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
Test standalone template renders #425
Comments
@MartinMystikJonas do you think it is possible to create generic solution for this? or we have to implement it in each project against its specific requirements? |
I am not sure I understand that use-case corerctly but if I fot it that I do not think there could be universal solution for that. We have no way to know which places to consider analysis "entry points" for lette tempalte context collecting. Currently this could be solved by custom LatteTemplateResolvers But I think we can do two things to make it easier for users.
|
My use case:
I wanted t find all Template->render() / Template->renderToString() calls, but I realize I don't know how to collect data for them. That's why I asked the question before. You've confirmed my thoughts that it couldn't be universal solution. |
Basically I want the createTemplate to be “entry point” and render / renderToString etc. to be the “end point”. Actual state is that entry point is always Class method, but that’s not always truth. |
Entry point must be class method for other parts of analysis to work (eslecially call chains). We could find all methods containing createTemplate and use them as entry points. But it could easily generate tons of false positives if context is set outside such method. Example: Method A calls B. B contains createTemplate and returns created template. A then sets context to template and calls render. In this scenario A is our correct entry point. But createTemplate is in B. |
And this is imho wrong design we use here :) entry point is class method only for components and presenters. Because the template is created there magically.
If we call e.g. sendResponse($template); sooner than some variable is assigned to template, we have false positive / negative too.
Yes but this is the problem also now. We can't know if the context is added to correct template in some method call where the template is passed.
I have to think about it. For now I'll create some Resolvers for our use cases. |
I am afraid that what you want is not possible by using static analysis of PHPStan. We would need something that works as "almost interpreter" to track lifecycle of template across codebase to solve it. It would be better but orders of magnitude more complex. |
Yes I know :( |
Let's say we have some custom service, where is TemplateFactory to create Template and then it is rendered to string. This should be tested too
The text was updated successfully, but these errors were encountered: