Skip to content

Commit

Permalink
fix some deprecations (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas authored Jul 13, 2021
1 parent 4c22ea1 commit 8e27862
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 36 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ext-libxml": "*",
"php-webdriver/webdriver": "^1.8.2",
"symfony/browser-kit": "^4.4 || ^5.0",
"symfony/deprecation-contracts": "^2.4",
"symfony/dom-crawler": "^4.4 || ^5.0",
"symfony/http-client": "^4.4.11 || ^5.2",
"symfony/polyfill-php72": "^1.9",
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<php>
<env name="KERNEL_CLASS" value="Symfony\Component\Panther\Tests\DummyKernel" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0" />
</php>

<testsuites>
Expand Down
7 changes: 7 additions & 0 deletions src/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ public function previousAll(): self
}

public function parents(): self
{
trigger_deprecation('symfony/panther', '1.1', 'The %s() method is deprecated, use ancestors() instead.', __METHOD__);

return $this->ancestors();
}

public function ancestors(): self
{
return $this->createSubCrawlerFromXpath('ancestor::*', true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/WebTestAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private static function getText(string $locator): string
return self::findElement($locator)->getText();
}

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

/**
Expand Down
28 changes: 14 additions & 14 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testWaitFor(string $locator): void
$crawler = $client->request('GET', '/waitfor.html');
$c = $client->waitFor($locator);
$this->assertInstanceOf(Crawler::class, $c);
$this->assertSame('Hello', $crawler->filter('#hello')->text());
$this->assertSame('Hello', $crawler->filter('#hello')->text(null, true));
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$cookieJar->expire('foo');
$this->assertNull($cookieJar->get('foo'));
Expand Down
41 changes: 30 additions & 11 deletions tests/DomCrawler/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public function testFilterXpath(callable $clientFactory): void
$crawler->filterXPath('descendant-or-self::body/p')->each(function (Crawler $crawler, int $i) {
switch ($i) {
case 0:
$this->assertSame('P1', $crawler->text());
$this->assertSame('P1', $crawler->text(null, true));
break;
case 1:
$this->assertSame('P2', $crawler->text());
$this->assertSame('P2', $crawler->text(null, true));
break;
case 2:
$this->assertSame('36', $crawler->text());
$this->assertSame('36', $crawler->text(null, true));
break;
default:
$this->fail(sprintf('Unexpected index "%d".', $i));
Expand All @@ -95,10 +95,10 @@ public function testFilter(callable $clientFactory): void

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

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

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

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

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

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

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

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

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

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

/**
* @dataProvider clientFactoryProvider
* @group legacy
*/
public function testParents(callable $clientFactory): void
{
Expand All @@ -233,6 +234,24 @@ public function testParents(callable $clientFactory): void
$this->assertSame(['main', 'body', 'html'], $names);
}

/**
* @dataProvider clientFactoryProvider
*/
public function testAncestors(callable $clientFactory): void
{
$crawler = $this->request($clientFactory, '/basic.html');
if (!method_exists($crawler, 'ancestors')) {
$this->markTestSkipped('Crawler::ancestors() doesn\'t exist.');
}

$names = [];
$crawler->filter('main > h1')->ancestors()->each(function (Crawler $c, int $i) use (&$names) {
$names[$i] = $c->nodeName();
});

$this->assertSame(['main', 'body', 'html'], $names);
}

/**
* @dataProvider clientFactoryProvider
*/
Expand Down Expand Up @@ -329,7 +348,7 @@ public function testNormalizeText(callable $clientFactory, string $clientClass):
}

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

public function testDoNotNormalizeText(): void
Expand Down
10 changes: 5 additions & 5 deletions tests/FutureAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testFutureExistenceAssertion(string $locator): void
{
$crawler = self::createPantherClient()->request('GET', '/waitfor.html');
$this->assertSelectorWillExist($locator);
$this->assertSame('Hello', $crawler->filter('#hello')->text());
$this->assertSame('Hello', $crawler->filter('#hello')->text(null, true));
}

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

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

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

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

/** @dataProvider futureDataProvider */
Expand Down
6 changes: 3 additions & 3 deletions tests/MultiClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public function testMultiClient(): void
$client->request('GET', '/cookie.php');

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

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

// Check that the cookie in the other client hasn't changed
$this->assertSame('1', $crawler->filter('#barcelona')->text());
$this->assertSame('1', $crawler->filter('#barcelona')->text(null, true));
}
}
2 changes: 1 addition & 1 deletion tests/WebDriver/WebDriverMouseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function test(string $method, string $cssSelector, string $result): void
$client = self::createPantherClient();

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

public function provide(): iterable
Expand Down

0 comments on commit 8e27862

Please sign in to comment.