Skip to content

Commit

Permalink
Added helper find and findAll methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon committed Dec 12, 2023
1 parent 8f7986b commit fc982b9
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 66 deletions.
57 changes: 1 addition & 56 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1990,11 +1970,6 @@ parameters:
count: 1
path: src/lib/Browser/Element/Element.php

-
message: "#^Call to function is_array\\(\\) with iterable\\<Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementInterface\\>&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
Expand Down Expand Up @@ -2045,26 +2020,6 @@ parameters:
count: 1
path: src/lib/Browser/Element/ElementCollection.php

-
message: "#^PHPDoc tag @return with type array\\<Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementInterface\\> is incompatible with native type Traversable\\.$#"
count: 1
path: src/lib/Browser/Element/ElementCollection.php

-
message: "#^Property Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollection\\:\\:\\$elements \\(iterable\\<Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementInterface\\>&Traversable\\) does not accept array\\.$#"
count: 1
path: src/lib/Browser/Element/ElementCollection.php

-
message: "#^Property Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollection\\:\\:\\$elements \\(iterable\\<Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementInterface\\>&Traversable\\) does not accept array\\<Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementInterface\\>\\.$#"
count: 7
path: src/lib/Browser/Element/ElementCollection.php

-
message: "#^Property Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementCollection\\:\\:\\$elements \\(iterable\\<Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementInterface\\>&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
Expand All @@ -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
Expand All @@ -2105,11 +2055,6 @@ parameters:
count: 1
path: src/lib/Browser/Element/ElementCollectionInterface.php

-
message: "#^PHPDoc tag @return with type array\\<Ibexa\\\\Behat\\\\Browser\\\\Element\\\\ElementInterface\\> 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
Expand Down Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions src/lib/Browser/Component/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ElementInterface> */
public function findAll(LocatorInterface $locator): ElementCollectionInterface
{
return $this->getHTMLPage()->findAll($locator);
}

public function setElementFactory(ElementFactoryInterface $elementFactory): void
{
$this->elementFactory = $elementFactory;
Expand Down
1 change: 1 addition & 0 deletions src/lib/Browser/Element/BaseElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function getTimeout(): int;

public function find(LocatorInterface $locator): ElementInterface;

/** @return ElementCollectionInterface<ElementInterface> */
public function findAll(LocatorInterface $locator): ElementCollectionInterface;

public function waitUntilCondition(ConditionInterface $condition): BaseElementInterface;
Expand Down
7 changes: 2 additions & 5 deletions src/lib/Browser/Element/ElementCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class ElementCollection implements ElementCollectionInterface
{
/** @var ElementInterface[]|\Traversable */
/** @var iterable<ElementInterface> */
private $elements;

/**
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/lib/Browser/Element/ElementCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
interface ElementCollectionInterface extends \Countable, \IteratorAggregate
{
/**
* @return \Ibexa\Behat\Browser\Element\ElementInterface[]
* @return ElementCollectionInterface<ElementInterface>
*/
public function getIterator(): Traversable;

/**
* @parameter array<ElementInterface> $elements;
*/
public function setElements(array $elements): void;

public function getByCriterion(CriterionInterface $criterion): ElementInterface;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Browser/Page/LoginPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Browser/Page/Preview/FolderPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc982b9

Please sign in to comment.