Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 414de14

Browse filesBrowse files
[DomCrawler] Support classes from the new DOM extension
1 parent 3f2ed0f commit 414de14
Copy full SHA for 414de14

37 files changed

+1774
-482
lines changed

‎UPGRADE-7.1.md

Copy file name to clipboardExpand all lines: UPGRADE-7.1.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Cache
1111

1212
* Deprecate `CouchbaseBucketAdapter`, use `CouchbaseCollectionAdapter` instead
1313

14+
DomCrawler
15+
----------
16+
17+
* Deprecate `Crawler`, use `DomCrawler` instead
18+
1419
ExpressionLanguage
1520
------------------
1621

‎src/Symfony/Bundle/FrameworkBundle/Test/DomCrawlerAssertionsTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Test/DomCrawlerAssertionsTrait.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\Constraint\LogicalAnd;
1515
use PHPUnit\Framework\Constraint\LogicalNot;
16-
use Symfony\Component\DomCrawler\Crawler;
16+
use Symfony\Component\DomCrawler\DomCrawler;
1717
use Symfony\Component\DomCrawler\Test\Constraint as DomCrawlerConstraint;
1818
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorExists;
1919

@@ -140,7 +140,7 @@ public static function assertNoFormValue(string $formSelector, string $fieldName
140140
self::assertArrayNotHasKey($fieldName, $values, $message ?: sprintf('Field "%s" has a value in form "%s".', $fieldName, $formSelector));
141141
}
142142

