2017 © Pedro PelĂĄez
 

library peridot-httpkernel-plugin

A Peridot plugin to simplify testing HttpKernel applications

image

peridot-php/peridot-httpkernel-plugin

A Peridot plugin to simplify testing HttpKernel applications

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

The README.md

Peridot HttpKernel Plugin

Build Status HHVM Status, (*1)

Easily test HttpKernel applications with Peridot., (*2)

Some HttpKernel based frameworks:, (*3)

  • Silex
  • [Laravel] (http://laravel.com/)
  • [Symfony2] (http://symfony.com/what-is-symfony)

Usage

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

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

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

<?php
use Evenement\EventEmitterInterface;
use Peridot\Plugin\HttpKernel\HttpKernelPlugin;

return function(EventEmitterInterface $emitter) {
    //the second argument expects an HttpKernelInterface or a function that returns one
    HttpKernelPlugin::register($emitter, include __DIR__ . '/app.php');
};

By registering the plugin, your Peridot tests will now have a $client property available:, (*6)

<?php
describe('Api', function() {
    describe('/info', function() {
        it('should return info about Peridot', function() {
            $this->client->request('GET', '/info');
            $response = $this->client->getResponse();
            $info = json_decode($response->getContent());
            assert($info->project == "Peridot", "project should be Peridot");
            assert($info->description == "Event driven testing framework", "description should describe Peridot");
            assert($info->styles == "BDD, TDD", "styles should be BDD, TDD");
        });
    });

    describe('/author', function() {
        it('should return info about the author', function() {
            $this->client->request('GET', '/author');
            $author = json_decode($this->client->getResponse()->getContent());
            assert($author->name == "Brian Scaturro", "author name should be on response");
            assert($author->likes == "pizza", "author should like pizza");
        });
    });
});

VoilĂ !, (*7)

Don't want a client in all of your tests? No problem., (*8)

Using on a test by test basis

Like any other peridot scope, you can mix the HttpKernelScope provided by this plugin on a test by test, or suite by suite basis., (*9)

<?php
use Peridot\Plugin\HttpKernel\HttpKernelScope;

describe('Api', function() {

    //here we manually mixin the http kernel scope
    $scope = new HttpKernelScope(include __DIR__ . '/../app.php');
    $this->peridotAddChildScope($scope);

    describe('/author', function() {
        it('should return info about the author', function() {
            $this->client->request('GET', '/author');
            $author = json_decode($this->client->getResponse()->getContent());
            assert($author->name == "Brian Scaturro", "author name should be on response");
            assert($author->likes == "pizza", "author should like pizza");
        });
    });
});

Configuring the client property name

If $this->client is a little too generic for your tastes, both the scope and plugin take an optional last argument that allows you to you set this., (*10)

HttpKernelPlugin::register($emitter, include __DIR__ . '/app.php', "browser");
$scope = new HttpKernelScope($application, "browser");

Your tests now become:, (*11)

<?php
use Peridot\Plugin\HttpKernel\HttpKernelScope;

describe('Api', function() {

    describe('/author', function() {
        it('should return info about the author', function() {
            $this->browser->request('GET', '/author');
            $author = json_decode($this->browser->getResponse()->getContent());
            assert($author->name == "Brian Scaturro", "author name should be on response");
            assert($author->likes == "pizza", "author should like pizza");
        });
    });
});

Example specs

This repo comes with a sample Silex application that is tested with this plugin., (*12)

To test examples that are using the plugin, run the following:, (*13)

$ vendor/bin/peridot -c app/peridot.php app/specs/api.spec.php

To test examples that are manually adding the scope in, run this:, (*14)

$ vendor/bin/peridot app/specs/no-plugin.spec.php

Running plugin tests

$ vendor/bin/peridot specs/

The Versions

06/01 2015

dev-master

9999999-dev

A Peridot plugin to simplify testing HttpKernel applications

  Sources   Download

MIT

The Requires

 

The Development Requires

24/10 2014

1.1.0

1.1.0.0

A Peridot plugin to simplify testing HttpKernel applications

  Sources   Download

MIT

The Requires

 

The Development Requires

23/10 2014

1.0.0

1.0.0.0

A Peridot plugin to simplify testing silex applications

  Sources   Download

MIT

The Requires

 

The Development Requires