Skip to content

Commit

Permalink
Update README to mention Patchwork loading during installation
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig committed Jan 3, 2017
1 parent abcd456 commit d7eb4b1
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
# Spies

A library to make testing in PHP so much easier. You can install it in a PHP project by running:

`composer require --dev sirbrillig/spies`.

Then just make sure you include the autoloader somewhere in your code:

If using in PHPUnit, you can add autoload to your `phpunit.xml` file:
```
<phpunit bootstrap="vendor/autoload.php">
...
```

Otherwise you can include the autoloader manually:
```
require( './vendor/autoload.php' );
```
A library to make testing in PHP so much easier. You can install it in a PHP project by following [the instructions below](#installation).

What is it? If you've ever used [sinon](http://sinonjs.org/) in JavaScript testing, you know about the concept of *Test Spies*, and in many ways this library is just implementing those concepts in PHP. It also includes *Expectations* to simplify spy assertions, inspired by [sinon-chai](https://github.com/domenic/sinon-chai).

Expand Down Expand Up @@ -85,6 +70,27 @@ Spies was designed as an optional replacement for the very excellent [WP_Mock](h

Suggestions, bug reports, and feature requests all welcome!

# Installation

A library to make testing in PHP so much easier. You can install it in a PHP project by running:

`composer require --dev sirbrillig/spies`.

Then just make sure you include the autoloader somewhere in your code:

If using in PHPUnit, you can add autoload to your `phpunit.xml` file:
```
<phpunit bootstrap="vendor/autoload.php">
...
```

Otherwise you can include the autoloader manually:
```
require( './vendor/autoload.php' );
```

However, please see [the note on mocking and spying on existing functions](#spying-and-mocking-existing-functions). If you need to do this, you will need to add an explicit bootstrap file.

# The Details

## Global Functions
Expand Down Expand Up @@ -358,7 +364,15 @@ See the [API document](API.md) for the full list of custom assertions available.

# Spying and Mocking existing functions

PHP does not allow mocking existing functions. However, there is a library called [Patchwork](http://patchwork2.org/) which allows this. If that library is loaded, it will be used by Spies. The library must be loaded *before* Spies. One way to do this is to use a test bootstrap file. Here's an example:
PHP does not allow mocking existing functions. However, there is a library called [Patchwork](http://patchwork2.org/) which allows this. If that library is loaded, it will be used by Spies. The library must be loaded *before* Spies. One way to do this is to use a test bootstrap file.

If using in PHPUnit, you can require the bootstrap from your `phpunit.xml` file:
```
<phpunit bootstrap="tests/bootstrap.php">
...
```

Here is an example bootstrap file that also loads the autoloader:

```php
<?php
Expand Down

0 comments on commit d7eb4b1

Please sign in to comment.