unit-testing/mockery-helper
最新稳定版本:v1.0.0
Composer 安装命令:
composer require --dev unit-testing/mockery-helper
包简介
a simple trait for convenient implementation of mockery mocks and spies in PHPUnit tests
README 文档
README
Simple module to help with creating mocks using mockery. You won't have to continually reference Mockery\Mockery and keep your tests a little DRY'er.
Installation
composer require --dev unit-testing/mockery-helper:dev-master- or in
require-devblock ofcomposer.json, add"unit-testing/mockery-helper": "dev-master"and then runcomposer update - don't forget to
require-devmockery/mockery
Usage
- In your phpunit test,
use UnitTesting\MockeryHelper\MockeryTrait. - in your
tearDown()method call$this->closeMocks() - When you want to mock something, use
$this->mock()as an alias forMockery::mock() - You can also use
$this->spy()as an alias forMockery::spy() - Use the result of one of the above function calls as you normally would for your assertions.
mockerymethod simply forwards any call to the Mockery static. The first argument is the method, and subsequent arguments are params for the Mockery method.
Example
<?php
use UnitTesting\MockeryHelper\MockeryTrait;
class SomeTest extends \PHPUnit_Framework_Testcase {
use MockeryTrait;
protected function tearDown()
{
$this->cleanUpSomeStuffBeforeEachTest();
$this->closeMocks();
}
function testSomeMethodWithAMock()
{
$mock = $this->mock('Child');
$parent = new ParentThatDependsChild($mock);
$mock->shouldReceive('doSomething')->once()->with($this->mockery('type', 'string'))->andReturn('result');
$result = $parent->someMethodWhichCallsDoSomethingOfChild('foo');
$this->assertEquals('result', $result);
}
}
统计信息
- 总下载量: 68
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-17