PHP 5.3+模擬框架:Prophecy

yxwpx 9年前發布 | 10K 次閱讀 Prophecy PHP開發

Prophecy 是功能強勁且靈活的 PHP 5.3+ 的模擬框架。盡管它最初是用來滿足 phpspec2 的需求,但是它足夠靈活,并且可以在任何測試框架中使用。

示例代碼:

<?php
class 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.baiduhome.net/lib/view/home/1437393986490

 本文由用戶 yxwpx 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!