2017 © Pedro Peláez
 

library spy

Test spies

image

aeris/spy

Test spies

  • Thursday, August 13, 2015
  • by eschwartz
  • Repository
  • 6 Watchers
  • 0 Stars
  • 3,260 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 37 % Grown

The README.md

Spy

Test spies for PHP., (*1)

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., (*2)

For example:, (*3)

$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., (*4)

$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., (*5)

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

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

The Versions

13/08 2015

dev-master

9999999-dev

Test spies

  Sources   Download

BSD

The Requires

 

by Edan Schwartz

13/08 2015

1.1.0

1.1.0.0

Test spies

  Sources   Download

BSD

The Requires

 

by Edan Schwartz

13/08 2015

1.0.0

1.0.0.0

Test spies

  Sources   Download

BSD

The Requires

 

by Edan Schwartz