https://github.com/peridot-php/peridot-prophecy-plugin
Add prophecy to your peridot tests and auto inject mocks
https://github.com/peridot-php/peridot-prophecy-plugin
Last synced: 11 months ago
JSON representation
Add prophecy to your peridot tests and auto inject mocks
- Host: GitHub
- URL: https://github.com/peridot-php/peridot-prophecy-plugin
- Owner: peridot-php
- Created: 2014-11-05T01:46:34.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-10-30T16:24:51.000Z (over 8 years ago)
- Last Synced: 2025-03-30T09:20:41.240Z (about 1 year ago)
- Language: PHP
- Homepage: http://peridot-php.github.io/
- Size: 156 KB
- Stars: 4
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Peridot Prophecy Plugin
=======================
[](https://travis-ci.org/peridot-php/peridot-prophecy-plugin) [](http://hhvm.h4cc.de/package/peridot-php/peridot-prophecy-plugin)
Use Peridot with the amazing mocking framework [Prophecy](https://github.com/phpspec/prophecy)
##Usage
We recommend installing this plugin to your project via composer:
```
$ composer require --dev peridot-php/peridot-prophecy-plugin:~1.0
```
You can register the plugin via your [peridot.php](http://peridot-php.github.io/#plugins) file.
```php
getProphet()->prophesize('Bird');
//do stuff with the mock
});
});
```
###Automatic injection of mock
If a test suite's description is an existing class, the prophecy plugin will automatically inject a `$subject` instance
variable into your tests that is a mock of the class.
```php
describe('Vendor\Namespace\Klass', function() {
it('should have a subject', function() {
$instance = $this->subject->reveal();
assert($instance instanceof Klass, 'should be instance of Klass');
});
});
```
###Using the scope on a test by test basis
Like any other peridot [scope](http://peridot-php.github.io/#scopes), you can mix the `ProphecyScope` provided by this plugin
on a test by test, or suite by suite basis.
```php
peridotAddChildScope($scope);
it('should fly', function() {
$mock = $this->getProphet()->prophesize('Bird');
//do stuff with the mock
});
});
```
##Example specs
To test examples that are using the plugin, run the following:
```
$ vendor/bin/peridot example/bird.spec.php
```
##Running plugin tests
```
$ vendor/bin/peridot specs/
```