-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathAbstractLazyTestCase.php
More file actions
82 lines (67 loc) · 2.37 KB
/
AbstractLazyTestCase.php
File metadata and controls
82 lines (67 loc) · 2.37 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
<?php
declare(strict_types=1);
namespace Rector\Testing\PHPUnit;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\Version;
use Rector\Config\RectorConfig;
use Rector\DependencyInjection\LazyContainerFactory;
abstract class AbstractLazyTestCase extends TestCase
{
protected static ?RectorConfig $rectorConfig = null;
protected function setUp(): void
{
// this is needed to have always the same preloaded nikic/php-parser classes
// in both bare AbstractLazyTestCase lazy tests and AbstractRectorTestCase tests
$this->includePreloadFilesAndScoperAutoload();
}
/**
* @api
* @param string[] $configFiles
*/
protected function bootFromConfigFiles(array $configFiles): void
{
$rectorConfig = self::getContainer();
foreach ($configFiles as $configFile) {
$rectorConfig->import($configFile);
}
}
/**
* @template TType as object
* @param class-string<TType> $class
* @return TType
*/
protected function make(string $class): object
{
return self::getContainer()->make($class);
}
protected static function getContainer(): RectorConfig
{
if (! self::$rectorConfig instanceof RectorConfig) {
$lazyContainerFactory = new LazyContainerFactory();
self::$rectorConfig = $lazyContainerFactory->create();
}
self::$rectorConfig->boot();
return self::$rectorConfig;
}
protected function isWindows(): bool
{
return strncasecmp(PHP_OS, 'WIN', 3) === 0;
}
private function includePreloadFilesAndScoperAutoload(): void
{
if (file_exists(__DIR__ . '/../../../preload.php')) {
if (file_exists(__DIR__ . '/../../../vendor')) {
// this ensure to not load preload.php on phpunit >= 12
if (! class_exists(Version::class) || (int) Version::id() < 12) {
require_once __DIR__ . '/../../../preload.php';
}
// test case in rector split package
} elseif (file_exists(__DIR__ . '/../../../../../../vendor')) {
require_once __DIR__ . '/../../../preload-split-package.php';
}
}
if (\file_exists(__DIR__ . '/../../../vendor/scoper-autoload.php')) {
require_once __DIR__ . '/../../../vendor/scoper-autoload.php';
}
}
}