-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStubTest.php
More file actions
26 lines (18 loc) · 818 Bytes
/
Copy pathStubTest.php
File metadata and controls
26 lines (18 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
require_once "SomeClass.php";
class StubTest extends \PHPUnit\Framework\TestCase {
public function testStub() {
// 为 SomeClass 类创建桩件。
$stub = $this->createMock(SomeClass::class);
// 配置桩件。
$stub->expects($this->any())->method('doSomething')->willReturn('foo');
// 现在调用 $stub->doSomething() 将返回 'foo'。
$this->assertEquals('foo', $stub->doSomething());
}
public function testMock() {
$stub = $this->getMockBuilder('SomeClass')->disableOriginalConstructor()->getMock();
//建立预期doSomething被执行0次或多次,返回foo值
$stub->expects($this->any())->method('doSomething')->will($this->returnValue('foo'));
$this->assertEquals('foo', $stub->doSomething());
}
}