forked from sebastianbergmann/phpunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistry.php
More file actions
105 lines (94 loc) · 3.12 KB
/
Copy pathRegistry.php
File metadata and controls
105 lines (94 loc) · 3.12 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TextUI\Configuration;
use function assert;
use function file_get_contents;
use function file_put_contents;
use function serialize;
use function unserialize;
use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\TextUI\CliArguments\Configuration as CliConfiguration;
use PHPUnit\TextUI\CliArguments\Exception;
use PHPUnit\TextUI\XmlConfiguration\Configuration as XmlConfiguration;
use PHPUnit\Util\VersionComparisonOperator;
/**
* CLI options and XML configuration are static within a single PHPUnit process.
* It is therefore okay to use a Singleton registry here.
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class Registry
{
private static ?Configuration $instance = null;
public static function saveTo(string $path): bool
{
$result = file_put_contents(
$path,
serialize(self::get()),
);
if ($result) {
return true;
}
return false;
}
/**
* This method is used by the "run test(s) in separate process" templates.
*
* @noinspection PhpUnused
*/
public static function loadFrom(string $path): void
{
self::$instance = unserialize(
file_get_contents($path),
[
'allowed_classes' => [
Configuration::class,
Php::class,
ConstantCollection::class,
Constant::class,
IniSettingCollection::class,
IniSetting::class,
VariableCollection::class,
Variable::class,
DirectoryCollection::class,
Directory::class,
FileCollection::class,
File::class,
FilterDirectoryCollection::class,
FilterDirectory::class,
TestDirectoryCollection::class,
TestDirectory::class,
TestFileCollection::class,
TestFile::class,
TestSuiteCollection::class,
TestSuite::class,
VersionComparisonOperator::class,
Source::class,
],
],
);
}
public static function get(): Configuration
{
assert(self::$instance instanceof Configuration);
return self::$instance;
}
/**
* @throws \PHPUnit\TextUI\XmlConfiguration\Exception
* @throws Exception
* @throws NoCustomCssFileException
*/
public static function init(CliConfiguration $cliConfiguration, XmlConfiguration $xmlConfiguration): Configuration
{
self::$instance = (new Merger)->merge($cliConfiguration, $xmlConfiguration);
EventFacade::emitter()->testRunnerConfigured(self::$instance);
return self::$instance;
}
}