prophecy 是功能强劲且灵活的 php 5.3+ 的模拟框架。尽管它最初是用来满足 phpspec2 的需求,但是它足够灵活,并且可以在任何测试框架中使用。
示例代码:
prophet->prophesize('app\security\hasher'); $user = new app\entity\user($hasher->reveal()); $hasher->generatehash($user, 'qwerty')->willreturn('hashed_pass'); $user->setpassword('qwerty'); $this->assertequals('hashed_pass', $user->getpassword()); } protected function setup() { $this->prophet = new \prophecy\prophet; } protected function teardown() { $this->prophet->checkpredictions(); }}
项目主页:http://www.open-open.com/lib/view/home/1437393986490