WordPress core test suite function and class declaration stubs for static analysis by PHPStan

Overview

WordPress Core Test Suite Stubs

This package provides stub declarations for the WordPress Core Test Suite functions, classes and interfaces.

These stubs can help plugin and theme developers leverage static analysis tools like PHPStan, when writing tests for WordPress plugins, themes, and core.

Stubs are generated directly from the source using giacocorsiglia/stubs-generator.

Requirements

  • PHP >=7.1

Installation

Require this package as a development dependency with Composer.

composer require --dev php-stubs/wordpress-tests-stubs

Alternatively you may download wordpress-tests-stubs.php directly.

Usage in PHPStan

Include all stubs in PHPStan configuration file.

parameters:
    bootstrapFiles:
        - %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php
        - %rootDir%/../../php-stubs/wordpress-tests-stubs/wordpress-tests-stubs.php
You might also like...
🚀WordPress Plugin Boilerplate using modern web techs like TypeScript, SASS, and so on... on top of a local development environment with Docker and predefined GitLab CI for continous integration and deployment!
🚀WordPress Plugin Boilerplate using modern web techs like TypeScript, SASS, and so on... on top of a local development environment with Docker and predefined GitLab CI for continous integration and deployment!

WP React Starter: WordPress React Boilerplate DEPRECATED: WP React Starter was a "research project" of devowl.io for the development of our WordPress

Scaffold plugin for creating and managing Blocks, Block Patterns, Block Styles and Block Editor Sidebars in the WordPress Block Editor (aka Gutenberg).
Scaffold plugin for creating and managing Blocks, Block Patterns, Block Styles and Block Editor Sidebars in the WordPress Block Editor (aka Gutenberg).

WordPress Block Editor Scaffold This project is a template repo for developing WordPress Blocks, Block Patterns, Block Styles and Block Editor Sidebar

Generates a list of WordPress actions and filters from code and outputs them as JSON

wp-hooks-generator Generates a JSON representation of the WordPress actions and filters in your code. Can be used with WordPress plugins, themes, and

Beauty and simple Wordpress video player plugin. Powerfull and lite in use.
Beauty and simple Wordpress video player plugin. Powerfull and lite in use.

Sonic Spectre Video Player Beauty and simple Wordpress video player plugin. Powerfull and lite in use. Quick Start: Download plugin from this repo and

Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation
Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation

Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation. Some of

Create custom WordPress routes and redirects, restrict access by roles and/or capabilities. Routes made simple
Create custom WordPress routes and redirects, restrict access by roles and/or capabilities. Routes made simple

Create custom WordPress routes and redirects, restrict access by roles and/or capabilities. Routes made simple

Documents WordPress Classic Editor integration points and their Gutenberg equivalents

Gutenberg Migration Guide This repository documents WordPress Classic Editor customization points and their Gutenberg equivalents (if such exist). Its

The easiest way to develop and release Gutenberg blocks (components) for WordPress

Contents Install Comparison with competition Future Plans Usage Creating a Block Install npm install gutenblock -g This is a Gutenberg plugin creator

Create WordPress themes with beautiful OOP code and the Twig Template Engine
Create WordPress themes with beautiful OOP code and the Twig Template Engine

By Jared Novack (@jarednova), Lukas Gächter (@lgaechter), Pascal Knecht (@pascalknecht), Maciej Palmowski (@palmiak_fp), Coby Tamayo (@cobytamayo), Up

Comments
  • Include WP Core test suite tooling in stubs?

    Include WP Core test suite tooling in stubs?

    I'm not sure if this should be handled here or via a separate stub repo, but I'm wondering if it would make sense to create a stub for the WordPress core test suite codebase.

    The main use-case here would be for developers writing code that extends the WP_UnitTestCase class — the WordPress instance itself will generally be installed to a tmp/ directory (or /srv/www/wordpress-develop in environments like VVV), putting it outside of the typical project scope. As a result, tools like Intelephense which, as best I can tell, uses this library for its WordPress stubs, flag a lot of standard PHPUnit code as error-filled because it doesn't know that WP_UnitTestCase extends PHPUnit\Framework\TestCase:

    Intelephense errors related to undefined PHPUnit methods

    Granted this is a bit of a niche use-case, but in the interest of encouraging better testing practices in WordPress I think it's worth a discussion :smile:.

    opened by stevegrunwell 4
  • Executing stubs fail because the lack of PHPUnit

    Executing stubs fail because the lack of PHPUnit

    The last test step is to execute stubs. php -f wordpress-tests-stubs.php It fails. https://app.travis-ci.com/github/php-stubs/wordpress-tests-stubs./jobs/547182050

    @stevegrunwell What PHPUnit versions do WordPress people use? https://phpunit.de/supported-versions.html

    PHP 7.4 PHP 7.3 PHP 7.2 PHP 7.1

    opened by szepeviktor 3
  • Update the PHPStan usage documentation

    Update the PHPStan usage documentation

    In order to properly discover symbols, the stub files should be added to scanFiles (e.g. "consider the definitions from these files"), not bootstrapFiles (which actually executes the files).

    Adding the stubs to bootstrapFiles will cause errors like the following:

    Fatal error: Cannot redeclare wp_cache_add() (previously declared in /path/to/project/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php:88572) in /path/to/project/vendor/php-stubs/wordpress-tests-stubs/wordpress-tests-stubs.php on line 4319

    opened by stevegrunwell 2
A PHP Class for creating Wordpress Custom Post Types easily

N.B I've released an updated version of the project to a new repository, PostTypes. WP Custom Post Type Class v1.4 A single class to help you build mo

Joe Grainger 412 Nov 25, 2022
A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities.

Awesome WordPress A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities. Inspired by bayand

Dropndot Limited 91 Dec 26, 2022
A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings.

Suspend WP A WordPress plugin to suspend WordPress sites automagically. Simple and lightweight, no annoying ads and fancy settings. ?? Demo (coming so

Waren Gonzaga 3 Nov 15, 2021
Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library.

Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library. Import Jamendo playlists with tracks in WordPress posts.

Pierre Saikali 3 Dec 7, 2022
The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone.

Pronamic WordPress Basecone The Pronamic WordPress Basecone plugin allows you to connect your WordPress installation to Basecone. Table of contents Au

Pronamic 1 Oct 19, 2021
Twenty Twenty-Two, the default WordPress theme that will launch with WordPress 5.9.

Twenty Twenty-Two Welcome to the development repository for the default theme that will launch with WordPress 5.9. About Twenty Twenty-Two is designed

null 414 Nov 28, 2022
Easy handle APlayer on WordPress. A shortcode for WordPress to using APlayer.

Description Easy handle APlayer on WordPress. A shortcode for WordPress to using APlayer. Support [audio] tag, compatible with AMP. Requirement WordPr

Karl Chen 24 Nov 3, 2022
WordPress plugin that lets you use Discourse as the community engine for a WordPress blog

WP Discourse Note: the wp-discourse plugin requires >= PHP-5.4.0. The WP Discourse plugin acts as an interface between your WordPress site and your Di

Discourse 497 Dec 10, 2022
WordPress & TypeScript. Simple starter template for WordPress projects

WordPress & TypeScript. Simple starter template for WordPress projects that want to use TypeScript in combination with @wordpress/scripts

Make it WorkPress 11 Sep 27, 2022
A PHP client for Wordpress websites that closely implement the XML-RPC WordPress API

Wordpress XML-RPC PHP Client A PHP client for Wordpress websites that closely implement the XML-RPC WordPress API Created by Hieu Le MIT licensed. Cur

Hieu Le 112 Nov 10, 2022