-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DX] Add new methods to DomCrawler to simplify some functional tests #11470
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
Comments
This is just a ping on this uncommented issue. Is this something that someone could find it useful? Would you solve this "problem" using a different and more elegant approach? |
For what its worth I normally use assertContains in a method where I'm checking for presence of a string. I've never found being explicit about exact markup to be very helpful given the markup can change (along with exact contents of markup). |
@merk thanks for your comment. I agree with you about not needing to validate the exact HTML markup. But my use case is a bit different. In the applications that we develop, HTML contents are always tabulated and broken into several lines to improve its readability: <p>
Lorem ipsum dolor sit amet,
consectetur adipisicing elit,
sed do eiusmod tempor incididunt.
</p> As you can see, the |
My point is more that is unnecessary to test for the presence of the entire string in your |
@merk I see it. Let's wait a bit more to see if we receive any other opinion. Otherwise, I will close this issue. Thanks. |
+1 to @merk 's comments |
very good points @merk 👍 |
Closing, as everybody agrees on not needing these methods. Thanks for your comments! |
The problem
The whitespace inside the HTML contents makes some functional tests harder than
they should be. Consider that you want to check the contents the following
element:
This test will fail:
You can obviously apply the
trim()
function, but this solution feelsunnatural:
The problem is worse when dealing with spaces and newlines:
This solution no longer works:
The solution
DomCrawler component could add two new methods called
trim()
andflatten()
.The first one is equivalent to the PHP's
trim()
function:The second one would also remove new lines and trim two or more spaces between
lines:
My questions: is it worth it adding these two helper methods? Should I instead
create better tests? Can you think of a better solution to solve this problem?
The text was updated successfully, but these errors were encountered: