PHPackages                             alperakgun/wp\_nock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. alperakgun/wp\_nock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

alperakgun/wp\_nock
===================

WP\_Http server mocking library for PHP/WordPress

0.6.1(6y ago)04.7kGPL-2.0-or-laterPHPPHP &gt;=5.3

Since Jul 22Pushed 6y agoCompare

[ Source](https://github.com/alperakgun/wp_nock)[ Packagist](https://packagist.org/packages/alperakgun/wp_nock)[ RSS](/packages/alperakgun-wp-nock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (11)Used By (0)

wp\_nock
========

[](#wp_nock)

WP\_Http server mocking library for PHP/WordPress inspired by the nock JavaScript library.

Usage
-----

[](#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
------------

[](#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
-------

[](#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
------------------

[](#were-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
-------

[](#license)

wp\_nock is licensed under [GNU General Public License v2 (or later)](../LICENSE.md).

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](http://www.gnu.org/licenses/license-list.en.html#GPLCompatibleLicenses), note that the Apache 2.0 license is *not* compatible.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

10

Last Release

2480d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/598667?v=4)[Alper Akgun](/maintainers/alperakgun)[@alperakgun](https://github.com/alperakgun)

---

Top Contributors

[![alperakgun](https://avatars.githubusercontent.com/u/598667?v=4)](https://github.com/alperakgun "alperakgun (19 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/alperakgun-wp-nock/health.svg)

```
[![Health](https://phpackages.com/badges/alperakgun-wp-nock/health.svg)](https://phpackages.com/packages/alperakgun-wp-nock)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M679](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M571](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.0k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
