awesomite/mock-finals
Composer 安装命令:
composer require awesomite/mock-finals
包简介
Mocking final classes and methods
README 文档
README
Mock Finals
Mock final classes and methods in your tests. Library overrides existing class loaders and removes all final
occurrences in runtime using uopz_flags.
Installation
composer require --dev awesomite/mock-finals
Requirements
- PHP ^7.1
- uopz (
pecl install uopz)
Use cases
In general, it's a bad practice to do so. However it may be helpful when you have to deal with legacy code or third party libraries.
Please read the following article to understand how to properly deal with final keyword in your code.
Example
class Greeter { final public function sayHello(): string { return 'hello'; } } class MyTest extends \PHPUnit\Framework\TestCase { public function testSayHello(): void { $mock = $this->getMockBuilder(Greeter::class)->getMock(); $mock ->expects($this->once()) ->method('sayHello') ->willReturn('goodbye') ; $this->assertSame('goodbye', $mock->sayHello()); } }
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-19