Skip to content

Commit 8e27862

Browse files
authored
fix some deprecations (#484)
1 parent 4c22ea1 commit 8e27862

File tree

9 files changed

+63
-36
lines changed

9 files changed

+63
-36
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"ext-libxml": "*",
2323
"php-webdriver/webdriver": "^1.8.2",
2424
"symfony/browser-kit": "^4.4 || ^5.0",
25+
"symfony/deprecation-contracts": "^2.4",
2526
"symfony/dom-crawler": "^4.4 || ^5.0",
2627
"symfony/http-client": "^4.4.11 || ^5.2",
2728
"symfony/polyfill-php72": "^1.9",

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<php>
1212
<env name="KERNEL_CLASS" value="Symfony\Component\Panther\Tests\DummyKernel" />
13-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=1" />
13+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0" />
1414
</php>
1515

1616
<testsuites>

src/DomCrawler/Crawler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ public function previousAll(): self
143143
}
144144

145145
public function parents(): self
146+
{
147+
trigger_deprecation('symfony/panther', '1.1', 'The %s() method is deprecated, use ancestors() instead.', __METHOD__);
148+
149+
return $this->ancestors();
150+
}
151+
152+
public function ancestors(): self
146153
{
147154
return $this->createSubCrawlerFromXpath('ancestor::*', true);
148155
}

src/WebTestAssertionsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private static function getText(string $locator): string
236236
return self::findElement($locator)->getText();
237237
}
238238

239-
return $client->getCrawler()->filter($locator)->text();
239+
return $client->getCrawler()->filter($locator)->text(null, true);
240240
}
241241

