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\Framework\GRPC; |
13
|
|
|
|
14
|
|
|
use Spiral\Files\Files; |
15
|
|
|
use Spiral\Tests\Framework\ConsoleTest; |
16
|
|
|
|
17
|
|
|
class GenerateTest extends ConsoleTest |
18
|
|
|
{ |
19
|
|
|
public const SERVICE = '<?php |
20
|
|
|
namespace Spiral\App\Service; |
21
|
|
|
|
22
|
|
|
use Spiral\GRPC; |
23
|
|
|
use Spiral\App\Service\Sub\Message; |
24
|
|
|
|
25
|
|
|
class EchoService implements EchoInterface |
26
|
|
|
{ |
27
|
|
|
public function Ping(GRPC\ContextInterface $ctx, Message $in): Message |
28
|
|
|
{ |
29
|
|
|
return $in; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
'; |
33
|
|
|
private $proto; |
34
|
|
|
|
35
|
|
|
public function setUp(): void |
36
|
|
|
{ |
37
|
|
|
exec('protoc 2>&1', $out); |
38
|
|
|
|
39
|
|
|
if (strpos(implode("\n", $out), '--php_out') === false) { |
40
|
|
|
$this->markTestSkipped('Protoc binary is missing'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
parent::setUp(); |
44
|
|
|
|
45
|
|
|
$fs = new Files(); |
46
|
|
|
$this->proto = \realpath($fs->normalizePath($this->app->dir('app') . 'proto/service.proto')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function tearDown(): void |
50
|
|
|
{ |
51
|
|
|
parent::tearDown(); |
52
|
|
|
|
53
|
|
|
$fs = new Files(); |
54
|
|
|
|
55
|
|
|
if ($fs->isDirectory($this->app->dir('app') . 'src/Service')) { |
56
|
|
|
$fs->deleteDirectory($this->app->dir('app') . 'src/Service'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ($fs->isDirectory($this->app->dir('app') . 'src/GPBMetadata')) { |
60
|
|
|
$fs->deleteDirectory($this->app->dir('app') . 'src/GPBMetadata'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testGenerateNotFound(): void |
65
|
|
|
{ |
66
|
|
|
$out = $this->runCommandDebug('grpc:generate', [ |
67
|
|
|
'proto' => 'notfound' |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
$this->assertStringContainsString('not found', $out); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testGenerateError(): void |
74
|
|
|
{ |
75
|
|
|
$out = $this->runCommandDebug('grpc:generate', [ |
76
|
|
|
'proto' => __FILE__ |
77
|
|
|
]); |
78
|
|
|
|
79
|
|
|
$this->assertStringContainsString('Error', $out); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testGenerate(): void |
83
|
|
|
{ |
84
|
|
|
$this->runCommandDebug('grpc:generate', [ |
85
|
|
|
'proto' => $this->proto |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
$this->assertFileExists($this->app->dir('app') . 'src/Service/EchoInterface.php'); |
89
|
|
|
$this->assertFileExists($this->app->dir('app') . 'src/Service/Sub/Message.php'); |
90
|
|
|
$this->assertFileExists($this->app->dir('app') . 'src/GPBMetadata/Service.php'); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|