console-helpers/prophecy-phpunit
PHPUnit integration helpers for Prophecy, providing convenience traits and utilities to streamline mock creation, prophecy assertions, and cleanup in your test suite. Designed to reduce boilerplate and keep Prophecy-based unit tests tidy and consistent.
Prophecy PhpUnit integrates the Prophecy mocking library with PHPUnit to provide an easier mocking in your testsuite.
Prophecy PhpUnit requires PHP 5.6 or greater. Prophecy PhpUnit requires PHPUnit 5.0 or greater.
composer require --dev phpspec/prophecy-phpunit
You can read more about Composer on its official webpage.
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());
}
}
How can I help you explore Laravel packages today?