-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTargetable.php
More file actions
52 lines (42 loc) · 1.52 KB
/
Targetable.php
File metadata and controls
52 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Ziadoz\AssertableHtml\Concerns;
use Ziadoz\AssertableHtml\Dom\AssertableDocument;
use Ziadoz\AssertableHtml\Dom\AssertableElement;
use Ziadoz\AssertableHtml\Dom\AssertableElementsList;
trait Targetable
{
/**
* Scope the first assertable element within the current assertable document or element matching the given selector.
*
* @param callable(AssertableElement $assertable): void $callback
*/
public function one(string $selector, callable $callback): static
{
$callback($this->querySelector($selector));
return $this;
}
/**
* Scope the matching assertable elements within the current assertable document or element matching the given selector.
*
* @param callable(AssertableElementsList $assertable): void $callback
*/
public function many(string $selector, callable $callback): static
{
$callback($this->querySelectorAll($selector));
return $this;
}
/**
* Scope the first assertable element elsewhere in the assertable document matching the given selector.
*
* @param callable(AssertableElement $assertable): void $callback
*/
public function elsewhere(string $selector, callable $callback): static
{
$document = $this instanceof AssertableDocument
? $this
: AssertableDocument::createFromString($this->element->ownerDocument->saveHtml());
$callback($document->querySelector($selector));
return $this;
}
}