Skip to content

Commit a080467

Browse files
committed
feat: #16 wiki upload zip
1 parent a77f594 commit a080467

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

app/Commands/WikiUploadCommand.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use App\Coding;
6+
use LaravelZero\Framework\Commands\Command;
7+
8+
class WikiUploadCommand extends Command
9+
{
10+
use WithCoding;
11+
12+
/**
13+
* The signature of the command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'wiki:upload
18+
{file : Zip 文件需包含 1 个 Markdown 文件及全部引用图片,Markdown 文件名将作为文档标题,图片使用相对路径}
19+
{--coding_token= : CODING 令牌}
20+
{--coding_team_domain= : CODING 团队域名,如 xxx.coding.net 即填写 xxx}
21+
{--coding_project_uri= : CODING 项目标识,如 xxx.coding.net/p/yyy 即填写 yyy}
22+
';
23+
24+
/**
25+
* The description of the command.
26+
*
27+
* @var string
28+
*/
29+
protected $description = '上传 Zip 导入 Wiki';
30+
31+
/**
32+
* Execute the console command.
33+
*
34+
*/
35+
public function handle(Coding $coding): int
36+
{
37+
$this->coding = $coding;
38+
$this->setCodingApi();
39+
40+
$filePath = $this->argument('file');
41+
if (!file_exists($filePath)) {
42+
$this->error("文件不存在:$filePath");
43+
return 1;
44+
}
45+
$result = $this->coding->createWikiByUploadZip($this->codingToken, $this->codingProjectUri, $filePath);
46+
$this->info('上传成功,正在处理,任务 ID:' . $result['JobId']);
47+
48+
return 0;
49+
}
50+
}

tests/Feature/WikiImportCommandTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use LaravelFans\Confluence\Facades\Confluence;
88
use Mockery\MockInterface;
99
use Tests\TestCase;
10-
use Tests\Unit\CodingTest;
1110

1211
class WikiImportCommandTest extends TestCase
1312
{
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use App\Coding;
6+
use Tests\TestCase;
7+
8+
class WikiUploadCommandTest extends TestCase
9+
{
10+
protected function setUp(): void
11+
{
12+
parent::setUp();
13+
$codingToken = $this->faker->md5;
14+
config(['coding.token' => $codingToken]);
15+
$codingTeamDomain = $this->faker->domainWord;
16+
config(['coding.team_domain' => $codingTeamDomain]);
17+
$codingProjectUri = $this->faker->slug;
18+
config(['coding.project_uri' => $codingProjectUri]);
19+
}
20+
21+
public function testHandleFileNotExist()
22+
{
23+
$filePath = sys_get_temp_dir() . '/nothing-' . $this->faker->uuid;
24+
$this->artisan('wiki:upload', ['file' => $filePath])
25+
->expectsOutput("文件不存在:${filePath}")
26+
->assertExitCode(1);
27+
}
28+
29+
public function testHandleConfluenceHtmlSuccess()
30+
{
31+
$mock = \Mockery::mock(Coding::class, [])->makePartial();
32+
$this->instance(Coding::class, $mock);
33+
34+
$mock->shouldReceive('createWikiByUploadZip')->times(1)->andReturn(json_decode(
35+
file_get_contents($this->dataDir . 'coding/' . 'CreateWikiByZipResponse.json'),
36+
true
37+
)['Response']);
38+
39+
$filePath = $this->faker->filePath();
40+
$this->artisan('wiki:upload', ['file' => $filePath])
41+
->expectsOutput('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615')
42+
->assertExitCode(0);
43+
}
44+
}

0 commit comments

Comments
 (0)