peridot-php/peridot-prophecy-plugin

Inject prophecy mocks into your Peridot tests

Maintainers

👁 brianium

Package info

github.com/peridot-php/peridot-prophecy-plugin

pkg:composer/peridot-php/peridot-prophecy-plugin

Statistics

Installs: 101 135

Dependents: 14

Suggesters: 1

Stars: 4

Open Issues: 1

1.1.0 2014-11-25 17:54 UTC

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 425c097aa93b8949d26f6820ca9905ec3d988c2d

  • Brian Scaturro <scaturrob.woop@gmail.com>

This package is not auto-updated.

Last update: 2026-06-16 12:07:54 UTC


README

👁 Build Status
👁 HHVM Status

Use Peridot with the amazing mocking framework 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 file.

<?php
use Evenement\EventEmitterInterface;
use Peridot\Plugin\Prophecy\ProphecyPlugin;

return function(EventEmitterInterface $emitter) {
 $plugin = new ProphecyPlugin($emitter);
};

Registering this plugin will add a ProphecyScope as a child scope to all of your tests. This will allow you to get a prophet object in all of your tests.

<?php
describe('Bird', function() {
 it('should fly', function() {
 $mock = $this->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.

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, you can mix the ProphecyScope provided by this plugin on a test by test, or suite by suite basis.

<?php
use Peridot\Plugin\Prophecy\ProphecyScope;

describe('Bird', function() {
 //here we manually mixin the http kernel scope
 $scope = new ProphecyScope();
 $this->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/