- Notifications
You must be signed in to change notification settings - Fork41
Integrating Prophecy in PHPUnit test cases
License
phpspec/prophecy-phpunit
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Prophecy PhpUnit integrates theProphecy mockinglibrary withPHPUnit to provide an easier mocking in your testsuite.
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.
composer require --dev phpspec/prophecy-phpunit
You can read more about Composer on itsofficial webpage.
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors14
Uh oh!
There was an error while loading.Please reload this page.