From 25afac3a48e74c93b26b8a07ae8071417fe7e3c6 Mon Sep 17 00:00:00 2001 From: Paul King Date: Wed, 26 Jan 2022 18:26:31 +0000 Subject: [PATCH] Fix compatibility with symfony/dom-crawler < 5.3.0-BETA-1 --- src/Codeception/Lib/InnerBrowser.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Lib/InnerBrowser.php b/src/Codeception/Lib/InnerBrowser.php index 593cb6e..d07f0ae 100644 --- a/src/Codeception/Lib/InnerBrowser.php +++ b/src/Codeception/Lib/InnerBrowser.php @@ -1013,7 +1013,7 @@ private function getFormFromCrawler(Crawler $form): SymfonyForm $formId = $form->attr('id'); if ($formId !== null) { $fakeForm = $fakeDom->firstChild; - $topParent = $form->ancestors()->last(); + $topParent = $this->getAncestorsFor($form)->last(); $fieldsByFormAttribute = $topParent->filter( sprintf('input[form=%s],select[form=%s],textarea[form=%s]', $formId, $formId, $formId) ); @@ -1044,7 +1044,7 @@ protected function getFormFor(Crawler $node): SymfonyForm if (strcasecmp($node->first()->getNode(0)->tagName, 'form') === 0) { $form = $node->first(); } else { - $form = $node->ancestors()->filter('form')->first(); + $form = $this->getAncestorsFor($node)->filter('form')->first(); } if (!$form) { @@ -1059,6 +1059,24 @@ protected function getFormFor(Crawler $node): SymfonyForm return $this->forms[$identifier]; } + /** + * Returns the ancestors of the passed SymfonyCrawler. + * + * symfony/dom-crawler deprecated parents() in favor of ancestors() + * This provides backward compatibility with < 5.3.0-BETA-1 + * + * @param SymfonyCrawler $crawler the crawler + * @return SymfonyCrawler the ancestors + */ + private function getAncestorsFor(SymfonyCrawler $crawler): SymfonyCrawler + { + if (method_exists($crawler, 'ancestors')) { + return $crawler->ancestors(); + } + + return $crawler->parents(); + } + /** * Returns an array of name => value pairs for the passed form. *