eltrino/phpunit-mockannotations

PHPUnit MockAnnotations

2.0.0 2017-04-14 15:44 UTC

This package is not auto-updated.

Last update: 2024-09-20 04:01:05 UTC


README

该工具提供了一种简化方法,通过在属性文档块中使用注解来创建本地PHPUnit模拟。目前不支持创建抽象类的模拟。

###安装

通过composer安装

composer require eltrino/phpunit-mockannotations

或将其添加到您的composer.json文件中。

用法

namespace Lib\Tests;

use Lib\Generator;
use Lib\ConfigInterface;
use Eltrino\PHPUnit\MockAnnotations\MockAnnotations;
use PHPUnit\Framework\TestCase;

class GeneratorTest extends TestCase
{
    /**
     * @Mock Lib\ConfigInterface
     */
    private $config;
    
    protected function setUp()
    {
        MockAnnotations::init($this);
    }
    
    public function testProcess()
    {
        $config
            ->expects($this->once())
            ->method('getOption')
            ->with($this->equalTo('title'))
            ->will($this->returnValue('option_value'));
            
        $generator = new Generator($this->config);
        $result = $generator->process();
        
        $this->assertIsNotNull($result);
    }
}

###许可证 MIT

贡献

我们欢迎各种形式的贡献,包括错误报告、补丁提交、功能请求或文档改进。如果您想成为项目的一部分,请参阅我们的贡献指南