回答編集履歴
4
link
answer
CHANGED
@@ -28,4 +28,4 @@
|
|
28
28
|
少し古い PHPUnit だと `PHPUnit_Framework_MockObject_BadMethodCallException` にはならないのですが、その場合でも `expects` ではモックにできません。
|
29
29
|
かわりに `staticExpects` を使うことが出来たのですが、最近の PHPUnit には `staticExpects` はありません。
|
30
30
|
|
31
|
-
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
|
31
|
+
[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)
|
3
fix
answer
CHANGED
@@ -24,3 +24,8 @@
|
|
24
24
|
1) HogeTest::test
|
25
25
|
PHPUnit_Framework_MockObject_BadMethodCallException:
|
26
26
|
```
|
27
|
+
|
28
|
+
少し古い PHPUnit だと `PHPUnit_Framework_MockObject_BadMethodCallException` にはならないのですが、その場合でも `expects` ではモックにできません。
|
29
|
+
かわりに `staticExpects` を使うことが出来たのですが、最近の PHPUnit には `staticExpects` はありません。
|
30
|
+
|
31
|
+
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
|
2
fix
answer
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<?php
|
7
7
|
class Hoge
|
8
8
|
{
|
9
|
-
public static function func() {}
|
9
|
+
public static function func($val) {}
|
10
10
|
}
|
11
11
|
|
12
12
|
class HogeTest extends PHPUnit_Framework_TestCase
|
@@ -15,7 +15,7 @@
|
|
15
15
|
{
|
16
16
|
$obj = $this->getMockBuilder(Hoge::class)->getMock();
|
17
17
|
$obj->expects($this->any())->method('func')->with($this->anything())->will($this->returnValue(true));
|
18
|
-
$obj->func();
|
18
|
+
$this->assertTrue($obj->func(123));
|
19
19
|
}
|
20
20
|
}
|
21
21
|
```
|
1
add
answer
CHANGED
@@ -1,1 +1,26 @@
|
|
1
|
-
LogUtil::kpiLogger が static メソッドなのではないでしょうか?
|
1
|
+
LogUtil::kpiLogger が static メソッドなのではないでしょうか?
|
2
|
+
|
3
|
+
static メソッドをモックして呼ぶと `PHPUnit_Framework_MockObject_BadMethodCallException` になります。
|
4
|
+
|
5
|
+
```php
|
6
|
+
<?php
|
7
|
+
class Hoge
|
8
|
+
{
|
9
|
+
public static function func() {}
|
10
|
+
}
|
11
|
+
|
12
|
+
class HogeTest extends PHPUnit_Framework_TestCase
|
13
|
+
{
|
14
|
+
public function test()
|
15
|
+
{
|
16
|
+
$obj = $this->getMockBuilder(Hoge::class)->getMock();
|
17
|
+
$obj->expects($this->any())->method('func')->with($this->anything())->will($this->returnValue(true));
|
18
|
+
$obj->func();
|
19
|
+
}
|
20
|
+
}
|
21
|
+
```
|
22
|
+
|
23
|
+
```
|
24
|
+
1) HogeTest::test
|
25
|
+
PHPUnit_Framework_MockObject_BadMethodCallException:
|
26
|
+
```
|