unit-testing/mockery-helper 问题修复 & 功能扩展

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

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

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-dev block of composer.json, add "unit-testing/mockery-helper": "dev-master" and then run composer update
  • don't forget to require-dev mockery/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 for Mockery::mock()
  • You can also use $this->spy() as an alias for Mockery::spy()
  • Use the result of one of the above function calls as you normally would for your assertions.
  • mockery method 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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-17