|
2 | 2 |
|
3 | 3 | *Mocks, stubs, and spies for PHP.* |
4 | 4 |
|
5 | | -[![The most recent stable version is 0.5.1][version-image]][semantic versioning] |
| 5 | +[![The most recent stable version is 0.5.2][version-image]][semantic versioning] |
6 | 6 | [![Current build status image][build-image]][current build status] |
7 | 7 | [![Current coverage status image][coverage-image]][current coverage status] |
8 | 8 |
|
|
11 | 11 | [coverage-image]: https://img.shields.io/codecov/c/github/eloquent/phony/develop.svg?style=flat-square "Current test coverage for the develop branch" |
12 | 12 | [current coverage status]: https://codecov.io/github/eloquent/phony |
13 | 13 | [semantic versioning]: http://semver.org/ |
14 | | -[version-image]: http://img.shields.io/:semver-0.5.1-yellow.svg?style=flat-square "This project uses semantic versioning" |
| 14 | +[version-image]: http://img.shields.io/:semver-0.5.2-yellow.svg?style=flat-square "This project uses semantic versioning" |
15 | 15 |
|
16 | 16 | ## Installation and documentation |
17 | 17 |
|
18 | 18 | - Available as [Composer] package [eloquent/phony]. |
| 19 | +- Read the [manual]. |
| 20 | +- Read the [API documentation]. |
19 | 21 |
|
| 22 | +[api documentation]: http://lqnt.co/phony/artifacts/documentation/api/ |
20 | 23 | [composer]: http://getcomposer.org/ |
21 | 24 | [eloquent/phony]: https://packagist.org/packages/eloquent/phony |
22 | 25 |
|
23 | | -## Here be dragons |
| 26 | +## What is *Phony*? |
24 | 27 |
|
25 | | -Documentation is coming, you can see [progress on the feature/docs branch]. Also |
26 | | -check out the [functional tests] for working examples. |
| 28 | +*Phony* is a PHP library for creating [test doubles]. *Phony* has first-class |
| 29 | +support for many modern PHP features such as [traits] and [generators], and |
| 30 | +supports PHP 7 and [HHVM]. |
27 | 31 |
|
28 | | -[functional tests]: test/suite/FunctionalTest.php |
29 | | -[progress on the feature/docs branch]: https://github.com/eloquent/phony/blob/feature/docs/doc/index.md |
| 32 | +[generators]: http://php.net/language.generators.overview |
| 33 | +[hhvm]: http://hhvm.com/ |
| 34 | +[test doubles]: https://en.wikipedia.org/wiki/Test_double |
| 35 | +[traits]: http://php.net/traits |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +For detailed usage, see the [manual]. |
| 40 | + |
| 41 | +### Standalone usage |
| 42 | + |
| 43 | +```php |
| 44 | +use function Eloquent\Phony\mock; |
| 45 | + |
| 46 | +$handle = mock('ClassA'); |
| 47 | +$handle->methodA('argument')->returns('value'); |
| 48 | + |
| 49 | +$mock = $handle->mock(); |
| 50 | + |
| 51 | +assert($mock->methodA('argument') === 'value'); |
| 52 | +$handle->methodA->calledWith('argument'); |
| 53 | +``` |
| 54 | + |
| 55 | +### Peridot usage |
| 56 | + |
| 57 | +```php |
| 58 | +use function Eloquent\Phony\mock; |
| 59 | + |
| 60 | +describe('Phony', function () { |
| 61 | + it('integrates with Peridot', function () { |
| 62 | + $handle = mock('ClassA'); |
| 63 | + $handle->methodA('argument')->returns('value'); |
| 64 | + |
| 65 | + $mock = $handle->mock(); |
| 66 | + |
| 67 | + expect($mock->methodA('argument'))->to->equal('value'); |
| 68 | + $handle->methodA->calledWith('argument'); |
| 69 | + }); |
| 70 | +}); |
| 71 | +``` |
| 72 | + |
| 73 | +### Pho usage |
| 74 | + |
| 75 | +```php |
| 76 | +use function Eloquent\Phony\Pho\mock; |
| 77 | + |
| 78 | +describe('Phony', function () { |
| 79 | + it('integrates with Pho', function () { |
| 80 | + $handle = mock('ClassA'); |
| 81 | + $handle->methodA('argument')->returns('value'); |
| 82 | + |
| 83 | + $mock = $handle->mock(); |
| 84 | + |
| 85 | + expect($mock->methodA('argument'))->toBe('value'); |
| 86 | + $handle->methodA->calledWith('argument'); |
| 87 | + }); |
| 88 | +}); |
| 89 | +``` |
| 90 | + |
| 91 | +### PHPUnit usage |
| 92 | + |
| 93 | +```php |
| 94 | +use Eloquent\Phony\Phpunit\Phony; |
| 95 | + |
| 96 | +class PhonyTest extends PHPUnit_Framework_TestCase |
| 97 | +{ |
| 98 | + public function testIntegration() |
| 99 | + { |
| 100 | + $handle = Phony::mock('ClassA'); |
| 101 | + $handle->methodA('argument')->returns('value'); |
| 102 | + |
| 103 | + $mock = $handle->mock(); |
| 104 | + |
| 105 | + $this->assertSame('value', $mock->methodA('argument')); |
| 106 | + $handle->methodA->calledWith('argument'); |
| 107 | + } |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +### SimpleTest usage |
| 112 | + |
| 113 | +```php |
| 114 | +use Eloquent\Phony\Simpletest\Phony; |
| 115 | + |
| 116 | +class PhonyTest extends UnitTestCase |
| 117 | +{ |
| 118 | + public function testIntegration() |
| 119 | + { |
| 120 | + $handle = Phony::mock('ClassA'); |
| 121 | + $handle->methodA('argument')->returns('value'); |
| 122 | + |
| 123 | + $mock = $handle->mock(); |
| 124 | + |
| 125 | + $this->assertSame($mock->methodA('argument'), 'value'); |
| 126 | + $handle->methodA->calledWith('argument'); |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +[manual]: doc/index.md |
0 commit comments