10000 BrowserKit - DomCrawler dependency problem? · Issue #18826 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

BrowserKit - DomCrawler dependency problem? #18826

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
anlutro opened this issue May 20, 2016 · 9 comments
Closed

BrowserKit - DomCrawler dependency problem? #18826

anlutro opened this issue May 20, 2016 · 9 comments

Comments

@anlutro
Copy link
Contributor
anlutro commented May 20, 2016

I've got a project running on Travis CI which fails when requiring "browser-kit": "~2.8|~3.0" and doing composer update --prefer-lowest. A plain composer update works fine.

The code being ran is very simple - $this->client is an instance of Symfony\Component\HttpKernel\Client:

$crawler = $this->client->request('GET', '/');

The error I'm getting:

RuntimeException: Unable to filter with a CSS selector as the Symfony CssSelector is not installed (you can use filterXPath instead).
/home/travis/build/autarky/skeleton/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/Crawler.php:511
/home/travis/build/autarky/skeleton/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/Crawler.php:123
/home/travis/build/autarky/skeleton/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/Crawler.php:103
/home/travis/build/autarky/skeleton/vendor/symfony/browser-kit/Client.php:423
/home/travis/build/autarky/skeleton/vendor/symfony/browser-kit/Client.php:336
/home/travis/build/autarky/skeleton/tests/ExampleTest.php:45

I'm not even using CSS filtering, so the error is rather confusing.

I suspect the reason being that browser-kit allows very old versions of the DomCrawler component, which maybe aren't compatible:

"symfony/dom-crawler": "~2.0,>=2.0.5|~3.0.0"

Here's a link to the full Travis CI job: https://travis-ci.org/autarky/skeleton/jobs/131778658#L145

@anlutro
Copy link
Contributor Author
anlutro commented May 20, 2016

Also noteworthy, this also wouldn't be caught by your test suite as the CssSelector component is added as a require-dev of the BrowserKit component.

@anlutro
Copy link
Contributor Author
anlutro commented May 20, 2016

It seems like the dependency on CssSelector was removed in 3e95126, which is in version 2.1.0 and up.

@anlutro
Copy link
Contributor Author
anlutro commented May 20, 2016

It seems like the exact time when the error starts happening is when going from 2.6.1 to 2.6.2:

  - Removing symfony/dom-crawler (2.0.4)
  - Installing symfony/dom-crawler (2.0.5)

  - Removing symfony/browser-kit (v2.6.1)
  - Installing symfony/browser-kit (v2.6.2)

But I've no idea why, as I can't see any noteworthy code changes to those components by doing git diff v2.0.4..v2.0.5 DomCrawler or git diff v2.6.1..v2.6.2 BrowserKit.

@javiereguiluz
Copy link
Member
javiereguiluz commented Jun 1, 2016

Looking at your Travis logs, the issue is that the old 2.0.x DomCrawler throws this exception if CssSelector is not found:

if (!class_exists('Symfony\\Component\\CssSelector\\CssSelector')) {
    // @codeCoverageIgnoreStart
    throw new \RuntimeException('Unable to filter with a CSS selector as the Symfony CssSelector is not installed (you can use filterXPath instead).');
    // @codeCoverageIgnoreEnd
}

This is thrown in the filter() method. Although you don't call that method explicitly, it's called indirectly in the constructor of DomCrawler due to the $this->add($node) instruction.

Although CssSelector is mandatory to run DomCrawler ... its composer.json file in 2.0 says that it is optional: https://github.com/symfony/symfony/blob/2.0/src/Symfony/Component/DomCrawler/composer.json


Should we fix the low dependencies of BrowserKit?

@stof
Copy link
Member
stof commented Jun 1, 2016

@javiereguiluz given that 2.0 is unmaintained since years, we won't change its composer.json

@javiereguiluz
Copy link
Member

@stof it looks like BrowserKit 2.3 allows DomCrawler 2.0: https://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/BrowserKit/composer.json

@stof
Copy link
Member
stof commented Jun 1, 2016

hmm, the DomCrawler class is indeed broken without CssSelector in 2.0.x (was fixed in 2.1)

@xabbuh
Copy link
Member
xabbuh commented Jun 5, 2016

@stof Even in more recent Symfony versions the CssSelector component is only part of the require-dev section but is not present in require (and the code in the filter() method didn't change).

@stof
Copy link
Member
stof commented Jun 6, 2016

@xabbuh sure, but adding content does not rely on filter anymore since 2.1. It relies on XPath filtering rather than CSS filtering.
The CssSelector is an optional dependency needed to use filter, but DomCrawler does not use filter internally anymore.

fabpot added a commit that referenced this issue Jun 6, 2016
…ement (jakzal)

This PR was submitted for the 2.3 branch but it was merged into the 2.7 branch instead (closes #18980).

Discussion
----------

[BrowserKit] Bump the dom-crawler minimum version requirement

| Q             | A
| ------------- | ---
| Branch?       | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18826
| License       | MIT
| Doc PR        | -

The BrowserKit Client will not work with DomCrawler 2.0 if the CssSelector component is not installed.

This will require an amendment when merging into the 2.8 branch. It currently uses `~2.0,>=2.0.5|~3.0.0`, while it should be `~2.1|~3.0.0`.

Commits
-------

5579d86 [BrowserKit] Bump dom-crawler minimum version requirement
@fabpot fabpot closed this as completed Jun 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
0