3
3
namespace Tests \Feature ;
4
4
5
5
use App \Coding \Issue ;
6
+ use App \Coding \Iteration ;
6
7
use App \Coding \Project ;
7
8
use Tests \TestCase ;
8
9
9
10
class IssueImportCommandTest extends TestCase
10
11
{
12
+ private string $ codingToken ;
11
13
private string $ codingTeamDomain ;
12
14
private string $ codingProjectUri ;
13
15
14
16
protected function setUp (): void
15
17
{
16
18
parent ::setUp ();
17
- $ codingToken = $ this ->faker ->md5 ;
18
- config (['coding.token ' => $ codingToken ]);
19
+ $ this -> codingToken = $ this ->faker ->md5 ;
20
+ config (['coding.token ' => $ this -> codingToken ]);
19
21
$ this ->codingTeamDomain = $ this ->faker ->domainWord ;
20
22
config (['coding.team_domain ' => $ this ->codingTeamDomain ]);
21
23
$ this ->codingProjectUri = $ this ->faker ->slug ;
@@ -34,6 +36,8 @@ public function testImportSuccess()
34
36
35
37
$ issueMock = \Mockery::mock (Issue::class, [])->makePartial ();
36
38
$ this ->instance (Issue::class, $ issueMock );
39
+ $ iterationMock = \Mockery::mock (Iteration::class, [])->makePartial ();
40
+ $ this ->instance (Iteration::class, $ iterationMock );
37
41
38
42
$ response = json_decode (
39
43
file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateIssueResponse.json ' ),
@@ -44,6 +48,11 @@ public function testImportSuccess()
44
48
$ response ['Code ' ] = $ i ;
45
49
$ results [] = $ response ;
46
50
}
51
+ $ iterationMock ->shouldReceive ('create ' )->times (2 )->andReturn (json_decode (
52
+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateIterationResponse.json ' ),
53
+ true
54
+ )['Response ' ]['Iteration ' ]);
55
+
47
56
$ issueMock ->shouldReceive ('create ' )->times (21 )->andReturn (...$ results );
48
57
49
58
$ this ->artisan ('issue:import ' , ['file ' => $ this ->dataDir . 'coding/scrum-issues.csv ' ])
@@ -54,4 +63,48 @@ public function testImportSuccess()
54
63
->expectsOutput ("https:// $ this ->codingTeamDomain .coding.net/p/ $ this ->codingProjectUri /all/issues/21 " )
55
64
->assertExitCode (0 );
56
65
}
66
+
67
+ public function testImportUserStorySuccess ()
68
+ {
69
+ $ mock = \Mockery::mock (Project::class, [])->makePartial ();
70
+ $ this ->instance (Project::class, $ mock );
71
+
72
+ $ mock ->shouldReceive ('getIssueTypes ' )->times (1 )->andReturn (json_decode (
73
+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'DescribeProjectIssueTypeListResponse.json ' ),
74
+ true
75
+ )['Response ' ]['IssueTypes ' ]);
76
+
77
+ $ issueMock = \Mockery::mock (Issue::class, [])->makePartial ();
78
+ $ this ->instance (Issue::class, $ issueMock );
79
+ $ iterationMock = \Mockery::mock (Iteration::class, [])->makePartial ();
80
+ $ this ->instance (Iteration::class, $ iterationMock );
81
+
82
+ $ response = json_decode (
83
+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateIssueResponse.json ' ),
84
+ true
85
+ )['Response ' ]['Issue ' ];
86
+ $ response ['Code ' ] = $ this ->faker ->randomNumber ();
87
+ $ result = $ response ;
88
+ $ iterationMock ->shouldReceive ('create ' )->times (1 )->andReturn (json_decode (
89
+ file_get_contents ($ this ->dataDir . 'coding/ ' . 'CreateIterationResponse.json ' ),
90
+ true
91
+ )['Response ' ]['Iteration ' ]);
92
+
93
+ $ issueMock ->shouldReceive ('create ' )->times (1 )->withArgs ([
94
+ $ this ->codingToken ,
95
+ $ this ->codingProjectUri ,
96
+ [
97
+ 'Type ' => 'REQUIREMENT ' ,
98
+ 'IssueTypeId ' => 213218 ,
99
+ 'Name ' => '用户可通过手机号注册账户 ' ,
100
+ 'Priority ' => "1 " ,
101
+ 'IterationCode ' => 2746 ,
102
+ ]
103
+ ])->andReturn ($ result );
104
+
105
+ $ this ->artisan ('issue:import ' , ['file ' => $ this ->dataDir . 'coding/scrum-issue-5.csv ' ])
106
+ ->expectsOutput ("https:// $ this ->codingTeamDomain .coding.net/p/ $ this ->codingProjectUri /all/issues/ " .
107
+ $ result ['Code ' ])
108
+ ->assertExitCode (0 );
109
+ }
57
110
}
0 commit comments