Prophecy是功能强劲且灵活的PHP5.3+的模拟框架。尽管它最初是用来满足phpspec2的需求,但是它足够灵活,并且可以在任何测试框架中使用。
示例代码:
<?phpclass UserTest exteds PHPUit_Framework_TestCase{ private $prophet; public fuctio testPasswordHashig() { $hasher = $this->prophet->prophesize('App\Security\Hasher'); $user = ew App\Etity\User($hasher->reveal()); $hasher->geerateHash($user, 'qwerty')->willRetur('hashed_pass'); $user->setPassword('qwerty'); $this->assertEquals('hashed_pass', $user->getPassword()); } protected fuctio setup() { $this->prophet = ew \Prophecy\Prophet; } protected fuctio tearDow() { $this->prophet->checkPredictios(); }}









评论