|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @author Anton Titov (Wolfy-J) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Spiral\Tests\Boot; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Psr\Container\ContainerInterface; |
|
16
|
|
|
use Spiral\Boot\Environment; |
|
17
|
|
|
use Spiral\Core\Exception\ScopeException; |
|
18
|
|
|
use Spiral\Tests\Boot\Fixtures\TestConfig; |
|
19
|
|
|
use Spiral\Tests\Boot\Fixtures\TestCore; |
|
20
|
|
|
use Spiral\Core\ContainerScope; |
|
21
|
|
|
|
|
22
|
|
|
class FunctionsTest extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
public function testSpiral(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$core = TestCore::init([ |
|
27
|
|
|
'root' => __DIR__, |
|
28
|
|
|
'config' => __DIR__ . '/config', |
|
29
|
|
|
]); |
|
30
|
|
|
|
|
31
|
|
|
/** @var ContainerInterface $c */ |
|
32
|
|
|
$c = $core->getContainer(); |
|
33
|
|
|
|
|
34
|
|
|
ContainerScope::runScope($c, function (): void { |
|
35
|
|
|
$this->assertSame(['key' => 'value'], spiral(TestConfig::class)->toArray()); |
|
36
|
|
|
}); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testEnv(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$core = TestCore::init([ |
|
42
|
|
|
'root' => __DIR__, |
|
43
|
|
|
'config' => __DIR__ . '/config', |
|
44
|
|
|
], new Environment([ |
|
45
|
|
|
'key' => '(true)', |
|
46
|
|
|
])); |
|
47
|
|
|
|
|
48
|
|
|
/** @var ContainerInterface $c */ |
|
49
|
|
|
$c = $core->getContainer(); |
|
50
|
|
|
|
|
51
|
|
|
ContainerScope::runScope($c, function (): void { |
|
52
|
|
|
$this->assertSame(true, env('key')); |
|
53
|
|
|
}); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testDirectory(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$core = TestCore::init([ |
|
59
|
|
|
'root' => __DIR__, |
|
60
|
|
|
'config' => __DIR__ . '/config', |
|
61
|
|
|
]); |
|
62
|
|
|
|
|
63
|
|
|
/** @var ContainerInterface $c */ |
|
64
|
|
|
$c = $core->getContainer(); |
|
65
|
|
|
|
|
66
|
|
|
ContainerScope::runScope($c, function (): void { |
|
67
|
|
|
$this->assertDir(__DIR__ . '/config', directory('config')); |
|
68
|
|
|
}); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testSpiralException(): void |
|
72
|
|
|
{ |
|
73
|
|
|
$this->expectException(ScopeException::class); |
|
74
|
|
|
|
|
75
|
|
|
spiral(TestConfig::class); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testSpiralException2(): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->expectException(ScopeException::class); |
|
81
|
|
|
|
|
82
|
|
|
$core = TestCore::init([ |
|
83
|
|
|
'root' => __DIR__, |
|
84
|
|
|
'config' => __DIR__ . '/config', |
|
85
|
|
|
]); |
|
86
|
|
|
|
|
87
|
|
|
/** @var ContainerInterface $c */ |
|
88
|
|
|
$c = $core->getContainer(); |
|
89
|
|
|
|
|
90
|
|
|
ContainerScope::runScope($c, function (): void { |
|
91
|
|
|
spiral(Invalid::class); |
|
|
|
|
|
|
92
|
|
|
}); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testEnvException(): void |
|
96
|
|
|
{ |
|
97
|
|
|
$this->expectException(ScopeException::class); |
|
98
|
|
|
|
|
99
|
|
|
env('key'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testDirectoryException(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->expectException(ScopeException::class); |
|
105
|
|
|
|
|
106
|
|
|
directory('key'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
private function assertDir($path, $value): void |
|
110
|
|
|
{ |
|
111
|
|
|
$path = str_replace(['\\', '//'], '/', $path); |
|
112
|
|
|
$this->assertSame(rtrim($path, '/') . '/', $value); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths