Skip to content

[DomCrawler] Revert previous restriction, allow selection of every DOMNode object #17035

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

Closed
wants to merge 7 commits into from
Closed

[DomCrawler] Revert previous restriction, allow selection of every DOMNode object #17035

wants to merge 7 commits into from

Conversation

EdgarPE
Copy link
Contributor

@EdgarPE EdgarPE commented Dec 16, 2015

Q A
Bug fix? no
New feature? yes, revert to previous behaviour
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16933
License MIT
Doc PR

This is a backport of PR #17021

@stof
Copy link
Member

stof commented Dec 16, 2015

you need to update the phpdoc of Crawler in a few place talking about DomElement though

@@ -709,6 +705,10 @@ public function link($method = 'get')

$node = $this->getNode(0);

if (!$node instanceof \DOMElement) {
throw new \InvalidArgumentException(sprintf("The current node list should contain only DOMElement instances, '%s' found.", get_class($node)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enclose the message in single quotes please.

@EdgarPE
Copy link
Contributor Author

EdgarPE commented Dec 21, 2015

Rebased changes. DomCrawler tests still pass.

$crawler = new Crawler();
$crawler->add(new \DOMNode());
$crawler = $this->createTestCrawler();
$crawler->addHtmlContent('<html><div class="foo"></html>', 'UTF-8');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding a test without any assertion here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to test the deprecation notice, but it's out of scope of this PR, so just removed it.

@stof
Copy link
Member

stof commented Dec 22, 2015

👍

@@ -709,6 +705,10 @@ public function link($method = 'get')

$node = $this->getNode(0);

if (!$node instanceof \DOMElement) {
throw new \InvalidArgumentException(sprintf('The current node list should contain only DOMElement instances, "%s" found.', get_class($node)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo the message is a bit misleading as you only check the type of the first element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest on this? Because only the first node is used my suggestion would be to reword the Exception like this:

throw new \InvalidArgumentException(sprintf('The selected node should be instance of  DOMElement, "%s" found.', get_class($node)));

For the corresponding PHPDoc:

@throws \InvalidArgumentException If the current node list is empty or the selected node is not instance of DOMElement

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that's better.

@jakzal
Copy link
Contributor

jakzal commented Dec 23, 2015

status: reviewed

@jakzal jakzal changed the title Backport to 2.8 of [DomCrawler] Revert previous restriction, allow selection of every DOMNode object [DomCrawler] Revert previous restriction, allow selection of every DOMNode object Dec 23, 2015
@jakzal
Copy link
Contributor

jakzal commented Dec 23, 2015

Thanks @EdgarPE for your excellent work!

jakzal added a commit that referenced this pull request Dec 23, 2015
…ion of every DOMNode object (EdgarPE)

This PR was squashed before being merged into the 2.8 branch (closes #17035).

Discussion
----------

[DomCrawler] Revert previous restriction, allow selection of every DOMNode object

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes, revert to previous behaviour
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16933
| License       | MIT
| Doc PR        |

This is a backport of PR #17021

Commits
-------

d2872a3 [DomCrawler] Revert previous restriction, allow selection of every DOMNode object
@jakzal
Copy link
Contributor

jakzal commented Dec 23, 2015

Looks like gh didn't close this PR automatically.

@jakzal jakzal closed this Dec 23, 2015
This was referenced Dec 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants