承接 karmabunny/visor 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

karmabunny/visor

Composer 安装命令:

composer require karmabunny/visor

包简介

A supervisor for PHP-CLI servers

README 文档

README

This is a small utility to wrap the built-in PHP cli-server feature.

There are two three parts to this library:

  1. An abstract 'server' instance that will manage the lifecycle of any cli-server compatible script.

  2. An 'echo server' implementation that, uh, echos. What you say at it, it says back.

  3. A 'mock server' implementation that will reply with defined responses.

Install

Using Composer:

composer require karmabunny/visor

Usage

This is ideal for creating small integration tests with a local application or creating mock servers and testing HTTP libraries.

Server Instance

use karmabunny\visor\Server;
use PHPUnit\Framework\TestCase;

/**
 * The application bootstrap is found at: 'index.php'. This must be capable
 * of accepting cli-server requests.
 */
class MyServer extends Server
{
    protected function getTargetScript(): string
    {
        return __DIR__ . '/index.php';
    }
}

class MyServerTest extends TestCase
{
    public function testThings()
    {
        // This create a server at localhost:8080
        $server = MyServer::create();

        // One can then perform tests against the application.
        $res = file_get_contents($server->getHostUrl() . '/health');
        $this->assertEquals('ok', $res);
    }
}

Echo Server

use karmabunny\visor\EchoServer;
use PHPUnit\Framework\TestCase;

class ClientTest extends TestCase
{
    public function testThings()
    {
        // This creates an echo server at localhost:8080
        $server = EchoServer::create();

        // Imagine this to be some kind of client that hits a remote
        // server of sorts.
        $res = file_get_contents($server->getHostUrl() . '/hello?test=123');

        // Not only is 'res' a JSON body of the payload, the payload is
        // also accessible from the the server instance.

        $payload = $server->getLatestPayload();

        $this->assertEquals('/hello', $payload['path']);
        $this->assertEquals(['test' => '123'], $payload['query']);
    }
}

Mock Server

use karmabunny\visor\MockServer;
use PHPUnit\Framework\TestCase;

class FakeTest extends TestCase
{
    public function testThings()
    {
        // This creates a mock server at localhost:8080
        $server = MockServer::create();

        $server->setMock('/mock-this', [], 'a fake response');
        $res = file_get_contents($server->getHostUrl() . '/mock-this');

        $payload = $server->getLatestPayload();

        $this->assertEquals('/mock-this', $payload['path']);
        $this->assertEquals('a fake response', $res);
    }
}

Config

name - default
host a binding address localhost
port HTTP port number 8080
wait pause until the server is ready (milliseconds) 100
path working directory of the server -

By default the log file path is randomised in a temporary system directory.

Log files

The server emit a log file to aid testing and debugging.

This includes logs from the server process, the application, and visor itself.

Server that extend the base class can use Server::log(). Applications can use the native error_log().

Mock + Echo Server

The included implementations will log additional data also.

  • latest.json is the request payload stored for introspection. Used by getLastPayload().
  • mocks.json is a store of response objects for the mock server.

Echo (+ Mock) payloads

Both Mock and Echo servers store the request object in a specific format.

Note that the body is unchanged, if you've sent a JSON or URL payload this will be 'as is' in it's encoded string form.

  • path - the request path, without the query string
  • query - an key-value array, from parse_str()
  • method - always uppercase
  • headers - key-value pairs, keys are lowercase
  • body - string body, from php://input

The JSON-encoded log file looks like this:

{
    "path": "/hello-world.json",
    "query": {
        "rando1": "7bb1166f0cf451cc3eb4cbb977ad932f674aac6c"
    },
    "method": "POST",
    "headers": {
        "host": "localhost:8080",
        "connection": "close",
        "content-length": "53",
        "content-type": "application/json"
    },
    "body": "{\"rando2\":\"267f3bf70d8939c2c7e77d1f8ea164e1df071bba\"}"
}

karmabunny/visor 适用场景与选型建议

karmabunny/visor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.02k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 karmabunny/visor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 karmabunny/visor 我们能提供哪些服务?
定制开发 / 二次开发

基于 karmabunny/visor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-30