incraigulous/request-hooks 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

incraigulous/request-hooks

Composer 安装命令:

composer require incraigulous/request-hooks

包简介

Modify application state for feature testing by using query parameters.

README 文档

README

Modify Laravel application state for browser testing by using query parameters.

How it works

Create a hook
Here's an example hook class that logs in a user if the test_login query string is set. That means if your feature testing, anytime you call a url like yourapp.dev/dashboard?test_login=true, the user will be logged in before the request is handled.

<?php

namespace App\RequestHooks;

use Illuminate\Http\Request;
use App\User;
use Incraigulous\RequestHooks\Contracts\RequestHook;

class Login implements RequestHook
{
    /**
     * @var Request
     */
    private $request;

    function __construct(Request $request)
    {
        $this->request = $request;
    }

    /**
     * Should the hook fire?
     * @return bool
     */
    public function shouldHandle()
    {
        if (!$this->request->test_login) return false;
        if (auth()->check()) return false;
        return true;
    }

    /**
     * Do whatever action the hook does
     */
    public function handle()
    {
        $user = user::first();
        auth()->login($user);
    }
}

Register your hook
in config/requestHooks.php:

return [
    /**
     * Which app.env environments should be considered testing environments by the request-hooks test middleware?
     */
    'testEnvironments' => ['development', 'testing', 'staging', 'local'],

    /**
     * Register your request hooks
     */
    'hooks' => [
        \App\RequestHooks\Login::class
    ]
];

Installation

composer require incraigulous/request-hooks

Register the service provider:

'providers' => [
   ...,
   Incraigulous\RequestHooks\RequestHooksServiceProvider::class,
   ,,.,
]

Register the middleware as global moddleware in the http kernel:

$middleware => [
   ...,
   Incraigulous\RequestHooks\TestingMiddleware::class
   ,,.,
]

Alternatively, you could extend Incraigulous\RequestHooks\TestingMiddleware or write your own if you need custom functionality.

Configuration

testEnvironments: An array of environment names (see the app.env configuration setting) that hooks should fire in.
hooks: Register your hook classes.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固