承接 alperakgun/wp_nock 相关项目开发

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

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

alperakgun/wp_nock

Composer 安装命令:

composer require alperakgun/wp_nock

包简介

WP_Http server mocking library for PHP/WordPress

README 文档

README

WP_Http server mocking library for PHP/WordPress inspired by the nock JavaScript library.

Usage

You can install wp_nock as a development composer package dependencies.

$ composer require --dev alperakgun/wp_nock

Require it in your tests/bootstrap.php

require dirname( dirname( __FILE__ ) ) . '/vendor/alperakgun/wp_nock/src/class-wp-nock.php';

Using PHPUnit, you can test any code which uses

  • WP_Http classes such as wp_remote_get, wp_remote_request,wp_remote_post.
  • Or wp_redirect, wp_safe_redirect etc.
use Alperakgun\Testing\WP_Nock;
use Alperakgun\Testing\WP_Nock_Exception;

class Test_My_Cool_WordPress_Plugin extends WP_UnitTestCase {

	const TEST_URL = 'https://www.wordpress.com/test';
  
  # Testing wp_remote_get, or wp_remote_post is similar
	public function test_wp_nock_wp_remote_get() {
		$nock = new WP_Nock();
		$nock->set_up();

		$nock->get(
			self::TEST_URL,
			array(
				'response' => array(
					'code' => 200,
				),
				'body'     => '{"foo":"bar"}',
			)
		);

		$result = wp_remote_get( self::TEST_URL );
		$this->assertSame( $result['response']['code'], 200 );
		$this->assertSame( $result['body'], '{"foo":"bar"}' );

		$nock->tear_down();
	}

Testing the wp_redirect requires a callback

	public function test_wp_nock_wp_redirect_with_callback() {
		$nock = new WP_Nock();
		$nock->set_up();

		$nock->redirect(
			self::TEST_URL,
			function( $payload ) {
				$this->assertSame( $payload['location'], self::TEST_URL );
				return false;
			}
		);

		wp_redirect( self::TEST_URL );
		$nock->tear_down();
	}

Another way of testing the wp_redirect requires an exception

	public function test_wp_nock_wp_redirect() {
		$nock = new WP_Nock();
		$nock->set_up();

		$nock->redirect( self::TEST_URL );
		try {

			wp_redirect( self::TEST_URL );

		} catch ( WP_Nock_Exception $ex ) {

			$payload = $ex->get_payload();
			$this->assertSame( $payload['location'], self::TEST_URL );
		}

		$nock->tear_down();
	}
  
}

Contributing

We welcome contributions. Please don’t hesitate to send a pull request, send a suggestion, file a bug, or just ask a question. We promise we’ll be nice.

For PHP, we use PHP Code Sniffer with the WordPress coding standards.

# Run this once at the beginning to set up some test instrumentation.
composer run lint

# Run this whenever you start testing to start Docker containers
composer run lint:fix

Testing

We like tests :) Make sure you run them before starting out!

PHP unit tests can be run with:

# Run this once at the very beginning to set up some test instrumentation.
composer run test:setup

# Run this whenever you start testing to start Docker containers
composer run test:run-docker

# Run PHP unit tests
composer run test

We’re Here To Help

We encourage you to ask for help at any point. We want your first experience with wp_nock to be a good one, so don’t be shy. If you’re wondering why something is the way it is, or how a decision was made, you can tag issues with [Type] Question or prefix them with “Question:”.

License

wp_nock is licensed under GNU General Public License v2 (or later).

All materials contributed should be compatible with the GPLv2. This means that if you own the material, you agree to license it under the GPLv2 license. If you are contributing code that is not your own, such as adding a component from another Open Source project, or adding an npm package, you need to make sure you follow these steps:

  1. Check that the code has a license. If you can't find one, you can try to contact the original author and get permission to use, or ask them to release under a compatible Open Source license.
  2. Check the license is compatible with GPLv2, note that the Apache 2.0 license is not compatible.

alperakgun/wp_nock 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2019-07-21