143-
private static function getCrawler(): Crawler
143+
private static function getCrawler(): DomCrawler
144144
{
145145
if (!$crawler = self::getClient()->getCrawler()) {
146146
static::fail('A client must have a crawler to make assertions. Did you forget to make an HTTP request?');

‎src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Test/WebTestCaseTest.php
+36-36Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
2020
use Symfony\Component\BrowserKit\Cookie;
2121
use Symfony\Component\BrowserKit\CookieJar;
22-
use Symfony\Component\DomCrawler\Crawler;
22+
use Symfony\Component\DomCrawler\DomCrawler;
2323
use Symfony\Component\HttpFoundation\Cookie as HttpFoundationCookie;
2424
use Symfony\Component\HttpFoundation\Request;
2525
use Symfony\Component\HttpFoundation\Response;
@@ -192,126 +192,126 @@ public function testAssertBrowserCookieValueSame()
192192

193193
public function testAssertSelectorExists()
194194
{
195-
$this->getCrawlerTester(new Crawler('<html><body><h1>'))->assertSelectorExists('body > h1');
195+
$this->getCrawlerTester(new DomCrawler('<html><body><h1>'))->assertSelectorExists('body > h1');
196196
$this->expectException(AssertionFailedError::class);
197197
$this->expectExceptionMessage('matches selector "body > h1".');
198-
$this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertSelectorExists('body > h1');
198+
$this->getCrawlerTester(new DomCrawler('<html><head><title>Foo'))->assertSelectorExists('body > h1');
199199
}
200200

201201
public function testAssertSelectorNotExists()
202202
{
203-
$this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertSelectorNotExists('body > h1');
203+
$this->getCrawlerTester(new DomCrawler('<html><head><title>Foo'))->assertSelectorNotExists('body > h1');
204204
$this->expectException(AssertionFailedError::class);
205205
$this->expectExceptionMessage('does not match selector "body > h1".');
206-
$this->getCrawlerTester(new Crawler('<html><body><h1>'))->assertSelectorNotExists('body > h1');
206+
$this->getCrawlerTester(new DomCrawler('<html><body><h1>'))->assertSelectorNotExists('body > h1');
207207
}
208208

209209
public function testAssertSelectorCount()
210210
{
211-
$this->getCrawlerTester(new Crawler('<html><body><p>Hello</p></body></html>'))->assertSelectorCount(1, 'p');
212-
$this->getCrawlerTester(new Crawler('<html><body><p>Hello</p><p>Foo</p></body></html>'))->assertSelectorCount(2, 'p');
213-
$this->getCrawlerTester(new Crawler('<html><body><h1>This is not a paragraph.</h1></body></html>'))->assertSelectorCount(0, 'p');
211+
$this->getCrawlerTester(new DomCrawler('<html><body><p>Hello</p></body></html>'))->assertSelectorCount(1, 'p');
212+
$this->getCrawlerTester(new DomCrawler('<html><body><p>Hello</p><p>Foo</p></body></html>'))->assertSelectorCount(2, 'p');
213+
$this->getCrawlerTester(new DomCrawler('<html><body><h1>This is not a paragraph.</h1></body></html>'))->assertSelectorCount(0, 'p');
214214
$this->expectException(AssertionFailedError::class);
215215
$this->expectExceptionMessage('Failed asserting that the Crawler selector "p" was expected to be found 0 time(s) but was found 1 time(s).');
216-
$this->getCrawlerTester(new Crawler('<html><body><p>Hello</p></body></html>'))->assertSelectorCount(0, 'p');
216+
$this->getCrawlerTester(new DomCrawler('<html><body><p>Hello</p></body></html>'))->assertSelectorCount(0, 'p');
217217
}
218218

219219
public function testAssertSelectorTextNotContains()
220220
{
221-
$this->getCrawlerTester(new Crawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Bar');
221+
$this->getCrawlerTester(new DomCrawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Bar');
222222
$this->expectException(AssertionFailedError::class);
223223
$this->expectExceptionMessage('matches selector "body > h1" and the text "Foo" of the node matching selector "body > h1" does not contain "Foo".');
224-
$this->getCrawlerTester(new Crawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Foo');
224+
$this->getCrawlerTester(new DomCrawler('<html><body><h1>Foo'))->assertSelectorTextNotContains('body > h1', 'Foo');
225225
}
226226

227227
public function testAssertAnySelectorTextContains()
228228
{
229-
$this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Foo Baz'))->assertAnySelectorTextContains('ul li', 'Foo');
229+
$this->getCrawlerTester(new DomCrawler('<ul><li>Bar</li><li>Foo Baz'))->assertAnySelectorTextContains('ul li', 'Foo');
230230
$this->expectException(AssertionFailedError::class);
231231
$this->expectExceptionMessage('matches selector "ul li" and the text of any node matching selector "ul li" contains "Foo".');
232-
$this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextContains('ul li', 'Foo');
232+
$this->getCrawlerTester(new DomCrawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextContains('ul li', 'Foo');
233233
}
234234

235235
public function testAssertAnySelectorTextSame()
236236
{
237-
$this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Foo'))->assertAnySelectorTextSame('ul li', 'Foo');
237+
$this->getCrawlerTester(new DomCrawler('<ul><li>Bar</li><li>Foo'))->assertAnySelectorTextSame('ul li', 'Foo');
238238
$this->expectException(AssertionFailedError::class);
239239
$this->expectExceptionMessage('matches selector "ul li" and has at least a node matching selector "ul li" with content "Foo".');
240-
$this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextSame('ul li', 'Foo');
240+
$this->getCrawlerTester(new DomCrawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextSame('ul li', 'Foo');
241241
}
242242

243243
public function testAssertAnySelectorTextNotContains()
244244
{
245-
$this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextNotContains('ul li', 'Foo');
245+
$this->getCrawlerTester(new DomCrawler('<ul><li>Bar</li><li>Baz'))->assertAnySelectorTextNotContains('ul li', 'Foo');
246246
$this->expectException(AssertionFailedError::class);
247247
$this->expectExceptionMessage('matches selector "ul li" and the text of any node matching selector "ul li" does not contain "Foo".');
248-
$this->getCrawlerTester(new Crawler('<ul><li>Bar</li><li>Foo'))->assertAnySelectorTextNotContains('ul li', 'Foo');
248+
$this->getCrawlerTester(new DomCrawler('<ul><li>Bar</li><li>Foo'))->assertAnySelectorTextNotContains('ul li', 'Foo');
249249
}
250250

251251
public function testAssertPageTitleSame()
252252
{
253-
$this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertPageTitleSame('Foo');
253+
$this->getCrawlerTester(new DomCrawler('<html><head><title>Foo'))->assertPageTitleSame('Foo');
254254
$this->expectException(AssertionFailedError::class);
255255
$this->expectExceptionMessage('matches selector "title" and has a node matching selector "title" with content "Bar".');
256-
$this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertPageTitleSame('Bar');
256+
$this->getCrawlerTester(new DomCrawler('<html><head><title>Foo'))->assertPageTitleSame('Bar');
257257
}
258258

259259
public function testAssertPageTitleContains()
260260
{
261-
$this->getCrawlerTester(new Crawler('<html><head><title>Foobar'))->assertPageTitleContains('Foo');
261+
$this->getCrawlerTester(new DomCrawler('<html><head><title>Foobar'))->assertPageTitleContains('Foo');
262262
$this->expectException(AssertionFailedError::class);
263263
$this->expectExceptionMessage('matches selector "title" and the text "Foo" of the node matching selector "title" contains "Bar".');
264-
$this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertPageTitleContains('Bar');
264+
$this->getCrawlerTester(new DomCrawler('<html><head><title>Foo'))->assertPageTitleContains('Bar');
265265
}
266266

267267
public function testAssertInputValueSame()
268268
{
269-
$this->getCrawlerTester(new Crawler('<html><body><form><input type="text" name="username" value="Fabien">'))->assertInputValueSame('username', 'Fabien');
269+
$this->getCrawlerTester(new DomCrawler('<html><body><form><input type="text" name="username" value="Fabien">'))->assertInputValueSame('username', 'Fabien');
270270
$this->expectException(AssertionFailedError::class);
271271
$this->expectExceptionMessage('matches selector "input[name="password"]" and has a node matching selector "input[name="password"]" with attribute "value" of value "pa$$".');
272-
$this->getCrawlerTester(new Crawler('<html><head><title>Foo'))->assertInputValueSame('password', 'pa$$');
272+
$this->getCrawlerTester(new DomCrawler('<html><head><title>Foo'))->assertInputValueSame('password', 'pa$$');
273273
}
274274

275275
public function testAssertInputValueNotSame()
276276
{
277-
$this->getCrawlerTester(new Crawler('<html><body><input type="text" name="username" value="Helene">'))->assertInputValueNotSame('username', 'Fabien');
277+
$this->getCrawlerTester(new DomCrawler('<html><body><input type="text" name="username" value="Helene">'))->assertInputValueNotSame('username', 'Fabien');
278278
$this->expectException(AssertionFailedError::class);
279279
$this->expectExceptionMessage('matches selector "input[name="password"]" and does not have a node matching selector "input[name="password"]" with attribute "value" of value "pa$$".');
280-
$this->getCrawlerTester(new Crawler('<html><body><form><input type="text" name="password" value="pa$$">'))->assertInputValueNotSame('password', 'pa$$');
280+
$this->getCrawlerTester(new DomCrawler('<html><body><form><input type="text" name="password" value="pa$$">'))->assertInputValueNotSame('password', 'pa$$');
281281
}
282282

283283
public function testAssertCheckboxChecked()
284284
{
285-
$this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe');
286-
$this->getCrawlerTester(new Crawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe');
285+
$this->getCrawlerTester(new DomCrawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe');
286+
$this->getCrawlerTester(new DomCrawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxChecked('rememberMe');
287287
$this->expectException(AssertionFailedError::class);
288288
$this->expectExceptionMessage('matches selector "input[name="rememberMe"]:checked".');
289-
$this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxChecked('rememberMe');
289+
$this->getCrawlerTester(new DomCrawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxChecked('rememberMe');
290290
}
291291

292292
public function testAssertCheckboxNotChecked()
293293
{
294-
$this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe');
295-
$this->getCrawlerTester(new Crawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe');
294+
$this->getCrawlerTester(new DomCrawler('<html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe');
295+
$this->getCrawlerTester(new DomCrawler('<!DOCTYPE html><body><form><input type="checkbox" name="rememberMe">'))->assertCheckboxNotChecked('rememberMe');
296296
$this->expectException(AssertionFailedError::class);
297297
$this->expectExceptionMessage('does not match selector "input[name="rememberMe"]:checked".');
298-
$this->getCrawlerTester(new Crawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxNotChecked('rememberMe');
298+
$this->getCrawlerTester(new DomCrawler('<html><body><form><input type="checkbox" name="rememberMe" checked>'))->assertCheckboxNotChecked('rememberMe');
299299
}
300300

301301
public function testAssertFormValue()
302302
{
303-
$this->getCrawlerTester(new Crawler('<html><body><form id="form"><input type="text" name="username" value="Fabien">', 'http://localhost'))->assertFormValue('#form', 'username', 'Fabien');
303+
$this->getCrawlerTester(new DomCrawler('<html><body><form id="form"><input type="text" name="username" value="Fabien">', 'http://localhost'))->assertFormValue('#form', 'username', 'Fabien');
304304
$this->expectException(AssertionFailedError::class);
305305
$this->expectExceptionMessage('Failed asserting that two strings are identical.');
306-
$this->getCrawlerTester(new Crawler('<html><body><form id="form"><input type="text" name="username" value="Fabien">', 'http://localhost'))->assertFormValue('#form', 'username', 'Jane');
306+
$this->getCrawlerTester(new DomCrawler('<html><body><form id="form"><input type="text" name="username" value="Fabien">', 'http://localhost'))->assertFormValue('#form', 'username', 'Jane');
307307
}
308308

309309
public function testAssertNoFormValue()
310310
{
311-
$this->getCrawlerTester(new Crawler('<html><body><form id="form"><input type="checkbox" name="rememberMe">', 'http://localhost'))->assertNoFormValue('#form', 'rememberMe');
311+
$this->getCrawlerTester(new DomCrawler('<html><body><form id="form"><input type="checkbox" name="rememberMe">', 'http://localhost'))->assertNoFormValue('#form', 'rememberMe');
312312
$this->expectException(AssertionFailedError::class);
313313
$this->expectExceptionMessage('Field "rememberMe" has a value in form "#form".');
314-
$this->getCrawlerTester(new Crawler('<html><body><form id="form"><input type="checkbox" name="rememberMe" checked>', 'http://localhost'))->assertNoFormValue('#form', 'rememberMe');
314+
$this->getCrawlerTester(new DomCrawler('<html><body><form id="form"><input type="checkbox" name="rememberMe" checked>', 'http://localhost'))->assertNoFormValue('#form', 'rememberMe');
315315
}
316316

317317
public function testAssertRequestAttributeValueSame()
@@ -357,7 +357,7 @@ private function getResponseTester(Response $response): WebTestCase
357357
return $this->getTester($client);
358358
}
359359

360-
private function getCrawlerTester(Crawler $crawler): WebTestCase
360+
private function getCrawlerTester(DomCrawler $crawler): WebTestCase
361361
{
362362
$client = $this->createMock(KernelBrowser::class);
363363
$client->expects($this->any())->method('getCrawler')->willReturn($crawler);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.