Passed
Push — master ( 3eb4db...99d5ff )
by Kirill
03:12
created

FunctionsTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 36
c 1
b 0
f 0
dl 0
loc 91
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testSpiralException2() 0 14 1
A testEnv() 0 14 1
A testEnvException() 0 5 1
A testDirectory() 0 12 1
A testDirectoryException() 0 5 1
A assertDir() 0 4 1
A testSpiralException() 0 5 1
A testSpiral() 0 12 1
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);
0 ignored issues
show
Bug introduced by
The type Spiral\Tests\Boot\Invalid was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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