承接 aeris/spy 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

aeris/spy

最新稳定版本:1.1.0

Composer 安装命令:

composer require aeris/spy

包简介

Test spies

README 文档

README

Test spies for PHP.

Install

composer require aeris/spy

Overview

An Aeris\Spy allows you to mock callables in PHP. A Spy wraps around a Mockery\ object, which means that you can use Mockery expectations with your Aeris Spies.

For example:

$spy = new Spy();

$spy(5);
$spy(6);
$spy(7);

$spy->shouldHaveBeenCalled()
  ->twice()
  ->with(\Mockery::on(function($arg) {
    return $arg > 5;
  )))

API

shouldHaveBeenCalled() / shouldNotHaveBeenCalled()

$spy = new Spy();

$spy();

$spy->shouldHaveBeenCalled();  // Passes (no exception)
$spy->shouldNotHaveBeenCalled(); // Failed (throws \Mockery\Exception\InvalidCountException)

andReturn($val)

$spy = new Spy();
$spy->andReturn('foo');

$spy();  // 'foo'

andReturnUsing

$spy = new Spy()
$spy->andReturnUsing(function($str) {
  strtoupper($str);
});

$spy('foo');  // 'FOO'

Spy::returns($val);

Creates a spy which returns a value. Short-hand for creating a spy, then calling andReturn.

$spy = Spy::returns('foo');

$spy(); 	// 'foo'

Spy::returnsUsing($callable);

Creates a spy which returns a value via a callable. Short-hand for creating a spy, then calling andReturnUsing.

$spy = Spy::returnsUsing(function($str) {
  strtoupper($str);
});

$spy('foo'); 	// 'FOO'

统计信息

  • 总下载量: 3.94k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: BSD
  • 更新时间: 2015-08-13