定制 peridot-php/peridot-httpkernel-plugin 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

peridot-php/peridot-httpkernel-plugin

最新稳定版本:1.1.0

Composer 安装命令:

composer require peridot-php/peridot-httpkernel-plugin

包简介

A Peridot plugin to simplify testing HttpKernel applications

README 文档

README

Build Status HHVM Status

Easily test HttpKernel applications with Peridot.

Some HttpKernel based frameworks:

##Usage

We recommend installing this plugin to your project via composer:

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

You can register the plugin via your peridot.php file.

<?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:

<?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à!

Don't want a client in all of your tests? No problem.

###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.

<?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.

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

Your tests now become:

<?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.

To test examples that are using the plugin, run the following:

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

To test examples that are manually adding the scope in, run this:

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

##Running plugin tests

$ vendor/bin/peridot specs/

统计信息

  • 总下载量: 7.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固