Skip to content

Commit

Permalink
bug #33278 [FrameworkBundle] Fix BrowserKit assertions to make them c…
Browse files Browse the repository at this point in the history
…ompatible with Panther (dunglas)

This PR was merged into the 4.3 branch.

Discussion
----------

[FrameworkBundle] Fix BrowserKit assertions to make them compatible with Panther

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | todo (remove the line telling that these assertions aren't compatible with Panther)

Backport of essential fixes provided by #32207. It allows most assertions to work with Panther even when using Symfony 4.3.

Commits
-------

2316dc3 [FrameworkBundle] Fix BrowserKit assertions to make them compatible with Panther
  • Loading branch information
fabpot committed Aug 21, 2019
2 parents 58439e3 + 2316dc3 commit 46b944f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Expand Up @@ -13,7 +13,7 @@

use PHPUnit\Framework\Constraint\LogicalAnd;
use PHPUnit\Framework\Constraint\LogicalNot;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Test\Constraint as BrowserKitConstraint;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Test\Constraint as DomCrawlerConstraint;
Expand Down Expand Up @@ -186,15 +186,15 @@ public static function assertRouteSame($expectedRoute, array $parameters = [], s
self::assertThat(self::getRequest(), $constraint, $message);
}

private static function getClient(KernelBrowser $newClient = null): ?KernelBrowser
private static function getClient(AbstractBrowser $newClient = null): ?AbstractBrowser
{
static $client;

if (0 < \func_num_args()) {
return $client = $newClient;
}

if (!$client instanceof KernelBrowser) {
if (!$client instanceof AbstractBrowser) {
static::fail(sprintf('A client must be set to make assertions on it. Did you forget to call "%s::createClient()"?', __CLASS__));
}

Expand Down
Expand Up @@ -47,7 +47,7 @@ protected function matches($crawler): bool
return false;
}

return $this->expectedText === trim($crawler->getNode(0)->getAttribute($this->attribute));
return $this->expectedText === trim($crawler->attr($this->attribute));
}

/**
Expand Down

0 comments on commit 46b944f

Please sign in to comment.