定制 console-helpers/prophecy-phpunit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

console-helpers/prophecy-phpunit

最新稳定版本:v3.0.0

Composer 安装命令:

composer require console-helpers/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 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());
    }
}

统计信息

  • 总下载量: 2.72k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 41
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-28