3
3
This package integrates the function mock library
4
4
[ PHP-Mock] ( https://github.com/php-mock/php-mock ) with PHPUnit.
5
5
6
- # Requirements
7
-
8
6
# Installation
9
7
8
+ Use [ Composer] ( https://getcomposer.org/ ) :
9
+
10
+ ``` json
11
+ {
12
+ "require-dev" : {
13
+ "php-mock/phpunit" : " 0.1"
14
+ }
15
+ }
16
+ ```
17
+
10
18
# Usage
11
19
12
20
PHP-Mock integrates with the trait
@@ -24,20 +32,40 @@ namespace foo;
24
32
25
33
use phpmock\phpunit\PHPMock;
26
34
27
- class FooTest extends \PHPUnit_Framework_TestCase
35
+ class BuiltinTest extends \PHPUnit_Framework_TestCase
28
36
{
29
37
30
38
use PHPMock;
31
39
32
- public function testBar ()
40
+ public function testTime ()
33
41
{
34
42
$time = $this->getFunctionMock(__NAMESPACE__, "time");
35
43
$time->expects($this->once())->willReturn(3);
44
+
36
45
$this->assertEquals(3, time());
37
46
}
47
+
48
+ public function testExec()
49
+ {
50
+ $exec = $this->getFunctionMock(__NAMESPACE__, "exec");
51
+ $exec->expects($this->once())->willReturnCallback(
52
+ function ($command, & $output, & $return_var) {
53
+ $this->assertEquals("foo", $command);
54
+ $output = ["failure"];
55
+ $return_var = 1;
56
+ }
57
+ );
58
+
59
+ exec("foo", $output, $return_var);
60
+ $this->assertEquals(["failure"], $output);
61
+ $this->assertEquals(1, $return_var);
62
+ }
38
63
}
39
64
```
40
65
66
+ There's no need to disable the mocked function. The PHPUnit integration does
67
+ that for you.
68
+
41
69
# License and authors
42
70
43
71
This project is free and under the WTFPL.
0 commit comments