首頁  >  文章  >  後端開發  >  PHP 5.3+模拟框架:Prophecy

PHP 5.3+模拟框架:Prophecy

WBOY
WBOY原創
2016-06-20 12:52:311039瀏覽

Prophecy 是功能强劲且灵活的 PHP 5.3+ 的模拟框架。尽管它最初是用来满足 phpspec2 的需求,但是它足够灵活,并且可以在任何测试框架中使用。

示例代码:

<?phpclass UserTest extends PHPUnit_Framework_TestCase{    private $prophet;    public function testPasswordHashing()    {        $hasher = $this->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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:代码上线php下一篇:phpstorm