質問編集履歴

1

自己解決

2018/10/18 08:30

投稿

tenpu
tenpu

スコア40

test CHANGED
@@ -1 +1 @@
1
- Mock作成時のS3Exception発生方法
1
+ MockS3Exception発生させたい
test CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
 
4
4
 
5
- S3ClientメソッドheadObjectを使用している自作関数hogeのテストコードを書くため、headObject()をMock化しています。
5
+ 自作関数hogeをテストしようとしています。hoge()内で、S3ClientメソッドheadObjectを使用しているため、headObject()をMock化しています。
6
6
 
7
7
 
8
8
 
9
+ そのテストケースとして、hoge関数内で、
10
+
9
- hoge関数内で、Aws\S3\Exception\S3Exception発生時テストをする、Mockで設定したいのですが、うまくいかずUT実行時にエラーになってしまいます。
11
+ Aws\S3\Exception\S3Exception発生時テストいので、Mockで設定したいのですが、うまくいかずUT実行時にエラーになってしまいます。
10
12
 
11
13
 
12
14
 
@@ -24,7 +26,7 @@
24
26
 
25
27
  ->with(m::any())
26
28
 
27
- ->andThrow(new S3Exception()); // S3Exceptionを発生させたい
29
+ ->andThrow(new S3Exception('', new Command('')));
28
30
 
29
31
 
30
32
 
@@ -48,10 +50,10 @@
48
50
 
49
51
 
50
52
 
51
- ```
52
53
 
53
- [UT実行時エラー]
54
54
 
55
- Fuel\Core\PhpErrorException: Argument 2 passed to Aws\Exception\AwsException::__construct() must implement interface Aws\CommandInterface, none given, called in ...
55
+ ~~[UT実行時エラー]
56
56
 
57
+ Fuel\Core\PhpErrorException: Argument 2 passed to Aws\Exception\AwsException::__construct() must implement interface Aws\CommandInterface, none given, called in ...~~
58
+
57
- ```
59
+ → parametereを追加したら、エラーは消えましたが期待値と異なったので、hoge()内を確認し、エラー制御に問題があったことが分かりました。