回答編集履歴

4

link

2016/03/10 04:10

投稿

ngyuki
ngyuki

スコア4514

test CHANGED
@@ -58,6 +58,6 @@
58
58
 
59
59
 
60
60
 
61
- http://qiita.com/ngyuki/items/ca43aaa1a728f48c8cde#%E9%9D%99%E7%9A%84%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89%E3%81%AE%E3%82%B9%E3%82%BF%E3%83%96%E3%81%A8%E3%83%A2%E3%83%83%E3%82%AF%E3%81%AE%E5%BB%83%E6%AD%A2
61
+ [http://qiita.com/ngyuki/items/ca43aaa1a728f48c8cde](http://qiita.com/ngyuki/items/ca43aaa1a728f48c8cde#%E9%9D%99%E7%9A%84%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89%E3%81%AE%E3%82%B9%E3%82%BF%E3%83%96%E3%81%A8%E3%83%A2%E3%83%83%E3%82%AF%E3%81%AE%E5%BB%83%E6%AD%A2)
62
62
 
63
63
 

3

fix

2016/03/10 04:10

投稿

ngyuki
ngyuki

スコア4514

test CHANGED
@@ -51,3 +51,13 @@
51
51
  ```
52
52
 
53
53
 
54
+
55
+ 少し古い PHPUnit だと `PHPUnit_Framework_MockObject_BadMethodCallException` にはならないのですが、その場合でも `expects` ではモックにできません。
56
+
57
+ かわりに `staticExpects` を使うことが出来たのですが、最近の PHPUnit には `staticExpects` はありません。
58
+
59
+
60
+
61
+ http://qiita.com/ngyuki/items/ca43aaa1a728f48c8cde#%E9%9D%99%E7%9A%84%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89%E3%81%AE%E3%82%B9%E3%82%BF%E3%83%96%E3%81%A8%E3%83%A2%E3%83%83%E3%82%AF%E3%81%AE%E5%BB%83%E6%AD%A2
62
+
63
+

2

fix

2016/03/10 04:08

投稿

ngyuki
ngyuki

スコア4514

test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  {
16
16
 
17
- public static function func() {}
17
+ public static function func($val) {}
18
18
 
19
19
  }
20
20
 
@@ -32,7 +32,7 @@
32
32
 
33
33
  $obj->expects($this->any())->method('func')->with($this->anything())->will($this->returnValue(true));
34
34
 
35
- $obj->func();
35
+ $this->assertTrue($obj->func(123));
36
36
 
37
37
  }
38
38
 

1

add

2016/03/10 04:02

投稿

ngyuki
ngyuki

スコア4514

test CHANGED
@@ -1 +1,53 @@
1
1
  LogUtil::kpiLogger が static メソッドなのではないでしょうか?
2
+
3
+
4
+
5
+ static メソッドをモックして呼ぶと `PHPUnit_Framework_MockObject_BadMethodCallException` になります。
6
+
7
+
8
+
9
+ ```php
10
+
11
+ <?php
12
+
13
+ class Hoge
14
+
15
+ {
16
+
17
+ public static function func() {}
18
+
19
+ }
20
+
21
+
22
+
23
+ class HogeTest extends PHPUnit_Framework_TestCase
24
+
25
+ {
26
+
27
+ public function test()
28
+
29
+ {
30
+
31
+ $obj = $this->getMockBuilder(Hoge::class)->getMock();
32
+
33
+ $obj->expects($this->any())->method('func')->with($this->anything())->will($this->returnValue(true));
34
+
35
+ $obj->func();
36
+
37
+ }
38
+
39
+ }
40
+
41
+ ```
42
+
43
+
44
+
45
+ ```
46
+
47
+ 1) HogeTest::test
48
+
49
+ PHPUnit_Framework_MockObject_BadMethodCallException:
50
+
51
+ ```
52
+
53
+