Skip to content

Commit 108679c

Browse files
nrocytbp-paul
andauthored
Fix compatibility with symfony/dom-crawler < 5.3.0-BETA-1 (#50)
Co-authored-by: Paul King <paul@thebotplatform.com>
1 parent 879872d commit 108679c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Codeception/Lib/InnerBrowser.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ private function getFormFromCrawler(Crawler $form): SymfonyForm
10131013
$formId = $form->attr('id');
10141014
if ($formId !== null) {
10151015
$fakeForm = $fakeDom->firstChild;
1016-
$topParent = $form->ancestors()->last();
1016+
$topParent = $this->getAncestorsFor($form)->last();
10171017
$fieldsByFormAttribute = $topParent->filter(
10181018
sprintf('input[form=%s],select[form=%s],textarea[form=%s]', $formId, $formId, $formId)
10191019
);
@@ -1044,7 +1044,7 @@ protected function getFormFor(Crawler $node): SymfonyForm
10441044
if (strcasecmp($node->first()->getNode(0)->tagName, 'form') === 0) {
10451045
$form = $node->first();
10461046
} else {
1047-
$form = $node->ancestors()->filter('form')->first();
1047+
$form = $this->getAncestorsFor($node)->filter('form')->first();
10481048
}
10491049

10501050
if (!$form) {
@@ -1059,6 +1059,24 @@ protected function getFormFor(Crawler $node): SymfonyForm
10591059
return $this->forms[$identifier];
10601060
}
10611061

1062+
/**
1063+
* Returns the ancestors of the passed SymfonyCrawler.
1064+
*
1065+
* symfony/dom-crawler deprecated parents() in favor of ancestors()
1066+
* This provides backward compatibility with < 5.3.0-BETA-1
1067+
*
1068+
* @param SymfonyCrawler $crawler the crawler
1069+
* @return SymfonyCrawler the ancestors
1070+
*/
1071+
private function getAncestorsFor(SymfonyCrawler $crawler): SymfonyCrawler
1072+
{
1073+
if (method_exists($crawler, 'ancestors')) {
1074+
return $crawler->ancestors();
1075+
}
1076+
1077+
return $crawler->parents();
1078+
}
1079+
10621080
/**
10631081
* Returns an array of name => value pairs for the passed form.
10641082
*

0 commit comments

Comments
 (0)