From bb7102db5a81f8a77a13ee4e729c099c7c8eeb5c Mon Sep 17 00:00:00 2001 From: Louis Wolmarans Date: Thu, 27 Nov 2025 22:11:28 +0200 Subject: [PATCH 1/4] setup for phpunit tests --- .github/workflows/phpunit-test.yml | 92 ++ .github/workflows/phpunit.yml | 79 ++ .gitignore | 4 + package.json | 2 + src/composer.json | 4 +- src/composer.lock | 1970 +++++++++++++++++++++++++++- tests/README.md | 79 ++ tests/bootstrap.php | 40 +- tests/install-wp-tests.sh | 170 +++ 9 files changed, 2381 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/phpunit-test.yml create mode 100644 .github/workflows/phpunit.yml create mode 100644 tests/README.md create mode 100755 tests/install-wp-tests.sh diff --git a/.github/workflows/phpunit-test.yml b/.github/workflows/phpunit-test.yml new file mode 100644 index 00000000..697c4296 --- /dev/null +++ b/.github/workflows/phpunit-test.yml @@ -0,0 +1,92 @@ +name: PHPUnit Test Runner + +on: + workflow_call: + inputs: + php-version: + required: false + type: string + default: '8.1' + description: 'PHP version to test against' + +jobs: + phpunit-test: + name: PHPUnit tests (PHP ${{ inputs.php-version }}) + runs-on: ubuntu-22.04 + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: wordpress_test + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php-version }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql + coverage: none + + - name: Compute dependency hash + id: deps-hash + run: | + set -euo pipefail + tmpfile=$(mktemp) + if [ -f "src/composer.lock" ]; then + cat "src/composer.lock" >> "$tmpfile" + fi + if [ -s "$tmpfile" ]; then + deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8) + else + deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8) + fi + echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT" + + - name: Get Composer cache + id: composer-cache + uses: actions/cache/restore@v4 + with: + path: src/vendor + key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }} + restore-keys: | + ${{ runner.os }}-php-${{ inputs.php-version }}-composer- + + - name: Install Composer dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: | + cd src + composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Save Composer cache + if: steps.composer-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: src/vendor + key: ${{ runner.os }}-php-${{ inputs.php-version }}-composer-${{ steps.deps-hash.outputs.deps_hash }} + + - name: Install WordPress test suite + run: | + bash tests/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 latest true + + - name: Run PHPUnit tests + run: | + cd src + vendor/bin/phpunit -c ../phpunit.xml --testdox + + - uses: actions/upload-artifact@v4 + if: always() + with: + name: phpunit-test-results-php-${{ inputs.php-version }} + path: | + .phpunit.result.cache + if-no-files-found: ignore + retention-days: 2 + diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 00000000..ad07ee2f --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,79 @@ +name: "(Test): PHPUnit" + +on: + pull_request: + types: [labeled, synchronize, opened, reopened] + push: + branches: + - 'core' + - 'pro' + paths-ignore: + - '**.md' + - '**.txt' + - '.gitignore' + - 'docs/**' + workflow_dispatch: + +permissions: + contents: read + pull-requests: read + actions: read + +concurrency: + group: phpunit-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + phpunit-php-7-4: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') + uses: ./.github/workflows/phpunit-test.yml + with: + php-version: '7.4' + + phpunit-php-8-0: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') + uses: ./.github/workflows/phpunit-test.yml + with: + php-version: '8.0' + + phpunit-php-8-1: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') + uses: ./.github/workflows/phpunit-test.yml + with: + php-version: '8.1' + + phpunit-php-8-2: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') + uses: ./.github/workflows/phpunit-test.yml + with: + php-version: '8.2' + + phpunit-php-8-3: + if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests') + uses: ./.github/workflows/phpunit-test.yml + with: + php-version: '8.3' + + test-result: + needs: [phpunit-php-7-4, phpunit-php-8-0, phpunit-php-8-1, phpunit-php-8-2, phpunit-php-8-3] + if: always() && (needs.phpunit-php-7-4.result != 'skipped' || needs.phpunit-php-8-0.result != 'skipped' || needs.phpunit-php-8-1.result != 'skipped' || needs.phpunit-php-8-2.result != 'skipped' || needs.phpunit-php-8-3.result != 'skipped') + runs-on: ubuntu-22.04 + name: PHPUnit - Test Results Summary + steps: + - name: Test status summary + run: | + echo "PHP 7.4: ${{ needs.phpunit-php-7-4.result }}" + echo "PHP 8.0: ${{ needs.phpunit-php-8-0.result }}" + echo "PHP 8.1: ${{ needs.phpunit-php-8-1.result }}" + echo "PHP 8.2: ${{ needs.phpunit-php-8-2.result }}" + echo "PHP 8.3: ${{ needs.phpunit-php-8-3.result }}" + + - name: Check overall status + if: | + (needs.phpunit-php-7-4.result != 'success' && needs.phpunit-php-7-4.result != 'skipped') || + (needs.phpunit-php-8-0.result != 'success' && needs.phpunit-php-8-0.result != 'skipped') || + (needs.phpunit-php-8-1.result != 'success' && needs.phpunit-php-8-1.result != 'skipped') || + (needs.phpunit-php-8-2.result != 'success' && needs.phpunit-php-8-2.result != 'skipped') || + (needs.phpunit-php-8-3.result != 'success' && needs.phpunit-php-8-3.result != 'skipped') + run: exit 1 + diff --git a/.gitignore b/.gitignore index 1c3b03cb..bf7f9418 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,10 @@ node_modules/ npm-debug.log .sass-cache/ +# PHPUnit +.phpunit.result.cache +/coverage/ + # Playwright playwright-report/ test-results/ diff --git a/package.json b/package.json index 2cd64ae5..fb95b25c 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "test": "tests" }, "scripts": { + "test:php": "cd src && vendor/bin/phpunit -c ../phpunit.xml", + "test:php:watch": "npm run test:php -- --testdox", "test:playwright": "playwright test -c tests/playwright/playwright.config.ts", "test:playwright:debug": "npm run test:playwright -- --debug", "test:playwright:ui": "npm run test:playwright -- --ui", diff --git a/src/composer.json b/src/composer.json index be43b794..2a10819a 100644 --- a/src/composer.json +++ b/src/composer.json @@ -37,7 +37,9 @@ "require-dev": { "wp-coding-standards/wpcs": "^3.1", "phpcompatibility/phpcompatibility-wp": "^2.1", - "dealerdirect/phpcodesniffer-composer-installer": "^1.0" + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "phpunit/phpunit": "^9.6", + "yoast/phpunit-polyfills": "^2.0" }, "config": { "platform": { diff --git a/src/composer.lock b/src/composer.lock index 56ee40d1..28f9004a 100644 --- a/src/composer.lock +++ b/src/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c322fb32f6db8844392d9f78341fcefb", + "content-hash": "1b291557f4b8130f2c07ad0bf3138d2b", "packages": [ { "name": "composer/installers", @@ -424,6 +424,312 @@ ], "time": "2025-11-11T04:32:07+00:00" }, + { + "name": "doctrine/instantiator", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9 || ^11", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.16 || ^1", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-phpunit": "^1", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.30 || ^5.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "https://ocramius.github.io/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.5.0" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "type": "tidelift" + } + ], + "time": "2022-12-30T00:15:36+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.13.4", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a", + "reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3 <3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.13.4" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2025-08-01T08:46:24+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v5.6.2", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "3a454ca033b9e06b63282ce19562e892747449bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/3a454ca033b9e06b63282ce19562e892747449bb", + "reference": "3a454ca033b9e06b63282ce19562e892747449bb", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-json": "*", + "ext-tokenizer": "*", + "php": ">=7.4" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v5.6.2" + }, + "time": "2025-10-21T19:32:17+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "54750ef60c58e43759730615a392c31c80e23176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, { "name": "phpcompatibility/php-compatibility", "version": "9.3.5", @@ -813,95 +1119,1586 @@ "time": "2025-11-11T00:17:56+00:00" }, { - "name": "squizlabs/php_codesniffer", - "version": "3.13.5", + "name": "phpunit/php-code-coverage", + "version": "9.2.32", "source": { "type": "git", - "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4" + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/0ca86845ce43291e8f5692c7356fccf3bcf02bf4", - "reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/85402a822d1ecf1db1096959413d35e1c37cf1a5", + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5", "shasum": "" }, "require": { - "ext-simplexml": "*", - "ext-tokenizer": "*", + "ext-dom": "*", + "ext-libxml": "*", "ext-xmlwriter": "*", - "php": ">=5.4.0" + "nikic/php-parser": "^4.19.1 || ^5.1.0", + "php": ">=7.3", + "phpunit/php-file-iterator": "^3.0.6", + "phpunit/php-text-template": "^2.0.4", + "sebastian/code-unit-reverse-lookup": "^2.0.3", + "sebastian/complexity": "^2.0.3", + "sebastian/environment": "^5.1.5", + "sebastian/lines-of-code": "^1.0.4", + "sebastian/version": "^3.0.2", + "theseer/tokenizer": "^1.2.3" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + "phpunit/phpunit": "^9.6" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" }, - "bin": [ - "bin/phpcbf", - "bin/phpcs" - ], "type": "library", + "extra": { + "branch-alias": { + "dev-main": "9.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], "authors": [ { - "name": "Greg Sherwood", - "role": "Former lead" - }, - { - "name": "Juliette Reinders Folmer", - "role": "Current lead" - }, - { - "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" } ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", "keywords": [ - "phpcs", - "standards", - "static analysis" + "coverage", + "testing", + "xunit" ], "support": { - "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", - "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", - "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", - "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.32" }, "funding": [ { - "url": "https://github.com/PHPCSStandards", - "type": "github" - }, - { - "url": "https://github.com/jrfnl", + "url": "https://github.com/sebastianbergmann", "type": "github" - }, - { - "url": "https://opencollective.com/php_codesniffer", - "type": "open_collective" - }, - { - "url": "https://thanks.dev/u/gh/phpcsstandards", - "type": "thanks_dev" } ], - "time": "2025-11-04T16:30:35+00:00" + "time": "2024-08-22T04:23:01+00:00" }, { - "name": "wp-coding-standards/wpcs", - "version": "3.2.0", + "name": "phpunit/php-file-iterator", + "version": "3.0.6", "source": { "type": "git", - "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "d2421de7cec3274ae622c22c744de9a62c7925af" + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/d2421de7cec3274ae622c22c744de9a62c7925af", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2021-12-02T12:48:52+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T05:58:55+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T05:33:50+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "5.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:16:10+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "9.6.29", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "9ecfec57835a5581bc888ea7e13b51eb55ab9dd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9ecfec57835a5581bc888ea7e13b51eb55ab9dd3", + "reference": "9ecfec57835a5581bc888ea7e13b51eb55ab9dd3", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.5.0 || ^2", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.13.4", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", + "php": ">=7.3", + "phpunit/php-code-coverage": "^9.2.32", + "phpunit/php-file-iterator": "^3.0.6", + "phpunit/php-invoker": "^3.1.1", + "phpunit/php-text-template": "^2.0.4", + "phpunit/php-timer": "^5.0.3", + "sebastian/cli-parser": "^1.0.2", + "sebastian/code-unit": "^1.0.8", + "sebastian/comparator": "^4.0.9", + "sebastian/diff": "^4.0.6", + "sebastian/environment": "^5.1.5", + "sebastian/exporter": "^4.0.8", + "sebastian/global-state": "^5.0.8", + "sebastian/object-enumerator": "^4.0.4", + "sebastian/resource-operations": "^3.0.4", + "sebastian/type": "^3.2.1", + "sebastian/version": "^3.0.2" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.6-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.29" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2025-09-24T06:29:11+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:27:43+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:08:54+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T05:30:19+00:00" + }, + { + "name": "sebastian/comparator", + "version": "4.0.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "67a2df3a62639eab2cc5906065e9805d4fd5dfc5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/67a2df3a62639eab2cc5906065e9805d4fd5dfc5", + "reference": "67a2df3a62639eab2cc5906065e9805d4fd5dfc5", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/diff": "^4.0", + "sebastian/exporter": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.9" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/comparator", + "type": "tidelift" + } + ], + "time": "2025-08-10T06:51:50+00:00" + }, + { + "name": "sebastian/complexity", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/25f207c40d62b8b7aa32f5ab026c53561964053a", + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.18 || ^5.0", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-12-22T06:19:30+00:00" + }, + { + "name": "sebastian/diff", + "version": "4.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-02T06:30:58+00:00" + }, + { + "name": "sebastian/environment", + "version": "5.1.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:03:51+00:00" + }, + { + "name": "sebastian/exporter", + "version": "4.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "14c6ba52f95a36c3d27c835d65efc7123c446e8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/14c6ba52f95a36c3d27c835d65efc7123c446e8c", + "reference": "14c6ba52f95a36c3d27c835d65efc7123c446e8c", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/exporter", + "type": "tidelift" + } + ], + "time": "2025-09-24T06:03:27+00:00" + }, + { + "name": "sebastian/global-state", + "version": "5.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "b6781316bdcd28260904e7cc18ec983d0d2ef4f6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/b6781316bdcd28260904e7cc18ec983d0d2ef4f6", + "reference": "b6781316bdcd28260904e7cc18ec983d0d2ef4f6", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/global-state", + "type": "tidelift" + } + ], + "time": "2025-08-10T07:10:35+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e1e4a170560925c26d424b6a03aed157e7dcc5c5", + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.18 || ^5.0", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-12-22T06:20:34+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "4.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71", + "shasum": "" + }, + "require": { + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:12:34+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:14:26+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "4.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "539c6691e0623af6dc6f9c20384c120f963465a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/539c6691e0623af6dc6f9c20384c120f963465a0", + "reference": "539c6691e0623af6dc6f9c20384c120f963465a0", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.6" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/recursion-context", + "type": "tidelift" + } + ], + "time": "2025-08-10T06:57:39+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "3.0.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "support": { + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-03-14T16:00:52+00:00" + }, + { + "name": "sebastian/type", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:13:03+00:00" + }, + { + "name": "sebastian/version", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c6c1022351a901512170118436c764e473f6de8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c", + "reference": "c6c1022351a901512170118436c764e473f6de8c", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T06:39:44+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.13.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/0ca86845ce43291e8f5692c7356fccf3bcf02bf4", + "reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-11-04T16:30:35+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "b7489ce515e168639d17feec34b8847c326b0b3c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b7489ce515e168639d17feec34b8847c326b0b3c", + "reference": "b7489ce515e168639d17feec34b8847c326b0b3c", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.3.1" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2025-11-17T20:03:58+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "3.2.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "d2421de7cec3274ae622c22c744de9a62c7925af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/d2421de7cec3274ae622c22c744de9a62c7925af", "reference": "d2421de7cec3274ae622c22c744de9a62c7925af", "shasum": "" }, @@ -956,11 +2753,74 @@ } ], "time": "2025-07-24T20:08:31+00:00" + }, + { + "name": "yoast/phpunit-polyfills", + "version": "2.0.5", + "source": { + "type": "git", + "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", + "reference": "1a6aecc9ebe4a9cea4e1047d0e6c496e52314c27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/1a6aecc9ebe4a9cea4e1047d0e6c496e52314c27", + "reference": "1a6aecc9ebe4a9cea4e1047d0e6c496e52314c27", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "yoast/yoastcs": "^3.2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.x-dev" + } + }, + "autoload": { + "files": [ + "phpunitpolyfills-autoload.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Team Yoast", + "email": "support@yoast.com", + "homepage": "https://yoast.com" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Yoast/PHPUnit-Polyfills/graphs/contributors" + } + ], + "description": "Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests", + "homepage": "https://github.com/Yoast/PHPUnit-Polyfills", + "keywords": [ + "phpunit", + "polyfill", + "testing" + ], + "support": { + "issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues", + "security": "https://github.com/Yoast/PHPUnit-Polyfills/security/policy", + "source": "https://github.com/Yoast/PHPUnit-Polyfills" + }, + "time": "2025-08-10T05:13:49+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -968,7 +2828,7 @@ "ext-dom": "*", "ext-json": "*" }, - "platform-dev": {}, + "platform-dev": [], "platform-overrides": { "php": "7.4" }, diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..397e2d7b --- /dev/null +++ b/tests/README.md @@ -0,0 +1,79 @@ +# PHPUnit Testing Setup + +## Quick Start + +### 1. Install WordPress Test Suite + +Run the install script with your database credentials: + +```bash +bash tests/install-wp-tests.sh wordpress_test root password localhost latest +``` + +**For Local by Flywheel users**, your database credentials are typically: +- **DB Name**: Choose any name like `wordpress_test` or `wp_phpunit_test` +- **DB User**: `root` +- **DB Password**: `root` +- **DB Host**: `localhost` + +Example for Local: +```bash +bash tests/install-wp-tests.sh wp_phpunit_test root root localhost latest +``` + +### 2. Run Tests + +Run all tests: +```bash +npm run test:php +``` + +Run tests with detailed output: +```bash +npm run test:php:watch +``` + +Or run PHPUnit directly from the src directory: +```bash +cd src && ../vendor/bin/phpunit -c ../phpunit.xml +``` + +## What Gets Installed + +The `install-wp-tests.sh` script will: +1. Download WordPress core to `/tmp/wordpress/` +2. Download the WordPress test library to `/tmp/wordpress-tests-lib/` +3. Create a test database (if it doesn't exist) +4. Configure the test environment + +## Troubleshooting + +### "Could not find includes/functions.php" +Run the install script to download the WordPress test suite. + +### Database connection errors +Verify your database credentials and that MySQL is running. + +### Permission errors +Make sure the install script is executable: +```bash +chmod +x tests/install-wp-tests.sh +``` + +## Writing Tests + +Tests should be placed in the `tests/` directory with the naming pattern `test-*.php`. + +Example test: +```php +assertTrue( true ); + } +} +``` + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e0f5446e..db9ef4de 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,10 +4,44 @@ use WP_UnitTestCase; -$tests_dir = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit'; -require_once $tests_dir . '/includes/functions.php'; -require $tests_dir . '/includes/bootstrap.php'; +// Determine the tests directory +if ( false !== getenv( 'WP_TESTS_DIR' ) ) { + $_tests_dir = getenv( 'WP_TESTS_DIR' ); +} elseif ( false !== getenv( 'WP_DEVELOP_DIR' ) ) { + $_tests_dir = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit'; +} elseif ( false !== getenv( 'WP_PHPUNIT__DIR' ) ) { + $_tests_dir = getenv( 'WP_PHPUNIT__DIR' ); +} elseif ( file_exists( '/tmp/wordpress-tests-lib/includes/functions.php' ) ) { + $_tests_dir = '/tmp/wordpress-tests-lib'; +} else { + $_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; +} + +if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) { + echo "Could not find $_tests_dir/includes/functions.php\n"; + echo "Please run: bash tests/install-wp-tests.sh [db-host] [wp-version]\n"; + exit( 1 ); +} + +// Give access to tests_add_filter() function. +require_once $_tests_dir . '/includes/functions.php'; + +/** + * Manually load the plugin being tested. + */ +function _manually_load_plugin() { + $plugin_dir = dirname( __DIR__ ); + require $plugin_dir . '/src/code-snippets.php'; +} + +tests_add_filter( 'muplugins_loaded', __NAMESPACE__ . '\\_manually_load_plugin' ); + +// Start up the WP testing environment. +require $_tests_dir . '/includes/bootstrap.php'; +/** + * Base test case for all Code Snippets tests. + */ class TestCase extends WP_UnitTestCase { // Put convenience methods here diff --git a/tests/install-wp-tests.sh b/tests/install-wp-tests.sh new file mode 100755 index 00000000..ec205487 --- /dev/null +++ b/tests/install-wp-tests.sh @@ -0,0 +1,170 @@ +#!/usr/bin/env bash + +if [ $# -lt 3 ]; then + echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + exit 1 +fi + +DB_NAME=$1 +DB_USER=$2 +DB_PASS=$3 +DB_HOST=${4-localhost} +WP_VERSION=${5-latest} +SKIP_DB_CREATE=${6-false} + +TMPDIR=${TMPDIR-/tmp} +TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") +WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} +WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} + +download() { + if [ `which curl` ]; then + curl -s "$1" > "$2"; + elif [ `which wget` ]; then + wget -nv -O "$2" "$1" + fi +} + +if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then + WP_BRANCH=${WP_VERSION%\-*} + WP_TESTS_TAG="branches/$WP_BRANCH" + +elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then + WP_TESTS_TAG="branches/$WP_VERSION" +elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then + if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then + # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x + WP_TESTS_TAG="tags/${WP_VERSION%??}" + else + WP_TESTS_TAG="tags/$WP_VERSION" + fi +elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + WP_TESTS_TAG="trunk" +else + # http serves a single offer, whereas https serves multiple. we only want one + download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json + grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json + LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') + if [[ -z "$LATEST_VERSION" ]]; then + echo "Latest WordPress version could not be found" + exit 1 + fi + WP_TESTS_TAG="tags/$LATEST_VERSION" +fi +set -ex + +install_wp() { + + if [ -d $WP_CORE_DIR ]; then + return; + fi + + mkdir -p $WP_CORE_DIR + + if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + mkdir -p $TMPDIR/wordpress-trunk + rm -rf $TMPDIR/wordpress-trunk/* + svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR/wordpress-trunk/wordpress + mv $TMPDIR/wordpress-trunk/wordpress/* $WP_CORE_DIR + else + if [ $WP_VERSION == 'latest' ]; then + local ARCHIVE_NAME='latest' + elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then + # https serves multiple offers, whereas http serves single. + download https://wordpress.org/wordpress-$WP_VERSION.tar.gz $TMPDIR/wordpress.tar.gz + ARCHIVE_NAME="wordpress-$WP_VERSION" + fi + + if [ ! -f $TMPDIR/wordpress.tar.gz ]; then + download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz + fi + tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR + fi + + download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php +} + +install_test_suite() { + # portable in-place argument for both GNU sed and Mac OSX sed + if [[ $(uname -s) == 'Darwin' ]]; then + local ioption='-i.bak' + else + local ioption='-i' + fi + + # set up testing suite if it doesn't yet exist + if [ ! -d $WP_TESTS_DIR ]; then + # set up testing suite + mkdir -p $WP_TESTS_DIR + rm -rf $WP_TESTS_DIR/{includes,data} + svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes + svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data + fi + + if [ ! -f wp-tests-config.php ]; then + download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php + # remove all forward slashes in the end + WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") + sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php + fi + +} + +recreate_db() { + shopt -s nocasematch + if [[ $1 =~ ^(y|yes)$ ]] + then + mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA + create_db + echo "Recreated the database ($DB_NAME)." + else + echo "Leaving the existing database ($DB_NAME) in place." + fi + shopt -u nocasematch +} + +create_db() { + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA +} + +install_db() { + + if [ ${SKIP_DB_CREATE} = "true" ]; then + return 0 + fi + + # parse DB_HOST for port or socket references + local PARTS=(${DB_HOST//\:/ }) + local DB_HOSTNAME=${PARTS[0]}; + local DB_SOCK_OR_PORT=${PARTS[1]}; + local EXTRA="" + + if ! [ -z $DB_HOSTNAME ] ; then + if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then + EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" + elif ! [ -z $DB_SOCK_OR_PORT ] ; then + EXTRA=" --socket=$DB_SOCK_OR_PORT" + elif ! [ -z $DB_HOSTNAME ] ; then + EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" + fi + fi + + # create database + if [ $(mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ] + then + echo "Reinstalling will delete the existing test database ($DB_NAME)" + read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB + recreate_db $DELETE_EXISTING_DB + else + create_db + fi +} + +install_wp +install_test_suite +install_db + From 770d9a7f7da43c3fcaa5544817778370003156e7 Mon Sep 17 00:00:00 2001 From: Louis Wolmarans Date: Thu, 27 Nov 2025 22:15:19 +0200 Subject: [PATCH 2/4] fix php setup --- .github/workflows/phpunit-test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/phpunit-test.yml b/.github/workflows/phpunit-test.yml index 697c4296..4eda61f6 100644 --- a/.github/workflows/phpunit-test.yml +++ b/.github/workflows/phpunit-test.yml @@ -29,11 +29,9 @@ jobs: uses: actions/checkout@v4 - name: Set up PHP - uses: shivammathur/setup-php@v2 + uses: codesnippetspro/setup-php@v2 with: php-version: ${{ inputs.php-version }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql - coverage: none - name: Compute dependency hash id: deps-hash From 03c67f5a4bbe8a45f1f9a46e7a7bff504ff7f07d Mon Sep 17 00:00:00 2001 From: Louis Wolmarans Date: Thu, 27 Nov 2025 22:25:08 +0200 Subject: [PATCH 3/4] add unit test for rest api --- tests/test-rest-api-snippets.php | 328 +++++++++++++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 tests/test-rest-api-snippets.php diff --git a/tests/test-rest-api-snippets.php b/tests/test-rest-api-snippets.php new file mode 100644 index 00000000..4b35048d --- /dev/null +++ b/tests/test-rest-api-snippets.php @@ -0,0 +1,328 @@ +user->create( [ + 'role' => 'administrator', + ] ); + } + + /** + * Set up before each test. + */ + public function set_up() { + parent::set_up(); + + // Set current user as admin for REST API permissions. + wp_set_current_user( self::$admin_user_id ); + + // Clear all existing snippets first for clean testing environment. + $this->clear_all_snippets(); + + // Seed 25 test snippets. + $this->seed_test_snippets( 25 ); + } + + /** + * Clean up after each test. + */ + public function tear_down() { + // Delete all created snippets. + foreach ( $this->created_snippet_ids as $snippet_id ) { + delete_snippet( $snippet_id ); + } + $this->created_snippet_ids = []; + + parent::tear_down(); + } + + /** + * Clear all snippets from the database. + */ + protected function clear_all_snippets() { + global $wpdb; + $table_name = code_snippets()->db->get_table_name(); + $wpdb->query( "TRUNCATE TABLE {$table_name}" ); + } + + /** + * Helper method to seed test snippets into the database. + * + * @param int $count Number of snippets to create. + */ + protected function seed_test_snippets( $count = 25 ) { + for ( $i = 1; $i <= $count; $i++ ) { + $snippet = new Snippet( [ + 'name' => "Test Snippet {$i}", + 'desc' => "This is test snippet number {$i}", + 'code' => "// Test snippet {$i}\necho 'Hello World {$i}';", + 'scope' => 'global', + 'active' => false, + 'tags' => [ 'test', "batch-{$i}" ], + ] ); + + $saved_snippet = save_snippet( $snippet ); + + if ( $saved_snippet && $saved_snippet->id ) { + $this->created_snippet_ids[] = $saved_snippet->id; + } + } + } + + /** + * Helper method to make a REST API request. + * + * @param string $endpoint Endpoint to request. + * @param array $params Query parameters. + * @return WP_REST_Response + */ + protected function make_request( $endpoint, $params = [] ) { + $request = new WP_REST_Request( 'GET', $endpoint ); + + foreach ( $params as $key => $value ) { + $request->set_param( $key, $value ); + } + + $response = rest_do_request( $request ); + return rest_get_server()->response_to_data( $response, false ); + } + + /** + * Test that we can retrieve all snippets without pagination. + */ + public function test_get_all_snippets_without_pagination() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + $response = $this->make_request( $endpoint, [ 'network' => false ] ); + + // Should return all 25 snippets. + $this->assertIsArray( $response ); + $this->assertCount( 25, $response, 'Should return all 25 snippets when no pagination params are provided' ); + + // Verify first snippet structure. + $this->assertArrayHasKey( 'id', $response[0] ); + $this->assertArrayHasKey( 'name', $response[0] ); + $this->assertArrayHasKey( 'code', $response[0] ); + } + + /** + * Test pagination with per_page parameter only (first page). + */ + public function test_get_snippets_with_per_page() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + $response = $this->make_request( $endpoint, [ + 'network' => false, + 'per_page' => 2, + ] ); + + // Should return only 2 snippets (first page). + $this->assertIsArray( $response ); + $this->assertCount( 2, $response, 'Should return exactly 2 snippets when per_page=2' ); + + // Verify we got the first 2 snippets. + $this->assertStringContainsString( 'Test Snippet 1', $response[0]['name'] ); + $this->assertStringContainsString( 'Test Snippet 2', $response[1]['name'] ); + } + + /** + * Test pagination with per_page and page parameters. + */ + public function test_get_snippets_with_per_page_and_page() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + $response = $this->make_request( $endpoint, [ + 'network' => false, + 'per_page' => 2, + 'page' => 3, + ] ); + + // Should return 2 snippets from page 3. + // Page 1: snippets 1-2, Page 2: snippets 3-4, Page 3: snippets 5-6. + $this->assertIsArray( $response ); + $this->assertCount( 2, $response, 'Should return exactly 2 snippets for page 3 with per_page=2' ); + + // Verify we got snippets 5 and 6. + $this->assertStringContainsString( 'Test Snippet 5', $response[0]['name'] ); + $this->assertStringContainsString( 'Test Snippet 6', $response[1]['name'] ); + } + + /** + * Test pagination with page parameter only (should use default per_page). + */ + public function test_get_snippets_with_page_only() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + + // First, let's get page 1 to see the default per_page behavior. + $page_1_response = $this->make_request( $endpoint, [ + 'network' => false, + 'page' => 1, + ] ); + + // WordPress REST API default per_page is typically 10. + $this->assertIsArray( $page_1_response ); + $this->assertGreaterThan( 0, count( $page_1_response ), 'Page 1 should have snippets' ); + + // Now get page 2. + $page_2_response = $this->make_request( $endpoint, [ + 'network' => false, + 'page' => 2, + ] ); + + $this->assertIsArray( $page_2_response ); + + // With 25 snippets and default per_page of 10, page 2 should have 10 snippets. + $this->assertCount( 10, $page_2_response, 'Page 2 with default per_page should have 10 snippets' ); + } + + /** + * Test that headers contain correct pagination metadata. + */ + public function test_pagination_headers() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + $request = new WP_REST_Request( 'GET', $endpoint ); + $request->set_param( 'network', false ); + $request->set_param( 'per_page', 5 ); + $request->set_param( 'page', 1 ); + + $response = rest_do_request( $request ); + + // Check headers. + $headers = $response->get_headers(); + + $this->assertEquals( 25, $headers['X-WP-Total'], 'X-WP-Total header should show 25 total snippets' ); + $this->assertEquals( 5, $headers['X-WP-TotalPages'], 'X-WP-TotalPages should be 5 (25 snippets / 5 per_page)' ); + } + + /** + * Test that last page returns correct number of snippets. + */ + public function test_last_page_with_partial_results() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + + // With 25 snippets and per_page=10, page 3 should have 5 snippets. + $response = $this->make_request( $endpoint, [ + 'network' => false, + 'per_page' => 10, + 'page' => 3, + ] ); + + $this->assertIsArray( $response ); + $this->assertCount( 5, $response, 'Last page should have only 5 remaining snippets (25 % 10)' ); + } + + /** + * Test that requesting a page beyond available pages returns empty array. + */ + public function test_page_beyond_available_returns_empty() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + + // Request page 100 (way beyond our 25 snippets). + $response = $this->make_request( $endpoint, [ + 'network' => false, + 'per_page' => 10, + 'page' => 100, + ] ); + + $this->assertIsArray( $response ); + $this->assertCount( 0, $response, 'Requesting page beyond available should return empty array' ); + } + + /** + * Test per_page with value of 1. + */ + public function test_per_page_one() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + $response = $this->make_request( $endpoint, [ + 'network' => false, + 'per_page' => 1, + 'page' => 5, + ] ); + + $this->assertIsArray( $response ); + $this->assertCount( 1, $response, 'Should return exactly 1 snippet when per_page=1' ); + $this->assertStringContainsString( 'Test Snippet 5', $response[0]['name'] ); + } + + /** + * Test that per_page larger than total returns all snippets. + */ + public function test_per_page_larger_than_total() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + $response = $this->make_request( $endpoint, [ + 'network' => false, + 'per_page' => 100, + 'page' => 1, + ] ); + + $this->assertIsArray( $response ); + $this->assertCount( 25, $response, 'Should return all 25 snippets when per_page exceeds total' ); + } + + /** + * Test that snippet data structure is correct. + */ + public function test_snippet_data_structure() { + $endpoint = "/{$this->namespace}/{$this->base_route}"; + $response = $this->make_request( $endpoint, [ + 'network' => false, + 'per_page' => 1, + ] ); + + $this->assertIsArray( $response ); + $this->assertCount( 1, $response ); + + $snippet = $response[0]; + + // Check required fields exist. + $required_fields = [ 'id', 'name', 'desc', 'code', 'scope', 'active', 'tags' ]; + foreach ( $required_fields as $field ) { + $this->assertArrayHasKey( $field, $snippet, "Snippet should have '{$field}' field" ); + } + + // Verify field types. + $this->assertIsInt( $snippet['id'] ); + $this->assertIsString( $snippet['name'] ); + $this->assertIsString( $snippet['code'] ); + $this->assertIsBool( $snippet['active'] ); + $this->assertIsArray( $snippet['tags'] ); + } +} From 78d686135e96144dbcd2a39f72fcddb92bfdbc91 Mon Sep 17 00:00:00 2001 From: Louis Wolmarans Date: Thu, 27 Nov 2025 22:37:59 +0200 Subject: [PATCH 4/4] simplify tests bootstrap --- tests/bootstrap.php | 32 ++++-------- tests/test-rest-api-snippets.php | 90 ++++++++++++++------------------ 2 files changed, 50 insertions(+), 72 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index db9ef4de..4158f648 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,12 +4,13 @@ use WP_UnitTestCase; -// Determine the tests directory -if ( false !== getenv( 'WP_TESTS_DIR' ) ) { +$_tests_dir = false; + +if ( getenv( 'WP_TESTS_DIR' ) ) { $_tests_dir = getenv( 'WP_TESTS_DIR' ); -} elseif ( false !== getenv( 'WP_DEVELOP_DIR' ) ) { +} elseif ( getenv( 'WP_DEVELOP_DIR' ) ) { $_tests_dir = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit'; -} elseif ( false !== getenv( 'WP_PHPUNIT__DIR' ) ) { +} elseif ( getenv( 'WP_PHPUNIT__DIR' ) ) { $_tests_dir = getenv( 'WP_PHPUNIT__DIR' ); } elseif ( file_exists( '/tmp/wordpress-tests-lib/includes/functions.php' ) ) { $_tests_dir = '/tmp/wordpress-tests-lib'; @@ -18,31 +19,18 @@ } if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) { - echo "Could not find $_tests_dir/includes/functions.php\n"; - echo "Please run: bash tests/install-wp-tests.sh [db-host] [wp-version]\n"; - exit( 1 ); + die( "WordPress test suite not found. Run: bash tests/install-wp-tests.sh \n" ); } -// Give access to tests_add_filter() function. require_once $_tests_dir . '/includes/functions.php'; -/** - * Manually load the plugin being tested. - */ -function _manually_load_plugin() { - $plugin_dir = dirname( __DIR__ ); - require $plugin_dir . '/src/code-snippets.php'; -} +tests_add_filter( 'muplugins_loaded', function() { + require dirname( __DIR__ ) . '/src/code-snippets.php'; +} ); -tests_add_filter( 'muplugins_loaded', __NAMESPACE__ . '\\_manually_load_plugin' ); - -// Start up the WP testing environment. require $_tests_dir . '/includes/bootstrap.php'; /** * Base test case for all Code Snippets tests. */ -class TestCase extends WP_UnitTestCase { - // Put convenience methods here - -} +class TestCase extends WP_UnitTestCase {} diff --git a/tests/test-rest-api-snippets.php b/tests/test-rest-api-snippets.php index 4b35048d..cbf5499d 100644 --- a/tests/test-rest-api-snippets.php +++ b/tests/test-rest-api-snippets.php @@ -6,7 +6,6 @@ use WP_REST_Request; use function Code_Snippets\code_snippets; use function Code_Snippets\save_snippet; -use function Code_Snippets\delete_snippet; /** * Tests for the Snippets REST API endpoint. @@ -15,13 +14,6 @@ */ class REST_API_Snippets_Test extends TestCase { - /** - * Array of created snippet IDs for cleanup. - * - * @var int[] - */ - protected $created_snippet_ids = []; - /** * REST API namespace and base route. * @@ -53,30 +45,12 @@ public static function wpSetUpBeforeClass( $factory ) { */ public function set_up() { parent::set_up(); - - // Set current user as admin for REST API permissions. - wp_set_current_user( self::$admin_user_id ); - // Clear all existing snippets first for clean testing environment. + wp_set_current_user( self::$admin_user_id ); $this->clear_all_snippets(); - - // Seed 25 test snippets. $this->seed_test_snippets( 25 ); } - /** - * Clean up after each test. - */ - public function tear_down() { - // Delete all created snippets. - foreach ( $this->created_snippet_ids as $snippet_id ) { - delete_snippet( $snippet_id ); - } - $this->created_snippet_ids = []; - - parent::tear_down(); - } - /** * Clear all snippets from the database. */ @@ -102,11 +76,7 @@ protected function seed_test_snippets( $count = 25 ) { 'tags' => [ 'test', "batch-{$i}" ], ] ); - $saved_snippet = save_snippet( $snippet ); - - if ( $saved_snippet && $saved_snippet->id ) { - $this->created_snippet_ids[] = $saved_snippet->id; - } + save_snippet( $snippet ); } } @@ -132,14 +102,16 @@ protected function make_request( $endpoint, $params = [] ) { * Test that we can retrieve all snippets without pagination. */ public function test_get_all_snippets_without_pagination() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; + + // Act. $response = $this->make_request( $endpoint, [ 'network' => false ] ); - // Should return all 25 snippets. + // Assert. $this->assertIsArray( $response ); $this->assertCount( 25, $response, 'Should return all 25 snippets when no pagination params are provided' ); - // Verify first snippet structure. $this->assertArrayHasKey( 'id', $response[0] ); $this->assertArrayHasKey( 'name', $response[0] ); $this->assertArrayHasKey( 'code', $response[0] ); @@ -149,17 +121,19 @@ public function test_get_all_snippets_without_pagination() { * Test pagination with per_page parameter only (first page). */ public function test_get_snippets_with_per_page() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; + + // Act. $response = $this->make_request( $endpoint, [ 'network' => false, 'per_page' => 2, ] ); - // Should return only 2 snippets (first page). + // Assert. $this->assertIsArray( $response ); $this->assertCount( 2, $response, 'Should return exactly 2 snippets when per_page=2' ); - // Verify we got the first 2 snippets. $this->assertStringContainsString( 'Test Snippet 1', $response[0]['name'] ); $this->assertStringContainsString( 'Test Snippet 2', $response[1]['name'] ); } @@ -168,19 +142,20 @@ public function test_get_snippets_with_per_page() { * Test pagination with per_page and page parameters. */ public function test_get_snippets_with_per_page_and_page() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; + + // Act. $response = $this->make_request( $endpoint, [ 'network' => false, 'per_page' => 2, 'page' => 3, ] ); - // Should return 2 snippets from page 3. - // Page 1: snippets 1-2, Page 2: snippets 3-4, Page 3: snippets 5-6. + // Assert. $this->assertIsArray( $response ); $this->assertCount( 2, $response, 'Should return exactly 2 snippets for page 3 with per_page=2' ); - // Verify we got snippets 5 and 6. $this->assertStringContainsString( 'Test Snippet 5', $response[0]['name'] ); $this->assertStringContainsString( 'Test Snippet 6', $response[1]['name'] ); } @@ -189,27 +164,27 @@ public function test_get_snippets_with_per_page_and_page() { * Test pagination with page parameter only (should use default per_page). */ public function test_get_snippets_with_page_only() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; - // First, let's get page 1 to see the default per_page behavior. + // Act. $page_1_response = $this->make_request( $endpoint, [ 'network' => false, 'page' => 1, ] ); - // WordPress REST API default per_page is typically 10. + // Assert. $this->assertIsArray( $page_1_response ); $this->assertGreaterThan( 0, count( $page_1_response ), 'Page 1 should have snippets' ); - // Now get page 2. + // Act. $page_2_response = $this->make_request( $endpoint, [ 'network' => false, 'page' => 2, ] ); + // Assert. $this->assertIsArray( $page_2_response ); - - // With 25 snippets and default per_page of 10, page 2 should have 10 snippets. $this->assertCount( 10, $page_2_response, 'Page 2 with default per_page should have 10 snippets' ); } @@ -217,17 +192,18 @@ public function test_get_snippets_with_page_only() { * Test that headers contain correct pagination metadata. */ public function test_pagination_headers() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; $request = new WP_REST_Request( 'GET', $endpoint ); $request->set_param( 'network', false ); $request->set_param( 'per_page', 5 ); $request->set_param( 'page', 1 ); + // Act. $response = rest_do_request( $request ); - - // Check headers. $headers = $response->get_headers(); + // Assert. $this->assertEquals( 25, $headers['X-WP-Total'], 'X-WP-Total header should show 25 total snippets' ); $this->assertEquals( 5, $headers['X-WP-TotalPages'], 'X-WP-TotalPages should be 5 (25 snippets / 5 per_page)' ); } @@ -236,15 +212,17 @@ public function test_pagination_headers() { * Test that last page returns correct number of snippets. */ public function test_last_page_with_partial_results() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; - // With 25 snippets and per_page=10, page 3 should have 5 snippets. + // Act. $response = $this->make_request( $endpoint, [ 'network' => false, 'per_page' => 10, 'page' => 3, ] ); + // Assert. $this->assertIsArray( $response ); $this->assertCount( 5, $response, 'Last page should have only 5 remaining snippets (25 % 10)' ); } @@ -253,15 +231,17 @@ public function test_last_page_with_partial_results() { * Test that requesting a page beyond available pages returns empty array. */ public function test_page_beyond_available_returns_empty() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; - // Request page 100 (way beyond our 25 snippets). + // Act. $response = $this->make_request( $endpoint, [ 'network' => false, 'per_page' => 10, 'page' => 100, ] ); + // Assert. $this->assertIsArray( $response ); $this->assertCount( 0, $response, 'Requesting page beyond available should return empty array' ); } @@ -270,13 +250,17 @@ public function test_page_beyond_available_returns_empty() { * Test per_page with value of 1. */ public function test_per_page_one() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; + + // Act. $response = $this->make_request( $endpoint, [ 'network' => false, 'per_page' => 1, 'page' => 5, ] ); + // Assert. $this->assertIsArray( $response ); $this->assertCount( 1, $response, 'Should return exactly 1 snippet when per_page=1' ); $this->assertStringContainsString( 'Test Snippet 5', $response[0]['name'] ); @@ -286,13 +270,17 @@ public function test_per_page_one() { * Test that per_page larger than total returns all snippets. */ public function test_per_page_larger_than_total() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; + + // Act. $response = $this->make_request( $endpoint, [ 'network' => false, 'per_page' => 100, 'page' => 1, ] ); + // Assert. $this->assertIsArray( $response ); $this->assertCount( 25, $response, 'Should return all 25 snippets when per_page exceeds total' ); } @@ -301,24 +289,26 @@ public function test_per_page_larger_than_total() { * Test that snippet data structure is correct. */ public function test_snippet_data_structure() { + // Arrange. $endpoint = "/{$this->namespace}/{$this->base_route}"; + + // Act. $response = $this->make_request( $endpoint, [ 'network' => false, 'per_page' => 1, ] ); + // Assert. $this->assertIsArray( $response ); $this->assertCount( 1, $response ); $snippet = $response[0]; - // Check required fields exist. $required_fields = [ 'id', 'name', 'desc', 'code', 'scope', 'active', 'tags' ]; foreach ( $required_fields as $field ) { $this->assertArrayHasKey( $field, $snippet, "Snippet should have '{$field}' field" ); } - // Verify field types. $this->assertIsInt( $snippet['id'] ); $this->assertIsString( $snippet['name'] ); $this->assertIsString( $snippet['code'] );