Skip to content

Commit

Permalink
Update the documentation following #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Oct 18, 2015
1 parent 82bc288 commit 65431d9
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ It doesn't reinvent anything and is not intended to cover every use case: only t
$ composer require --dev mnapoli/phpunit-easymock
```

To be able to use EasyMock in your tests **you must include the trait in your class**:

```php
class MyTest extends \PHPUnit_Framework_TestCase
{
use EasyMock;

// ...
}
```

## Usage

Here is what a very common PHPUnit mock looks like:
Expand All @@ -35,15 +46,15 @@ Yuck!
Here is how to write it with EasyMock:

```php
$mock = EasyMock::mock('My\Class', [
$mock = $this->easyMock('My\Class', [
'sayHello' => 'Hello',
]);
```

What if you want to assert that the method is called once (i.e. `$mock->expect($this->once())`)? Use `spy()` instead:

```php
$mock = EasyMock::spy('My\Class', [
$mock = $this->easySpy('My\Class', [
'sayHello' => 'Hello',
]);
```
Expand All @@ -53,15 +64,15 @@ $mock = EasyMock::spy('My\Class', [
You can mock methods so that they return values:

```php
$mock = EasyMock::mock('My\Class', [
$mock = $this->easyMock('My\Class', [
'sayHello' => 'Hello',
]);
```

Or so that they use a callback:

```php
$mock = EasyMock::mock('My\Class', [
$mock = $this->easyMock('My\Class', [
'sayHello' => function ($name) {
return 'Hello ' . $name;
},
Expand All @@ -71,17 +82,17 @@ $mock = EasyMock::mock('My\Class', [
You can also have methods throw exceptions by providing an `Exception` instance:

```php
$mock = EasyMock::mock('My\Class', [
$mock = $this->easyMock('My\Class', [
'sayHello' => new \RuntimeException('Whoops'),
]);
```

It is possible to call the `mock()` method again on an existing mock:

```php
$mock = EasyMock::mock('My\Class');
$mock = $this->easyMock('My\Class');

$mock = EasyMock::mock($mock, [
$mock = $this->easyMock($mock, [
'sayHello' => 'Hello',
]);
```
Expand All @@ -91,7 +102,7 @@ $mock = EasyMock::mock($mock, [
If you want to use assertions or other PHPUnit features, just do it:

```php
$mock = EasyMock::mock('My\Class', [
$mock = $this->easyMock('My\Class', [
'sayHello' => 'hello',
]);

Expand Down

0 comments on commit 65431d9

Please sign in to comment.