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

GenerateTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 24
dl 0
loc 70
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGenerateNotFound() 0 7 1
A setUp() 0 9 1
A testGenerate() 0 9 1
A tearDown() 0 12 3
A testGenerateError() 0 7 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 GenerateTest extends ConsoleTest
16
{
17
    private $proto;
18
19
    public const SERVICE = '<?php
20
    namespace Spiral\App\Service;
21
    use Spiral\GRPC;
22
    
23
    class EchoService implements EchoInterface 
24
    {
25
        public function Ping(GRPC\ContextInterface $ctx, Message $in): Message
26
        {
27
            return $in;
28
        }
29
    }
30
    ';
31
32
    public function setUp()
33
    {
34
        parent::setUp();
35
36
        $fs = new Files();
37
        $this->proto = $fs->normalizePath($this->app->dir('app') . 'proto/service.proto');
38
39
        // protoc can't figure relative paths
40
        $this->proto = str_replace('Framework/../', '', $this->proto);
41
    }
42
43
    public function tearDown()
44
    {
45
        parent::tearDown();
46
47
        $fs = new Files();
48
49
        if ($fs->isDirectory($this->app->dir('app') . 'src/Service')) {
50
            $fs->deleteDirectory($this->app->dir('app') . 'src/Service');
51
        }
52
53
        if ($fs->isDirectory($this->app->dir('app') . 'src/GPBMetadata')) {
54
            $fs->deleteDirectory($this->app->dir('app') . 'src/GPBMetadata');
55
        }
56
    }
57
58
    public function testGenerateNotFound()
59
    {
60
        $out = $this->runCommandDebug('grpc:generate', [
61
            'proto' => 'notfound'
62
        ]);
63
64
        $this->assertContains('not found', $out);
65
    }
66
67
    public function testGenerateError()
68
    {
69
        $out = $this->runCommandDebug('grpc:generate', [
70
            'proto' => __FILE__
71
        ]);
72
73
        $this->assertContains('Error', $out);
74
    }
75
76
    public function testGenerate()
77
    {
78
        $this->runCommandDebug('grpc:generate', [
79
            'proto' => $this->proto
80
        ]);
81
82
        $this->assertFileExists($this->app->dir('app') . 'src/Service/EchoInterface.php');
83
        $this->assertFileExists($this->app->dir('app') . 'src/Service/Message.php');
84
        $this->assertFileExists($this->app->dir('app') . 'src/GPBMetadata/Service.php');
85
    }
86
}