242242
/**

tests/ClientTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testWaitFor(string $locator): void
5959
$crawler = $client->request('GET', '/waitfor.html');
6060
$c = $client->waitFor($locator);
6161
$this->assertInstanceOf(Crawler::class, $c);
62-
$this->assertSame('Hello', $crawler->filter('#hello')->text());
62+
$this->assertSame('Hello', $crawler->filter('#hello')->text(null, true));
6363
}
6464

6565
public function testWaitForHiddenInputElement(): void
@@ -86,7 +86,7 @@ public function testWaitForVisibility(string $locator): void
8686
$crawler = $client->request('GET', '/waitfor-element-to-be-visible.html');
8787
$c = $client->waitForVisibility($locator);
8888
$this->assertInstanceOf(Crawler::class, $c);
89-
$this->assertSame('Hello', $crawler->filter('#hello')->text());
89+
$this->assertSame('Hello', $crawler->filter('#hello')->text(null, true));
9090
}
9191

9292
/**
@@ -98,7 +98,7 @@ public function testWaitForInvisibility(string $locator): void
9898
$crawler = $client->request('GET', '/waitfor-element-to-be-invisible.html');
9999
$c = $client->waitForInvisibility($locator);
100100
$this->assertInstanceOf(Crawler::class, $c);
101-
$this->assertSame('', $crawler->filter('#hello')->text());
101+
$this->assertSame('', $crawler->filter('#hello')->text(null, true));
102102
}
103103

104104
/**
@@ -110,7 +110,7 @@ public function testWaitForElementToContain(string $locator): void
110110
$crawler = $client->request('GET', '/waitfor-element-to-contain.html');
111111
$c = $client->waitForElementToContain($locator, 'new content');
112112
$this->assertInstanceOf(Crawler::class, $c);
113-
$this->assertSame('Hello new content', $crawler->filter('#hello')->text());
113+
$this->assertSame('Hello new content', $crawler->filter('#hello')->text(null, true));
114114
}
115115

116116
/**
@@ -122,7 +122,7 @@ public function testWaitForElementToNotContain(string $locator): void
122122
$crawler = $client->request('GET', '/waitfor-element-to-not-contain.html');
123123
$c = $client->waitForElementToNotContain($locator, 'removed content');
124124
$this->assertInstanceOf(Crawler::class, $c);
125-
$this->assertSame('Hello', $crawler->filter('#hello')->text());
125+
$this->assertSame('Hello', $crawler->filter('#hello')->text(null, true));
126126
}
127127

128128
/**
@@ -234,7 +234,7 @@ public function testRefreshCrawler(): void
234234
$crawler = $client->request('GET', '/js-redirect.html');
235235
$linkCrawler = $crawler->selectLink('Redirect Link');
236236

237-
$this->assertSame('Redirect Link', $linkCrawler->text());
237+
$this->assertSame('Redirect Link', $linkCrawler->text(null, true));
238238

239239
$client->click($linkCrawler->link());
240240
$client->wait(5)->until(WebDriverExpectedCondition::titleIs('A basic page'));
@@ -243,7 +243,7 @@ public function testRefreshCrawler(): void
243243

244244
$this->assertInstanceOf(Crawler::class, $refreshedCrawler);
245245
$this->assertSame(self::$baseUri.'/basic.html', $refreshedCrawler->getUri());
246-
$this->assertSame('Hello', $refreshedCrawler->filter('h1')->text());
246+
$this->assertSame('Hello', $refreshedCrawler->filter('h1')->text(null, true));
247247
}
248248

249249
/**
@@ -282,15 +282,15 @@ public function testSubmitForm(callable $clientFactory): void
282282
$this->assertInstanceOf(Crawler::class, $crawler);
283283
}
284284
$this->assertSame(self::$baseUri.'/form-handle.php', $crawler->getUri());
285-
$this->assertSame('I1: Reclus', $crawler->filter('#result')->text());
285+
$this->assertSame('I1: Reclus', $crawler->filter('#result')->text(null, true));
286286

287287
$crawler = $client->back();
288288
$form = $crawler->filter('form')->eq(0)->form([
289289
'i1' => 'Michel',
290290
]);
291291

292292
$crawler = $client->submit($form);
293-
$this->assertSame('I1: n/a', $crawler->filter('#result')->text());
293+
$this->assertSame('I1: n/a', $crawler->filter('#result')->text(null, true));
294294
$this->assertSame(self::$baseUri.'/form-handle.php?i1=Michel&i2=&i3=&i4=i4a', $crawler->getUri());
295295
}
296296

@@ -312,7 +312,7 @@ public function testSubmitFormWithValues(callable $clientFactory, string $type):
312312
$this->assertInstanceOf(Crawler::class, $crawler);
313313
}
314314
$this->assertSame(self::$baseUri.'/form-handle.php', $crawler->getUri());
315-
$this->assertSame('I1: Reclus', $crawler->filter('#result')->text());
315+
$this->assertSame('I1: Reclus', $crawler->filter('#result')->text(null, true));
316316
}
317317

318318
/**
@@ -353,7 +353,7 @@ public function testCookie(callable $clientFactory, string $type): void
353353
$cookieJar->clear(); // Firefox keeps the existing context by default, be sure to clear existing cookies
354354

355355
$crawler = $client->request('GET', self::$baseUri.'/cookie.php');
356-
$this->assertSame('0', $crawler->filter('#barcelona')->text());
356+
$this->assertSame('0', $crawler->filter('#barcelona')->text(null, true));
357357

358358
$this->assertInstanceOf(BrowserKitCookieJar::class, $cookieJar);
359359
if (Client::class === $type) {
@@ -378,7 +378,7 @@ public function testCookie(callable $clientFactory, string $type): void
378378
$this->assertNotNull($cookieJar->get('barcelona', '/cookie.php/bar', '127.0.0.1'));
379379

380380
$crawler = $client->reload();
381-
$this->assertSame('1', $crawler->filter('#barcelona')->text());
381+
$this->assertSame('1', $crawler->filter('#barcelona')->text(null, true));
382382

383383
$this->assertNotEmpty($cookieJar->all());
384384
$cookieJar->clear();
@@ -387,8 +387,8 @@ public function testCookie(callable $clientFactory, string $type): void
387387
$cookieJar->set(new Cookie('foo', 'bar'));
388388
$crawler = $client->reload();
389389
$this->assertSame('bar', $cookieJar->get('foo')->getValue());
390-
$this->assertSame('0', $crawler->filter('#barcelona')->text());
391-
$this->assertSame('bar', $crawler->filter('#foo')->text());
390+
$this->assertSame('0', $crawler->filter('#barcelona')->text(null, true));
391+
$this->assertSame('bar', $crawler->filter('#foo')->text(null, true));
392392

393393
$cookieJar->expire('foo');
394394
$this->assertNull($cookieJar->get('foo'));

tests/DomCrawler/CrawlerTest.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ public function testFilterXpath(callable $clientFactory): void
7171
$crawler->filterXPath('descendant-or-self::body/p')->each(function (Crawler $crawler, int $i) {
7272
switch ($i) {
7373
case 0:
74-
$this->assertSame('P1', $crawler->text());
74+
$this->assertSame('P1', $crawler->text(null, true));
7575
break;
7676
case 1:
77-
$this->assertSame('P2', $crawler->text());
77+
$this->assertSame('P2', $crawler->text(null, true));
7878
break;
7979
case 2:
80-
$this->assertSame('36', $crawler->text());
80+
$this->assertSame('36', $crawler->text(null, true));
8181
break;
8282
default:
8383
$this->fail(sprintf('Unexpected index "%d".', $i));
@@ -95,10 +95,10 @@ public function testFilter(callable $clientFactory): void
9595

9696
$texts = [];
9797
$crawler->filter('main > p')->each(function (Crawler $crawler, int $i) use (&$texts) {
98-
$texts[$i] = $crawler->text();
98+
$texts[$i] = $crawler->text(null, true);
9999
});
100100
$this->assertSame(['Sibling', 'Sibling 2', 'Sibling 3'], $texts);
101-
$this->assertSame('Sibling 2', $crawler->filter('main')->filter('#a-sibling')->text());
101+
$this->assertSame('Sibling 2', $crawler->filter('main')->filter('#a-sibling')->text(null, true));
102102
}
103103

104104
/**
@@ -129,7 +129,7 @@ public function testEq(callable $clientFactory): void
129129
public function testFirst(callable $clientFactory): void
130130
{
131131
$crawler = $this->request($clientFactory, '/basic.html');
132-
$this->assertSame('Sibling', $crawler->filter('main > p')->first()->text());
132+
$this->assertSame('Sibling', $crawler->filter('main > p')->first()->text(null, true));
133133
}
134134

135135
/**
@@ -138,7 +138,7 @@ public function testFirst(callable $clientFactory): void
138138
public function testLast(callable $clientFactory): void
139139
{
140140
$crawler = $this->request($clientFactory, '/basic.html');
141-
$this->assertSame('Sibling 3', $crawler->filter('main > p')->last()->text());
141+
$this->assertSame('Sibling 3', $crawler->filter('main > p')->last()->text(null, true));
142142
}
143143

144144
/**
@@ -150,7 +150,7 @@ public function testSiblings(callable $clientFactory): void
150150

151151
$texts = [];
152152
$crawler->filter('main > p')->siblings()->each(function (Crawler $c, int $i) use (&$texts) {
153-
$texts[$i] = $c->text();
153+
$texts[$i] = $c->text(null, true);
154154
});
155155

156156
$this->assertSame(['Main', 'Sibling 2', 'Sibling 3'], $texts);
@@ -165,7 +165,7 @@ public function testNextAll(callable $clientFactory): void
165165

166166
$texts = [];
167167
$crawler->filter('main > p')->nextAll()->each(function (Crawler $c, int $i) use (&$texts) {
168-
$texts[$i] = $c->text();
168+
$texts[$i] = $c->text(null, true);
169169
});
170170

171171
$this->assertSame(['Sibling 2', 'Sibling 3'], $texts);
@@ -180,7 +180,7 @@ public function testPreviousAll(callable $clientFactory): void
180180

181181
$texts = [];
182182
$crawler->filter('main > p')->previousAll()->each(function (Crawler $c, int $i) use (&$texts) {
183-
$texts[$i] = $c->text();
183+
$texts[$i] = $c->text(null, true);
184184
});
185185

186186
$this->assertSame(['Main'], $texts);
@@ -220,6 +220,7 @@ public function testChildrenFilter($clientFactory): void
220220

221221
/**
222222
* @dataProvider clientFactoryProvider
223+
* @group legacy
223224
*/
224225
public function testParents(callable $clientFactory): void
225226
{
@@ -233,6 +234,24 @@ public function testParents(callable $clientFactory): void
233234
$this->assertSame(['main', 'body', 'html'], $names);
234235
}
235236

