diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c3d91f51..87394009 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1400,11 +1400,6 @@ parameters: count: 1 path: src/lib/Browser/Element/Action/ChainAction.php - - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\BaseElement\\:\\:findAll\\(\\) return type has no value type specified in iterable type Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollectionInterface\\.$#" - count: 1 - path: src/lib/Browser/Element/BaseElement.php - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\BaseElement\\:\\:internalFindAll\\(\\) return type has no value type specified in iterable type Traversable\\.$#" count: 1 @@ -1415,11 +1410,6 @@ parameters: count: 1 path: src/lib/Browser/Element/BaseElement.php - - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\BaseElementInterface\\:\\:findAll\\(\\) return type has no value type specified in iterable type Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollectionInterface\\.$#" - count: 1 - path: src/lib/Browser/Element/BaseElementInterface.php - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\BaseElementInterface\\:\\:waitUntil\\(\\) has no return type specified\\.$#" count: 1 @@ -1455,11 +1445,6 @@ parameters: count: 1 path: src/lib/Browser/Element/Criterion/LogicalOrCriterion.php - - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\Debug\\\\Highlighting\\\\BaseElement\\:\\:findAll\\(\\) return type has no value type specified in iterable type Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollectionInterface\\.$#" - count: 1 - path: src/lib/Browser/Element/Debug/Highlighting/BaseElement.php - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\Debug\\\\Highlighting\\\\BaseElement\\:\\:waitUntil\\(\\) has no return type specified\\.$#" count: 1 @@ -1585,11 +1570,6 @@ parameters: count: 1 path: src/lib/Browser/Element/Debug/Interactive/BaseElement.php - - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\Debug\\\\Interactive\\\\BaseElement\\:\\:findAll\\(\\) return type has no value type specified in iterable type Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollectionInterface\\.$#" - count: 1 - path: src/lib/Browser/Element/Debug/Interactive/BaseElement.php - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\Debug\\\\Interactive\\\\BaseElement\\:\\:setInteractiveBreakpoint\\(\\) has parameter \\$variables with no value type specified in iterable type array\\.$#" count: 1 @@ -1990,11 +1970,6 @@ parameters: count: 1 path: src/lib/Browser/Element/Element.php - - - message: "#^Call to function is_array\\(\\) with iterable\\&Traversable will always evaluate to false\\.$#" - count: 8 - path: src/lib/Browser/Element/ElementCollection.php - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollection\\:\\:__construct\\(\\) has parameter \\$elements with no value type specified in iterable type iterable\\.$#" count: 1 @@ -2045,26 +2020,6 @@ parameters: count: 1 path: src/lib/Browser/Element/ElementCollection.php - - - message: "#^PHPDoc tag @return with type array\\ is incompatible with native type Traversable\\.$#" - count: 1 - path: src/lib/Browser/Element/ElementCollection.php - - - - message: "#^Property Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollection\\:\\:\\$elements \\(iterable\\&Traversable\\) does not accept array\\.$#" - count: 1 - path: src/lib/Browser/Element/ElementCollection.php - - - - message: "#^Property Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollection\\:\\:\\$elements \\(iterable\\&Traversable\\) does not accept array\\\\.$#" - count: 7 - path: src/lib/Browser/Element/ElementCollection.php - - - - message: "#^Property Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollection\\:\\:\\$elements \\(iterable\\&Traversable\\) does not accept iterable\\.$#" - count: 1 - path: src/lib/Browser/Element/ElementCollection.php - - message: "#^Interface Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollectionInterface extends generic interface IteratorAggregate but does not specify its types\\: TKey, TValue$#" count: 1 @@ -2080,11 +2035,6 @@ parameters: count: 1 path: src/lib/Browser/Element/ElementCollectionInterface.php - - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollectionInterface\\:\\:getIterator\\(\\) return type has no value type specified in iterable type Traversable\\.$#" - count: 1 - path: src/lib/Browser/Element/ElementCollectionInterface.php - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollectionInterface\\:\\:map\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -2105,11 +2055,6 @@ parameters: count: 1 path: src/lib/Browser/Element/ElementCollectionInterface.php - - - message: "#^PHPDoc tag @return with type array\\ is incompatible with native type Traversable\\.$#" - count: 1 - path: src/lib/Browser/Element/ElementCollectionInterface.php - - message: "#^Method Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementInterface\\:\\:attachFile\\(\\) has parameter \\$filePath with no type specified\\.$#" count: 1 @@ -2691,7 +2636,7 @@ parameters: path: src/lib/Core/Debug/Shell/Shell.php - - message: "#^Parameter \\#2 \\$callback of function array_filter expects callable\\(int\\|string\\)\\: mixed, Closure\\(string\\)\\: bool given\\.$#" + message: "#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(int\\|string\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: bool given\\.$#" count: 1 path: src/lib/Core/Debug/Shell/Shell.php diff --git a/src/lib/Browser/Component/Component.php b/src/lib/Browser/Component/Component.php index 9b51f95c..ad6ed518 100644 --- a/src/lib/Browser/Component/Component.php +++ b/src/lib/Browser/Component/Component.php @@ -10,6 +10,8 @@ use Behat\Mink\Session; use Facebook\WebDriver\Chrome\ChromeDevToolsDriver; +use Ibexa\Behat\Browser\Element\ElementCollectionInterface; +use Ibexa\Behat\Browser\Element\ElementInterface; use Ibexa\Behat\Browser\Element\Factory\Debug\Highlighting\ElementFactory as HighlightingDebugElementFactory; use Ibexa\Behat\Browser\Element\Factory\Debug\Interactive\ElementFactory as InteractiveDebugElementFactory; use Ibexa\Behat\Browser\Element\Factory\ElementFactory; @@ -46,6 +48,17 @@ final protected function getHTMLPage(): RootElementInterface return $this->elementFactory->createRootElement($this->getSession(), $this->elementFactory); } + public function find(LocatorInterface $locator): ElementInterface + { + return $this->getHTMLPage()->find($locator); + } + + /** @return ElementCollectionInterface */ + public function findAll(LocatorInterface $locator): ElementCollectionInterface + { + return $this->getHTMLPage()->findAll($locator); + } + public function setElementFactory(ElementFactoryInterface $elementFactory): void { $this->elementFactory = $elementFactory; diff --git a/src/lib/Browser/Element/BaseElementInterface.php b/src/lib/Browser/Element/BaseElementInterface.php index a8783a24..5ea9b1c2 100644 --- a/src/lib/Browser/Element/BaseElementInterface.php +++ b/src/lib/Browser/Element/BaseElementInterface.php @@ -19,6 +19,7 @@ public function getTimeout(): int; public function find(LocatorInterface $locator): ElementInterface; + /** @return ElementCollectionInterface */ public function findAll(LocatorInterface $locator): ElementCollectionInterface; public function waitUntilCondition(ConditionInterface $condition): BaseElementInterface; diff --git a/src/lib/Browser/Element/ElementCollection.php b/src/lib/Browser/Element/ElementCollection.php index 42c0e097..7157663c 100644 --- a/src/lib/Browser/Element/ElementCollection.php +++ b/src/lib/Browser/Element/ElementCollection.php @@ -19,7 +19,7 @@ class ElementCollection implements ElementCollectionInterface { - /** @var ElementInterface[]|\Traversable */ + /** @var iterable */ private $elements; /** @@ -38,16 +38,13 @@ public function setElements(array $elements): void $this->elements = $elements; } - /** - * @return \Ibexa\Behat\Browser\Element\ElementInterface[] - */ public function getIterator(): Traversable { if (is_array($this->elements)) { return new \ArrayIterator($this->elements); } - return $this->elements; + yield from $this->elements; } public function getByCriterion(CriterionInterface $criterion): ElementInterface diff --git a/src/lib/Browser/Element/ElementCollectionInterface.php b/src/lib/Browser/Element/ElementCollectionInterface.php index 238d0a98..7ecf56c7 100644 --- a/src/lib/Browser/Element/ElementCollectionInterface.php +++ b/src/lib/Browser/Element/ElementCollectionInterface.php @@ -16,10 +16,13 @@ interface ElementCollectionInterface extends \Countable, \IteratorAggregate { /** - * @return \Ibexa\Behat\Browser\Element\ElementInterface[] + * @return ElementCollectionInterface */ public function getIterator(): Traversable; + /** + * @parameter array $elements; + */ public function setElements(array $elements): void; public function getByCriterion(CriterionInterface $criterion): ElementInterface; diff --git a/src/lib/Browser/Page/LoginPage.php b/src/lib/Browser/Page/LoginPage.php index 6ba1713f..66f974bf 100644 --- a/src/lib/Browser/Page/LoginPage.php +++ b/src/lib/Browser/Page/LoginPage.php @@ -24,9 +24,9 @@ public function logout(): void public function loginSuccessfully($username, $password): void { - $this->getHTMLPage()->find($this->getLocator('username'))->setValue($username); - $this->getHTMLPage()->find($this->getLocator('password'))->setValue($password); - $this->getHTMLPage()->findAll($this->getLocator('button')) + $this->find($this->getLocator('username'))->setValue($username); + $this->find($this->getLocator('password'))->setValue($password); + $this->findAll($this->getLocator('button')) ->filterBy(new LogicalOrCriterion([ new ElementTextCriterion('Login'), new ElementTextCriterion('Log in'), diff --git a/src/lib/Browser/Page/Preview/FolderPreview.php b/src/lib/Browser/Page/Preview/FolderPreview.php index 4e64e7ec..4160686f 100644 --- a/src/lib/Browser/Page/Preview/FolderPreview.php +++ b/src/lib/Browser/Page/Preview/FolderPreview.php @@ -23,7 +23,7 @@ public function setExpectedPreviewData(array $data) public function verifyPreviewData() { - $this->getHTMLPage()->find($this->getLocator('title'))->assert()->textEquals($this->expectedPageTitle); + $this->find($this->getLocator('title'))->assert()->textEquals($this->expectedPageTitle); } public function supports(string $contentTypeIdentifier, string $viewType): bool