-
-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathStorageState.php
More file actions
49 lines (40 loc) · 1.04 KB
/
StorageState.php
File metadata and controls
49 lines (40 loc) · 1.04 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
<?php
declare(strict_types=1);
namespace Pest\Browser\Support;
use Pest\TestSuite;
/**
* @internal
*/
final class StorageState
{
/**
* Return the path to the storage state directory.
*/
public static function dir(): string
{
return TestSuite::getInstance()->rootPath
.'/tests/Browser/StorageState';
}
/**
* Return the full path for a storage state file.
*/
public static function path(string $name): string
{
return self::dir().DIRECTORY_SEPARATOR.mb_ltrim($name, '/').'.json';
}
/**
* Save a storage state JSON string to the filesystem.
*/
public static function save(string $json, ?string $name = null): string
{
if ($name === null) {
// @phpstan-ignore-next-line
$name = str_replace('__pest_evaluable_', '', test()->name());
}
if (is_dir(self::dir()) === false) {
mkdir(self::dir(), 0755, true);
}
file_put_contents(self::path($name), $json);
return $name;
}
}