質問編集履歴

1

回答をいただいて試したことを追記

2022/08/29 14:53

投稿

ttpk
ttpk

スコア338

test CHANGED
File without changes
test CHANGED
@@ -60,3 +60,47 @@
60
60
  PHPUnit 9.5.21
61
61
  mockery 1.5
62
62
 
63
+
64
+ ### 回答をいただいて書いたコード
65
+ テストしたいコードからstaticを外し
66
+ self::を$thisに修正しました
67
+ ```PHP
68
+ class makeUnfollowCheckClass
69
+ {
70
+ public function makeUnfollowCheck($twitter_account_id, $target_account_id): bool
71
+ {
72
+ $latestTweetCheck = $this->latestTweetCheck($twitter, $target_account_id);
73
+ }
74
+
75
+ return $chk_flg;
76
+
77
+ }
78
+
79
+ function latestTweetCheck(TwitterOAuth $twitter, $target_account_id)
80
+ { return $chk_flg;
81
+ }
82
+ }
83
+
84
+ ```
85
+ テストコードの書き方も修正しました
86
+ ```PHP
87
+ $makeUnfollowCheckClass = Mockery::mock(makeUnfollowCheckClass::class)
88
+ ->shouldReceive('latestTweetCheck')
89
+ ->andReturn(false);
90
+
91
+ $result = $makeUnfollowCheckClass->makeUnfollowCheck($twitter_account_id, $target_account_id);
92
+
93
+ ```
94
+ > ErrorException: call_user_func_array() expects parameter 1 to be a valid callback, class 'Mockery\Expectation' does not have a method 'makeUnfollowCheck'
95
+
96
+ そんなメソッドはないといった意味のエラーが出たので引き続き調べてみます
97
+
98
+ また、makeUnfollowCheckClassは
99
+ App\Console\Commands
100
+ 配下の
101
+ unfollowExecクラスで使用する想定です
102
+ ```PHP
103
+ $unfollow_check = app(makeUnfollowCheckClass::class)->makeUnfollowCheck($twitter, $targetId);
104
+
105
+ ```
106
+