-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DomCrawler] Added Crawler::innerText() method #42338
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
Conversation
/** | ||
* Tests that innerText() returns only text that is the direct descendent of the current node, in contrast to | ||
* text() that returns the text of all child nodes. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test scenario is not needed, in a technical sense, but it is needed in a maintainability sense. It conveys what the original intent of the test is, which helps greatly in determining how to fix it when it should break in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my POV we can keep it, but testInnerText()
method name makes clear what's the point here 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, but I think writing test scenarios is a good habit to be into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we use this anywhere else in the DomCrawler's test suite? If not, I am in favour of removing the comment and, if necessary, change the method name to something like testInnerTextReturnsContentOfDirectDescendantTextNodesExclusively()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strongly disagree. Prose is much easier to read as space-separated words instead of stuffing entire sentences into camel-cased method names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case testInnerText()
is enough
*/ | ||
public function innerText(): string | ||
{ | ||
return $this->filterXPath('.//text()')->text(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be expressed as child::node()/text()
. I don't know which is "better".
@Bilge Can you take suggestions into account? |
@fabpot Suggestions have been taken into account. |
Thank you @Bilge. |
Adds a method to get the inner text that is directly descended from the current node only, ignoring text nodes in any child nodes.