237+
/**
238+
* @dataProvider clientFactoryProvider
239+
*/
240+
public function testAncestors(callable $clientFactory): void
241+
{
242+
$crawler = $this->request($clientFactory, '/basic.html');
243+
if (!method_exists($crawler, 'ancestors')) {
244+
$this->markTestSkipped('Crawler::ancestors() doesn\'t exist.');
245+
}
246+
247+
$names = [];
248+
$crawler->filter('main > h1')->ancestors()->each(function (Crawler $c, int $i) use (&$names) {
249+
$names[$i] = $c->nodeName();
250+
});
251+
252+
$this->assertSame(['main', 'body', 'html'], $names);
253+
}
254+
236255
/**
237256
* @dataProvider clientFactoryProvider
238257
*/
@@ -329,7 +348,7 @@ public function testNormalizeText(callable $clientFactory, string $clientClass):
329348
}
330349

331350
$crawler = $this->request($clientFactory, '/normalize.html');
332-
$this->assertSame('Foo Bar Baz', $crawler->filter('#normalize')->text());
351+
$this->assertSame('Foo Bar Baz', $crawler->filter('#normalize')->text(null, true));
333352
}
334353

335354
public function testDoNotNormalizeText(): void

tests/FutureAssertionsTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testFutureExistenceAssertion(string $locator): void
2020
{
2121
$crawler = self::createPantherClient()->request('GET', '/waitfor.html');
2222
$this->assertSelectorWillExist($locator);
23-
$this->assertSame('Hello', $crawler->filter('#hello')->text());
23+
$this->assertSame('Hello', $crawler->filter('#hello')->text(null, true));
2424
}
2525

