Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Integrating Prophecy in PHPUnit test cases

License

NotificationsYou must be signed in to change notification settings

phpspec/prophecy-phpunit

Repository files navigation

Build Status

Prophecy PhpUnit integrates theProphecy mockinglibrary withPHPUnit to provide an easier mocking in your testsuite.

Installation

Prerequisites

Prophecy PhpUnit requires PHP 7.3 or greater.Prophecy PhpUnit requires PHPUnit 9.1 or greater. Older versions of PHPUnit are providing the Prophecy integration themselves.

Setup through composer

composer require --dev phpspec/prophecy-phpunit

You can read more about Composer on itsofficial webpage.

How to use it

The traitProphecyTrait provides a methodprophesize($classOrInterface = null) to use Prophecy.For the usage of the Prophecy doubles, please refer to theProphecy documentation.

Below is a usage example:

<?phpnamespaceApp;usePHPUnit\Framework\TestCase;useProphecy\PhpUnit\ProphecyTrait;useApp\Security\Hasher;useApp\Entity\User;class UserTestextends TestCase{use ProphecyTrait;publicfunctiontestPasswordHashing()    {$hasher =$this->prophesize(Hasher::class);$user   =newUser($hasher->reveal());$hasher->generateHash($user,'qwerty')->willReturn('hashed_pass');$user->setPassword('qwerty');$this->assertEquals('hashed_pass',$user->getPassword());    }}

About

Integrating Prophecy in PHPUnit test cases

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors14

Languages


[8]ページ先頭

©2009-2025 Movatter.jp