|
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 ListTest extends ConsoleTest |
|
18
|
|
|
{ |
|
19
|
|
|
private $proto; |
|
20
|
|
|
|
|
21
|
|
|
public function setUp(): void |
|
22
|
|
|
{ |
|
23
|
|
|
exec('protoc 2>&1', $out); |
|
24
|
|
|
if (strpos(join("\n", $out), '--php_out') === false) { |
|
25
|
|
|
$this->markTestSkipped('Protoc binary is missing'); |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
parent::setUp(); |
|
30
|
|
|
|
|
31
|
|
|
$fs = new Files(); |
|
32
|
|
|
$this->proto = $fs->normalizePath($this->app->dir('app') . 'proto/service.proto'); |
|
33
|
|
|
|
|
34
|
|
|
// protoc can't figure relative paths |
|
35
|
|
|
$this->proto = str_replace('Framework/../', '', $this->proto); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function tearDown(): void |
|
39
|
|
|
{ |
|
40
|
|
|
parent::tearDown(); |
|
41
|
|
|
|
|
42
|
|
|
$fs = new Files(); |
|
43
|
|
|
|
|
44
|
|
|
if ($fs->isDirectory($this->app->dir('app') . 'src/Service')) { |
|
45
|
|
|
$fs->deleteDirectory($this->app->dir('app') . 'src/Service'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($fs->isDirectory($this->app->dir('app') . 'src/GPBMetadata')) { |
|
49
|
|
|
$fs->deleteDirectory($this->app->dir('app') . 'src/GPBMetadata'); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testListEmpty(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$out = $this->runCommandDebug('grpc:services'); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertStringContainsString('No GRPC services', $out); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testListService(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->runCommandDebug('grpc:generate', [ |
|
63
|
|
|
'proto' => $this->proto |
|
64
|
|
|
]); |
|
65
|
|
|
|
|
66
|
|
|
$output = $this->app->dir('app') . 'src/Service/EchoService.php'; |
|
67
|
|
|
file_put_contents($output, GenerateTest::SERVICE); |
|
68
|
|
|
|
|
69
|
|
|
$out = $this->runCommandDebug('grpc:services'); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertStringContainsString('service.Echo', $out); |
|
72
|
|
|
$this->assertStringContainsString('Spiral\App\Service\EchoService', $out); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|