2626
/** @dataProvider futureDataProvider */
@@ -36,7 +36,7 @@ public function testFutureVisibilityAssertion(string $locator): void
3636
{
3737
$crawler = self::createPantherClient()->request('GET', '/waitfor-element-to-be-visible.html');
3838
$this->assertSelectorWillBeVisible($locator);
39-
$this->assertSame('Hello', $crawler->filter('#hello')->text());
39+
$this->assertSame('Hello', $crawler->filter('#hello')->text(null, true));
4040
$this->assertSelectorExists($locator);
4141
}
4242

@@ -45,23 +45,23 @@ public function testFutureInvisibilityAssertion(string $locator): void
4545
{
4646
$crawler = self::createPantherClient()->request('GET', '/waitfor-element-to-be-invisible.html');
4747
$this->assertSelectorWillNotBeVisible($locator);
48-
$this->assertSame('', $crawler->filter('#hello')->text());
48+
$this->assertSame('', $crawler->filter('#hello')->text(null, true));
4949
}
5050

5151
/** @dataProvider futureDataProvider */
5252
public function testFutureContainAssertion(string $locator): void
5353
{
5454
$crawler = self::createPantherClient()->request('GET', '/waitfor-element-to-contain.html');
5555
$this->assertSelectorWillContain($locator, 'new content');
56-
$this->assertSame('Hello new content', $crawler->filter('#hello')->text());
56+
$this->assertSame('Hello new content', $crawler->filter('#hello')->text(null, true));
5757
}
5858

5959
/** @dataProvider futureDataProvider */
6060
public function testFutureNotContainAssertion(string $locator): void
6161
{
6262
$crawler = self::createPantherClient()->request('GET', '/waitfor-element-to-not-contain.html');
6363
$this->assertSelectorWillNotContain($locator, 'removed content');
64-
$this->assertSame('Hello', $crawler->filter('#hello')->text());
64+
$this->assertSame('Hello', $crawler->filter('#hello')->text(null, true));
6565
}
6666

6767
/** @dataProvider futureDataProvider */

tests/MultiClientsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public function testMultiClient(): void
2121
$client->request('GET', '/cookie.php');
2222

2323
$crawler = $client->request('GET', '/cookie.php');
24-
$this->assertSame('1', $crawler->filter('#barcelona')->text());
24+
$this->assertSame('1', $crawler->filter('#barcelona')->text(null, true));
2525

2626
$client2 = self::createAdditionalPantherClient();
2727
$crawler2 = $client2->request('GET', '/cookie.php');
28-
$this->assertSame('0', $crawler2->filter('#barcelona')->text());
28+
$this->assertSame('0', $crawler2->filter('#barcelona')->text(null, true));
2929

3030
// Check that the cookie in the other client hasn't changed
31-
$this->assertSame('1', $crawler->filter('#barcelona')->text());
31+
$this->assertSame('1', $crawler->filter('#barcelona')->text(null, true));
3232
}
3333
}

tests/WebDriver/WebDriverMouseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function test(string $method, string $cssSelector, string $result): void
3333
$client = self::createPantherClient();
3434

3535
$client->getMouse()->{$method}($cssSelector);
36-
$this->assertEquals($result, $client->getCrawler()->filter('#result')->text());
36+
$this->assertEquals($result, $client->getCrawler()->filter('#result')->text(null, true));
3737
}
3838

3939
public function provide(): iterable

0 commit comments

Comments
 (0)