apsconnect/connect-quickstart-template 问题修复 & 功能扩展

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

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

apsconnect/connect-quickstart-template

Composer 安装命令:

composer create-project apsconnect/connect-quickstart-template

包简介

APS Connect QuickStart Template

README 文档

README

The Connect SDK Template for php provides developers an complete skeleton to start their automation project using the Connect Fulfillment API together with the Connect SDK for PHP.

Requirements

In order to use this template you will need an environment capable to run PHP scripts, any version starting PHP 5.6 is supported. Additionally please ensure that composer it's functional.

Installation

You can download the quick start template with Composer create-project command in your terminal:

composer create-project --prefer-dist apsconnect/connect-quickstart-template project-name

Once you have the skeleton project ready you can start developing your custom code in app/ProductFulfillment.php file in the processRequest() method.

<?php

namespace App;

/**
 * Class ProductFulfillment
 * @package App
 */
class ProductFulfillment extends \Connect\FulfillmentAutomation
{

    /**
     * Process each pending request
     * @param \Connect\Request $request
     */
    public function processRequest($request)
    {
        // TODO: Implement processRequest() method.
    }

    /**
     * Run the Product Fulfillment Request Processor
     * @return bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function run()
    {
        try {

            /**
             * run the application in custom context, any error
             * handling customization should be done here
             */
            $this->process();
            return true;

        } catch (\Exception $e) {

            $this->logger->error($e->getMessage());
            if (is_callable([$this->logger, 'dump'])) {
                $this->logger->dump();
            }
        }

        return false;
    }
}

Testing your project

Test the ProductFulfillment class is quite easy, you just need to create your tests in tests/Feature/ directory by default the skeleton have some common tests.

Mocking the FulFillment API calls

To mock the fulfillment API, and with that test like if a request is retrived, you only have to create a valid json file with the response that you want in the tests/Feature/ directory with the name YOUR-TEST-NAME.http.json where YOUR-TEST-NAME is the name of the test file in where you want to use that fake response, for example:

  • ProcessSkipTest.http.json will be injected in ProcessSkipTest.php test.
  • RunAndFailTest.http.json will be injected in RunAndFailTest.php test.

Mocking other services

The skeleton also provides a easy way to mock other services, for this you only need to create a new service provider in tests/Providers, this new service provider MUST extends the MockServiceProvider. Inside this file you should configure your mocked service using the static property $scope to retrieve any auxiliary file like a fake json.

<?php

namespace Test\Providers;

use Pimple\Container;

/**
 * Class HttpServiceProvider
 * @package Test\Unit\Runtime\Providers
 */
class HttpServiceProvider extends MockServiceProvider
{
    public function register(Container $container)
    {
        $content = '[]';
        $fakeRequestFile = dirname(__DIR__) . '/Feature/' . self::$scope . '.json';
        if (is_readable($fakeRequestFile)) {
            $content = trim(file_get_contents($fakeRequestFile));
        }

        $body = \Mockery::mock('\Psr\Http\Message\StreamInterface');
        $body->shouldReceive('getContents')
            ->andReturn($content);

        $response = \Mockery::mock('\Psr\Http\Message\ResponseInterface');
        $response->shouldReceive('getStatusCode')
            ->andReturn(200);

        $response->shouldReceive('getBody')
            ->andReturn($body);

        $client = \Mockery::mock('GuzzleHttp\ClientInterface');
        $client->shouldReceive('request')
            ->withAnyArgs()
            ->andReturn($response);

        return $client;
    }
}

Finally you need to register your mocked service in the $providers property of tests/TestCase file.

    /**
     * List of Mocked Service Providers
     * @var MockServiceProvider[]
     */
    protected $providers = [
        'logger' => '\Test\Providers\LoggerServiceProvider',
        'http' => '\Test\Providers\HttpServiceProvider'
    ];

The scope id has the format YOUR-TEST-NAME.serviceId.json where:

  • YOUR-TEST-NAME is the filename of the test that is running.
  • serviceId is the id of the service for example logger is the logger service id and http is the default Http service for the FulFillment API.

apsconnect/connect-quickstart-template 适用场景与选型建议

apsconnect/connect-quickstart-template 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 149 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 apsconnect/connect-quickstart-template 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2018-10-15