5
5
use App \Coding ;
6
6
use Confluence \Content ;
7
7
use LaravelFans \Confluence \Facades \Confluence ;
8
+ use Mockery \Mock ;
8
9
use Mockery \MockInterface ;
9
10
use Tests \TestCase ;
11
+ use Tests \Unit \CodingTest ;
10
12
11
13
class WikiImportCommandTest extends TestCase
12
14
{
13
- private array $ codingResponse ;
15
+ private array $ codingCreateWikiResponse ;
14
16
15
17
protected function setUp (): void
16
18
{
17
19
parent ::setUp ();
18
- $ this ->codingResponse = json_decode (file_get_contents ($ this ->dataDir . 'coding/createWikiResponse.json ' ), true )
19
- ['Response ' ]['Data ' ];
20
+ $ this ->codingCreateWikiResponse = json_decode (
21
+ file_get_contents ($ this ->dataDir . 'coding/createWikiResponse.json ' ),
22
+ true
23
+ )['Response ' ]['Data ' ];
20
24
}
21
25
22
26
public function testHandleIndex ()
@@ -91,7 +95,7 @@ public function testHandleShow()
91
95
});
92
96
Confluence::setResource ($ mock );
93
97
94
- $ codingResponse = $ this ->codingResponse ;
98
+ $ codingResponse = $ this ->codingCreateWikiResponse ;
95
99
$ this ->mock (Coding::class, function (MockInterface $ mock ) use (
96
100
$ codingToken ,
97
101
$ codingProjectUri ,
@@ -142,7 +146,7 @@ public function testHandleConfluenceHtmlFileNotExist()
142
146
->assertExitCode (1 );
143
147
}
144
148
145
- public function testHandleConfluenceHtml ()
149
+ public function testHandleConfluenceHtmlSuccess ()
146
150
{
147
151
$ codingToken = $ this ->faker ->md5 ;
148
152
config (['coding.token ' => $ codingToken ]);
@@ -151,29 +155,31 @@ public function testHandleConfluenceHtml()
151
155
$ codingProjectUri = $ this ->faker ->slug ;
152
156
config (['coding.project_uri ' => $ codingProjectUri ]);
153
157
154
- $ path = $ this ->dataDir . 'confluence/space1/ ' ;
158
+ $ codingPath = $ this ->dataDir . 'coding/ ' ;
159
+ // 注意:不能使用 partialMock
160
+ // https://laracasts.com/discuss/channels/testing/this-partialmock-doesnt-call-the-constructor
161
+ $ mock = \Mockery::mock (Coding::class, [])->makePartial ();
162
+ $ this ->instance (Coding::class, $ mock );
155
163
156
- $ codingResponse = $ this ->codingResponse ;
157
- $ this ->mock (Coding::class, function (MockInterface $ mock ) use (
158
- $ codingToken ,
159
- $ codingProjectUri ,
160
- $ codingResponse
161
- ) {
162
- $ mock ->shouldReceive ('createWiki ' )->times (2 )->andReturn ($ codingResponse );
163
- });
164
+ $ mock ->shouldReceive ('createUploadToken ' )->times (2 )->andReturn (CodingTest::$ uploadToken );
165
+ $ mock ->shouldReceive ('upload ' )->times (2 )->andReturn (true );
166
+ $ mock ->shouldReceive ('createWikiByZip ' )->times (2 )->andReturn (json_decode (
167
+ file_get_contents ($ codingPath . 'CreateWikiByZipResponse.json ' ),
168
+ true
169
+ )['Response ' ]);
164
170
165
171
$ this ->artisan ('wiki:import ' )
166
172
->expectsQuestion ('数据来源? ' , 'Confluence ' )
167
173
->expectsQuestion ('数据类型? ' , 'HTML ' )
168
- ->expectsQuestion ('路径: ' , $ path )
174
+ ->expectsQuestion ('路径: ' , $ this -> dataDir . ' confluence/space1/ ' )
169
175
->expectsOutput ('空间名称:空间 1 ' )
170
176
->expectsOutput ('空间标识:space1 ' )
171
177
->expectsOutput ('发现 2 个一级页面 ' )
172
178
->expectsOutput ("开始导入 CODING: " )
173
179
->expectsOutput ('标题:Image Demo ' )
174
- ->expectsOutput (" https:// $ {codingTeamDomain} .coding.net/p/ $ codingProjectUri /wiki/27 " )
180
+ ->expectsOutput (' 上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
175
181
->expectsOutput ('标题:你好世界 ' )
176
- ->expectsOutput (" https:// $ {codingTeamDomain} .coding.net/p/ $ codingProjectUri /wiki/27 " )
182
+ ->expectsOutput (' 上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615 ' )
177
183
->assertExitCode (0 );
178
184
}
179
185
}
0 commit comments