ホームページ  >  記事  >  バックエンド開発  >  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 までご連絡ください。