console-helpers/prophecy-phpunit

Integrating the Prophecy mocking library in PHPUnit test cases

Maintainers

👁 aik099

Package info

github.com/console-helpers/prophecy-phpunit

Homepage

pkg:composer/console-helpers/prophecy-phpunit

Statistics

Installs: 3 497

Dependents: 5

Suggesters: 0

Stars: 0

Open Issues: 0

v3.1.0 2026-05-14 10:38 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT da65bda2fba966f22b0598092d50cfa414a10ffe

  • Christophe Coevoet <stof.woop@notk.org>

phpunitprophecy

This package is auto-updated.

Last update: 2026-06-19 07:42:17 UTC


README

👁 Build Status

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

Installation

Prerequisites

Prophecy PhpUnit requires PHP 5.6 or greater. Prophecy PhpUnit requires PHPUnit 5.0 or greater.

Setup through composer

composer require --dev phpspec/prophecy-phpunit

You can read more about Composer on its official webpage.

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.

Below is a usage example:

<?php

namespace App;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use App\Security\Hasher;
use App\Entity\User;

class UserTest extends TestCase
{
 use ProphecyTrait;

 public function testPasswordHashing()
 {
 $hasher = $this->prophesize(Hasher::class);
 $user = new User($hasher->reveal());

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

 $user->setPassword('qwerty');

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