Skip to content

Commit 65431d9

Browse files
committed
Update the documentation following #2
1 parent 82bc288 commit 65431d9

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ It doesn't reinvent anything and is not intended to cover every use case: only t
1717
$ composer require --dev mnapoli/phpunit-easymock
1818
```
1919

20+
To be able to use EasyMock in your tests **you must include the trait in your class**:
21+
22+
```php
23+
class MyTest extends \PHPUnit_Framework_TestCase
24+
{
25+
use EasyMock;
26+
27+
// ...
28+
}
29+
```
30+
2031
## Usage
2132

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

3748
```php
38-
$mock = EasyMock::mock('My\Class', [
49+
$mock = $this->easyMock('My\Class', [
3950
'sayHello' => 'Hello',
4051
]);
4152
```
4253

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

4556
```php
46-
$mock = EasyMock::spy('My\Class', [
57+
$mock = $this->easySpy('My\Class', [
4758
'sayHello' => 'Hello',
4859
]);
4960
```
@@ -53,15 +64,15 @@ $mock = EasyMock::spy('My\Class', [
5364
You can mock methods so that they return values:
5465

5566
```php
56-
$mock = EasyMock::mock('My\Class', [
67+
$mock = $this->easyMock('My\Class', [
5768
'sayHello' => 'Hello',
5869
]);
5970
```
6071

6172
Or so that they use a callback:
6273

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

7384
```php
74-
$mock = EasyMock::mock('My\Class', [
85+
$mock = $this->easyMock('My\Class', [
7586
'sayHello' => new \RuntimeException('Whoops'),
7687
]);
7788
```
7889

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

8192
```php
82-
$mock = EasyMock::mock('My\Class');
93+
$mock = $this->easyMock('My\Class');
8394

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

93104
```php
94-
$mock = EasyMock::mock('My\Class', [
105+
$mock = $this->easyMock('My\Class', [
95106
'sayHello' => 'hello',
96107
]);
97108

0 commit comments

Comments
 (0)