phpspec/prophecy-phpunit 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phpspec/prophecy-phpunit

最新稳定版本:v2.4.0

Composer 安装命令:

composer require phpspec/prophecy-phpunit

包简介

Integrating the Prophecy mocking library in PHPUnit test cases

README 文档

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 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

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());
    }
}

统计信息

  • 总下载量: 50.88M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 195
  • 点击次数: 1
  • 依赖项目数: 1465
  • 推荐数: 1

GitHub 信息

  • Stars: 194
  • Watchers: 14
  • Forks: 41
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04