This package is abandoned and no longer maintained. The author suggests using the phpunit/phpunit package instead.

PhpUnit test case integrating the Prophecy mocking library

v1.1.0 2015-02-09 11:20 UTC

This package is auto-updated.

Last update: 2019-02-20 19:25:18 UTC


This package is not maintained anymore. Prophecy is supported in PHPUnit directly as of PHPUnit 4.5, making this package useless.

Build Status

Prophecy PhpUnit integrates the Prophecy mocking library with PHPUnit to provide an easier mocking in your testsuite.



use Prophecy\PhpUnit\ProphecyTestCase;

class UserTest extends ProphecyTestCase
    public function testPasswordHashing()
        $hasher = $this->prophesize('App\Security\Hasher');
        $user   = new App\Entity\User($hasher->reveal());

        $hasher->generateHash($user, 'qwerty')->willReturn('hashed_pass');


        $this->assertEquals('hashed_pass', $user->getPassword());



Prophecy PhpUnit requires PHP 5.3.3 or greater.

Setup through composer

First, add Prophecy to the list of dependencies inside your composer.json:

    "require-dev": {
        "phpspec/prophecy-phpunit": "~1.0"

Then simply install it with composer:

$> composer install --prefer-dist

You can read more about Composer on its official webpage.

How to use it

The special ProphecyTestCase exposes a method prophesize($classOrInterface = null) to use Prophecy. For the usage of the Prophecy doubles, please refer to the Prophecy documentation.

If you want to add some logic in the tearDown method you are advised to call the parent method - doing so will ensure that the Prophect object has been unset before the next test case runs.