xp-framework/mocks 问题修复 & 功能扩展

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

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

xp-framework/mocks

最新稳定版本:v8.0.1

Composer 安装命令:

composer require xp-framework/mocks

包简介

Mocks for the XP Framework

关键字:

README 文档

README

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.0+ Supports PHP 8.0+ Latest Stable Version

Mocks for the XP Framework.

Example

Here's an example implementation:

use lang\IllegalAccessException;

interface Context {
  public function hasPermission($name);
}

class UserService {
  private $context;

  public function __construct(Context $context) {
    $this->context= $context;
  }

  public function allUsers() {
    if (!$this->context->hasPermission('rt=all,rn=users')) {
      throw new IllegalAccessException('Permission denied!');
    }

    return []; // TODO: Actually do something:)
  }
}

This is how we can mock the Context interface:

use unittest\TestCase;

class UserServiceTest extends TestCase {

  #[@test]
  public function allUsers_works_when_hasPermission_returns_true() {
    $mocks= new MockRepository();
    $context= $mocks->createMock('Context');
    $context->hasPermission('rt=all,rn=users')->returns(true);
    $mocks->replayAll();

    $fixture= new UserService($context);
    $this->assertEquals([], $fixture->allUsers());
  }
}

Further reading

See XP RFC #0219 for a detailled introduction.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-08-06