承接 mcustiel/codeception-http-mock 相关项目开发

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

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

mcustiel/codeception-http-mock

最新稳定版本:v0.7

Composer 安装命令:

composer require mcustiel/codeception-http-mock

包简介

Extension for HTTP Mock.

README 文档

README

This Codeception Extension allows developers and testers to use HttpMock to mock external services when running codeception tests.

codeception-http-mock runs an instance of http-mock before your tests run so they can mock external services. After the tests are finished it will close the connection and turn http-mock off.

See also

Note

http-mock is a nice application but it is very simple and lacks a lot of functionality. If you need a more complete application to mock and stub remote services, please give Phiremock a try. Phiremock also has a nice codeception extension.

Installation

Composer:

This project is published in packagist, so you just need to add it as a dependency in your composer.json:

    "require": {
        // ...
        "mcustiel/codeception-http-mock": "*"
    }

If you want to access directly to this repo, adding this to your composer.json should be enough:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/mcustiel/codeception-http-mock"
        }
    ],
    "require": {
        "mcustiel/codeception-http-mock": "dev-master"
    }
}

Or just download the release and include it in your path.

Configuration Example

Extension

# codeception.yml
extensions:
    enabled:
        - Codeception\Extension\HttpMock
    config:
        Codeception\Extension\HttpMock:
            port: 18080 # defaults to http-mock default port
            host: name.for.my.server # defaults to http-mock default host

Module

# acceptance.yml
modules:
    enabled:
        - HttpMock

How to use

Prepare your application

First of all, configure your application so when it is being tested it will replace its external services with http-mock. For instance, if you make some requests to a REST service located under http://your.rest.interface, replace that url in configuration with the host yoy set up in http-mock extension configuration.

Write your tests

// YourCest.php
class YourCest extends \Codeception\TestCase\Test
{
    // tests
    public function tryToTest(\AcceptanceTester $I)
    {
        $I->expectRequest()->when()
                ->methodIs('GET')
                ->pathIs('/foo')
            ->then()
                ->body('mocked body')
            ->end();
        $I->doNotExpectAnyOtherRequest();
        $response = file_get_contents('http://localhost:28080/foo');
        $I->assertEquals('mocked body', $response);
    }
}

统计信息

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

GitHub 信息

  • Stars: 14
  • Watchers: 3
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2015-11-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固