PHP code example of syde / wp-phpunit-integration

1. Go to this page and download the library: Download syde/wp-phpunit-integration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

syde / wp-phpunit-integration example snippets




declare(strict_types=1);

use Syde\WpPhpUnitIntegration\Bootstrap;

$packagePath = dirname(__DIR__, 2);
$vendorPath = "{$packagePath}/vendor";

if (!realpath($vendorPath)) {
    die('Please install via Composer before running tests.');
}


use Syde\WpPhpUnitIntegration\Bootstrap;
use Syde\WpPhpUnitIntegration\BootstrapLifecycle;
use Syde\WpPhpUnitIntegration\WpTestEnv;

Bootstrap::init(
    $packagePath,
    new BootstrapLifecycle(
        setup: function (): void {
            // Run some setup tasks before the default ones.
            
            WpTestEnv::setup();
        },
        load: function () use ($packagePath): void {
            // Omit the default WpTestEnv::load() to use your own custom logic.
            
            

WpTestEnv::runWpCliCommand([
    'plugin',
    'activate',
    'woocommerce',
]);

WpTestEnv::addEarlyFilter(
    'wonolog.buffer-handler',
    function (): bool {
        return false;
    },
);
xml
<phpunit
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
        bootstrap="tests/phpunit/bootstrap-integration.php">
    <testsuites>
        <testsuite name="integration">
            <directory>tests/phpunit/Integration</directory>
        </testsuite>
    </testsuites>
</phpunit>
yaml
name: PHP Integration Testing
on:
    pull_request:
        paths:
            - '**.php'
            - 'composer.*'
            - 'phpunit.*'
jobs:
    tests-unit-php:
        uses: inpsyde/reusable-workflows/.github/workflows/tests-unit-php.yml@main
        secrets:
            COMPOSER_AUTH_JSON: '${{secrets.PACKAGIST_AUTH_JSON}}'
        with:
            PHPUNIT_ARGS: '-c phpunit-integration.xml.dist --coverage-text'
            PHP_VERSION: '8.2'