-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathFixtures.php
More file actions
51 lines (41 loc) · 1022 Bytes
/
Fixtures.php
File metadata and controls
51 lines (41 loc) · 1022 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
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Codeception\Util;
use RuntimeException;
/**
* Really basic class to store data in global array and use it in Cests/Tests.
*
* ```php
* <?php
* Fixtures::add('user1', ['name' => 'davert']);
* Fixtures::get('user1');
* Fixtures::exists('user1');
* ```
*/
class Fixtures
{
protected static array $fixtures = [];
public static function add(string $name, $data): void
{
self::$fixtures[$name] = $data;
}
public static function get(string $name)
{
if (!self::exists($name)) {
throw new RuntimeException("{$name} not found in fixtures");
}
return self::$fixtures[$name];
}
public static function cleanup(string $name = ''): void
{
if (self::exists($name)) {
unset(self::$fixtures[$name]);
return;
}
self::$fixtures = [];
}
public static function exists(string $name): bool
{
return isset(self::$fixtures[$name]);
}
}