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
|
|
|
} |