Passed
Branch master (b47b37)
by Anton
01:59
created

ListTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 20
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 12 3
A testListService() 0 12 1
A setUp() 0 9 1
A testListEmpty() 0 5 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
declare(strict_types=1);
9
10
namespace Spiral\Framework\GRPC;
11
12
use Spiral\Files\Files;
13
use Spiral\Framework\ConsoleTest;
14
15
class ListTest extends ConsoleTest
16
{
17
    private $proto;
18
19
    public function setUp()
20
    {
21
        parent::setUp();
22
23
        $fs = new Files();
24
        $this->proto = $fs->normalizePath($this->app->dir('app') . 'proto/service.proto');
25
26
        // protoc can't figure relative paths
27
        $this->proto = str_replace('Framework/../', '', $this->proto);
28
    }
29
30
    public function tearDown()
31
    {
32
        parent::tearDown();
33
34
        $fs = new Files();
35
36
        if ($fs->isDirectory($this->app->dir('app') . 'src/Service')) {
37
            $fs->deleteDirectory($this->app->dir('app') . 'src/Service');
38
        }
39
40
        if ($fs->isDirectory($this->app->dir('app') . 'src/GPBMetadata')) {
41
            $fs->deleteDirectory($this->app->dir('app') . 'src/GPBMetadata');
42
        }
43
    }
44
45
    public function testListEmpty()
46
    {
47
        $out = $this->runCommandDebug('grpc:services');
48
49
        $this->assertContains('No GRPC services', $out);
50
    }
51
52
    public function testListService()
53
    {
54
        $this->runCommandDebug('grpc:generate', [
55
            'proto' => $this->proto
56
        ]);
57
58
        file_put_contents($this->app->dir('app') . 'src/Service/EchoService.php', GenerateTest::SERVICE);
59
60
        $out = $this->runCommandDebug('grpc:services');
61
62
        $this->assertContains('service.Echo', $out);
63
        $this->assertContains('Spiral\App\Service\EchoService', $out);
64
    }
65
}