@@ -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
2233Here is what a very common PHPUnit mock looks like:
@@ -35,15 +46,15 @@ Yuck!
3546Here 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
4354What 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', [
5364You 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
6172Or 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', [
7182You 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
7990It 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, [
91102If 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