Passed
Push — main ( aa44b1...eed324 )
by Chema
18:47 queued 12:28
created

NsCommandTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 36
c 2
b 0
f 1
dl 0
loc 74
rs 10
wmc 3

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 3 1
A hp$0 ➔ test_output_loaded_namespaces() 0 28 1
test_output_loaded_namespaces() 0 28 ?
test_output_namespace_dependencies() 0 36 ?
A hp$0 ➔ getFacade() 0 3 1
A hp$1 ➔ getFacade() 0 3 1
A hp$1 ➔ __construct() 0 3 1
A hp$1 ➔ test_output_namespace_dependencies() 0 36 1
A hp$0 ➔ __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhelTest\Integration\Run\Command\Ns;
6
7
use Phel\Build\Domain\Extractor\NamespaceInformation;
0 ignored issues
show
Bug introduced by
The type Phel\Build\Domain\Extractor\NamespaceInformation 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...
8
use Phel\Phel;
9
use Phel\Run\Infrastructure\Command\NsCommand;
10
use Phel\Run\RunFacadeInterface;
11
use PhelTest\Integration\Run\Command\AbstractTestCommand;
12
use Symfony\Component\Console\Input\InputInterface;
13
14
final class NsCommandTest extends AbstractTestCommand
15
{
16
    public static function setUpBeforeClass(): void
17
    {
18
        Phel::bootstrap(__DIR__);
19
    }
20
21
    public function test_output_loaded_namespaces(): void
22
    {
23
        $facade = self::createStub(RunFacadeInterface::class);
24
        $facade->method('getLoadedNamespaces')
25
            ->willReturn([
26
                new NamespaceInformation(__FILE__, 'app\\foo', []),
27
                new NamespaceInformation(__FILE__, 'app\\bar', []),
28
            ]);
29
30
        $command = new class($facade) extends NsCommand {
31
            public function __construct(
32
                private readonly RunFacadeInterface $facade,
33
            ) {
34
                parent::__construct();
35
            }
36
37
            protected function getFacade(): RunFacadeInterface
38
            {
39
                return $this->facade;
40
            }
41
        };
42
43
        $this->expectOutputRegex('/app\\\\foo/');
44
        $this->expectOutputRegex('/app\\\\bar/');
45
46
        $command->run(
47
            self::createStub(InputInterface::class),
48
            $this->stubOutput(),
49
        );
50
    }
51
52
    public function test_output_namespace_dependencies(): void
53
    {
54
        $facade = self::createStub(RunFacadeInterface::class);
55
        $facade->method('getAllPhelDirectories')
56
            ->willReturn(['src']);
57
        $facade->method('getDependenciesForNamespace')
58
            ->willReturn([
59
                new NamespaceInformation('foo.phel', 'app\\foo', []),
60
                new NamespaceInformation('bar.phel', 'app\\bar', ['app\\foo']),
61
            ]);
62
63
        $command = new class($facade) extends NsCommand {
64
            public function __construct(private readonly RunFacadeInterface $facade)
65
            {
66
                parent::__construct();
67
            }
68
69
            protected function getFacade(): RunFacadeInterface
70
            {
71
                return $this->facade;
72
            }
73
        };
74
75
        $input = self::createStub(InputInterface::class);
76
        $input->method('getArgument')->willReturn('app\\bar');
77
78
        $this->expectOutputRegex('/Dependencies for namespace: app\\\\bar/');
79
        $this->expectOutputRegex('/1\) Namespace: app\\\\foo/');
80
        $this->expectOutputRegex('/Used by: app\\\\bar/');
81
        $this->expectOutputRegex('/Dependencies: app\\\\foo \(foo\.phel\)/');
82
        $this->expectOutputRegex('/2\) Namespace: app\\\\bar/');
83
        $this->expectOutputRegex('/File: bar\.phel/');
84
85
        $command->run(
86
            $input,
87
            $this->stubOutput(),
88
        );
89
    }
90
}
91