-
-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathInteractsWithDownloads.php
More file actions
43 lines (34 loc) · 931 Bytes
/
InteractsWithDownloads.php
File metadata and controls
43 lines (34 loc) · 931 Bytes
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
<?php
declare(strict_types=1);
namespace Pest\Browser\Api\Concerns;
use Pest\Browser\Api\Download;
trait InteractsWithDownloads
{
/**
* Executes a callback and captures the download it triggers.
*
* @param callable(self): void $callback
*/
public function expectDownload(callable $callback): Download
{
$download = $this->page->pendingDownload();
$callback($this);
return $download;
}
/**
* Executes a callback and captures all downloads it triggers.
*
* @param callable(self): void $callback
* @return array<int, Download>
*/
public function expectDownloads(callable $callback, ?int $count = null): array
{
$collector = $this->page->downloadCollector();
try {
$callback($this);
return $collector->all($count);
} finally {
$collector->stop();
}
}
}