2017 © Pedro Peláez
 

library peridot-prophecy-plugin

Inject prophecy mocks into your Peridot tests

image

peridot-php/peridot-prophecy-plugin

Inject prophecy mocks into your Peridot tests

  • Tuesday, January 6, 2015
  • by brianium
  • Repository
  • 4 Watchers
  • 4 Stars
  • 30,924 Installations
  • PHP
  • 13 Dependents
  • 1 Suggesters
  • 4 Forks
  • 2 Open issues
  • 3 Versions
  • 8 % Grown

The README.md

Peridot Prophecy Plugin

Build Status HHVM Status, (*1)

Use Peridot with the amazing mocking framework Prophecy, (*2)

Usage

We recommend installing this plugin to your project via composer:, (*3)

$ composer require --dev peridot-php/peridot-prophecy-plugin:~1.0

You can register the plugin via your peridot.php file., (*4)

<?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., (*5)

<?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., (*6)

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., (*7)

<?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:, (*8)

$ vendor/bin/peridot example/bird.spec.php

Running plugin tests

$ vendor/bin/peridot specs/

The Versions

06/01 2015

dev-master

9999999-dev

Inject prophecy mocks into your Peridot tests

  Sources   Download

MIT

The Requires

 

25/11 2014

1.1.0

1.1.0.0

Inject prophecy mocks into your Peridot tests

  Sources   Download

MIT

The Requires

 

05/11 2014

1.0.0

1.0.0.0

Inject prophecy mocks into your Peridot tests

  Sources   Download

MIT

The Requires