https://github.com/phpspec/prophecy-phpunit
Integrating Prophecy in PHPUnit test cases
https://github.com/phpspec/prophecy-phpunit
Last synced: about 1 year ago
JSON representation
Integrating Prophecy in PHPUnit test cases
- Host: GitHub
- URL: https://github.com/phpspec/prophecy-phpunit
- Owner: phpspec
- License: mit
- Created: 2013-07-04T19:43:48.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2025-05-13T13:52:33.000Z (about 1 year ago)
- Last Synced: 2025-05-13T23:16:30.868Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 72.3 KB
- Stars: 185
- Watchers: 16
- Forks: 40
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Prophecy
[](https://github.com/phpspec/prophecy-phpunit/actions/workflows/ci.yml)
Prophecy PhpUnit integrates the [Prophecy](https://github.com/phpspec/prophecy) mocking
library with [PHPUnit](https://phpunit.de) 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
```bash
composer require --dev phpspec/prophecy-phpunit
```
You can read more about Composer on its [official webpage](https://getcomposer.org).
## How to use it
The trait ``ProphecyTrait`` provides a method ``prophesize($classOrInterface = null)`` to use Prophecy.
For the usage of the Prophecy doubles, please refer to the [Prophecy documentation](https://github.com/phpspec/prophecy).
Below is a usage example:
```php
prophesize(Hasher::class);
$user = new User($hasher->reveal());
$hasher->generateHash($user, 'qwerty')->willReturn('hashed_pass');
$user->setPassword('qwerty');
$this->assertEquals('hashed_pass', $user->getPassword());
}
}
```