xp-framework/mocks
最新稳定版本:v8.0.1
Composer 安装命令:
composer require xp-framework/mocks
包简介
Mocks for the XP Framework
README 文档
README
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
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-08-06

