From a7d6a57f0103612243491e32ca321b59d4b6a8a7 Mon Sep 17 00:00:00 2001 From: magdev Date: Sun, 1 Mar 2026 13:08:22 +0100 Subject: [PATCH] Add PHPUnit test suite, PSR-4 refactor, lint+test CI jobs (v1.3.1) - 57 unit tests covering ProductType, StockManager, CartHandler, Plugin, Admin/ProductData, Admin/Settings using Brain Monkey + Mockery - WooCommerce class stubs for testing without WP installation - PHP lint and test jobs in release workflow (test gate blocks release) - PSR-4 namespace change: WC_Composable_Product -> Magdev\WcComposableProduct - PascalCase filenames for all classes under includes/ Co-Authored-By: Claude Opus 4.6 --- .gitea/workflows/release.yml | 45 + .gitignore | 4 + CHANGELOG.md | 17 + CLAUDE.md | 15 +- README.md | 13 +- composer.json | 10 + composer.lock | 2065 ++++++++++++++++++- phpunit.xml.dist | 24 + tests/TestCase.php | 75 + tests/Unit/Admin/ProductDataTest.php | 108 + tests/Unit/Admin/SettingsTest.php | 84 + tests/Unit/CartHandlerTest.php | 184 ++ tests/Unit/PluginTest.php | 72 + tests/Unit/ProductTypeTest.php | 218 ++ tests/Unit/StockManagerTest.php | 226 ++ tests/bootstrap.php | 33 + tests/stubs/class-wc-admin-settings.php | 11 + tests/stubs/class-wc-cart.php | 15 + tests/stubs/class-wc-data.php | 35 + tests/stubs/class-wc-order-item-product.php | 28 + tests/stubs/class-wc-order.php | 24 + tests/stubs/class-wc-product.php | 88 + tests/stubs/class-wc-settings-page.php | 29 + wc-composable-product.php | 4 +- 24 files changed, 3415 insertions(+), 12 deletions(-) create mode 100644 phpunit.xml.dist create mode 100644 tests/TestCase.php create mode 100644 tests/Unit/Admin/ProductDataTest.php create mode 100644 tests/Unit/Admin/SettingsTest.php create mode 100644 tests/Unit/CartHandlerTest.php create mode 100644 tests/Unit/PluginTest.php create mode 100644 tests/Unit/ProductTypeTest.php create mode 100644 tests/Unit/StockManagerTest.php create mode 100644 tests/bootstrap.php create mode 100644 tests/stubs/class-wc-admin-settings.php create mode 100644 tests/stubs/class-wc-cart.php create mode 100644 tests/stubs/class-wc-data.php create mode 100644 tests/stubs/class-wc-order-item-product.php create mode 100644 tests/stubs/class-wc-order.php create mode 100644 tests/stubs/class-wc-product.php create mode 100644 tests/stubs/class-wc-settings-page.php diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 4b9e915..f34665f 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -6,7 +6,52 @@ on: - 'v*' jobs: + lint: + name: PHP Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + extensions: mbstring, xml, zip + tools: composer:v2 + + - name: PHP Syntax Check + run: | + find includes -name "*.php" -print0 | xargs -0 -n1 php -l + find tests -name "*.php" -print0 | xargs -0 -n1 php -l + + test: + runs-on: ubuntu-latest + needs: lint + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + extensions: mbstring, xml + tools: composer:v2 + + - name: Install Composer dependencies + run: | + composer config platform.php 8.3.0 + composer install --optimize-autoloader --no-interaction + + - name: Run PHPUnit tests + run: vendor/bin/phpunit --testdox + build-release: + needs: test runs-on: ubuntu-latest steps: - name: Checkout code diff --git a/.gitignore b/.gitignore index 8bb3ff0..df89653 100755 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,10 @@ logs/ Thumbs.db .directory +# PHPUnit local overrides +phpunit.xml + # Binary files languages/*.mo +.phpunit.result.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b50ab3..c9e24dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.3.1] - 2026-03-01 + +### Added + +- **PHPUnit test suite**: 57 unit tests covering all 6 core classes (ProductType, StockManager, CartHandler, Plugin, Admin/ProductData, Admin/Settings) +- **Brain Monkey + Mockery** for WordPress/WooCommerce function mocking without a full WP installation +- **WooCommerce class stubs** in `tests/stubs/` for classes extended by the plugin (WC_Product, WC_Settings_Page, etc.) +- **PHP lint job** in release workflow — syntax-checks all PHP files before testing +- **Test job** in release workflow — tests must pass before release package is built (`needs: test`) +- Testing section in README + +### Changed + +- **PSR-4 refactored**: Renamed files to PascalCase (Product_Type → ProductType, etc.) and changed namespace from `WC_Composable_Product` to `Magdev\WcComposableProduct` +- Updated all cross-references in PHP files, main plugin file, composer.json, CSS/JS doc comments, and translation file source comments +- Release workflow now has three stages: lint → test → build-release + ## [1.3.0] - 2026-03-01 ### Added diff --git a/CLAUDE.md b/CLAUDE.md index 6f1c627..4fc05f8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -18,6 +18,7 @@ This project is 100% AI-generated ("vibe-coded") using Claude.AI. - **Styling:** Custom CSS - **Dependencies:** Composer - **i18n:** WordPress i18n (.pot/.po/.mo), text domain: `wc-composable-product` +- **Testing:** PHPUnit 9.6 + Brain Monkey 2.7 + Mockery 1.6 - **CI/CD:** Gitea Actions (`.gitea/workflows/release.yml`) ## Project Structure @@ -45,10 +46,16 @@ wc-composable-product/ │ └── StockManager.php # Stock management & inventory tracking ├── languages/ # Translation files (.pot, .po, .mo) ├── releases/ # Release packages (gitignored) +├── tests/ +│ ├── bootstrap.php # Test environment setup (constants, stubs) +│ ├── TestCase.php # Base test case with Brain Monkey +│ ├── stubs/ # Minimal WooCommerce class stubs +│ └── Unit/ # PHPUnit unit tests ├── templates/ │ └── product-selector.twig # Frontend selection interface ├── vendor/ # Composer dependencies (gitignored, included in releases) ├── composer.json +├── phpunit.xml.dist # PHPUnit configuration └── wc-composable-product.php # Main plugin file ``` @@ -133,11 +140,17 @@ Compile .po to .mo: `for po in languages/*.po; do msgfmt -o "${po%.po}.mo" "$po" WordPress requires compiled .mo files — .po files alone are insufficient. +## Testing + +Run unit tests: `vendor/bin/phpunit --testdox` + +Tests use **Brain Monkey** to mock WordPress/WooCommerce functions without a full WP installation. WooCommerce classes (`WC_Product`, `WC_Settings_Page`, etc.) are provided as minimal stubs in `tests/stubs/` so PHP can parse `extends` declarations. The release workflow runs tests before building — a failing test blocks the release. + ## Release Workflow ### Automated (Gitea CI/CD) -Push an annotated tag (`v*`) to trigger the workflow. It installs PHP 8.3, production Composer deps, compiles translations, verifies version matches tag, creates ZIP with checksums, and publishes a Gitea release. +Push an annotated tag (`v*`) to trigger the workflow. It first runs the PHPUnit test suite, then installs PHP 8.3, production Composer deps, compiles translations, verifies version matches tag, creates ZIP with checksums, and publishes a Gitea release. Tests must pass before the release package is built. ### Manual diff --git a/README.md b/README.md index c4f71e3..14e7bd9 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ Create composable products where customers can select a limited number of items - **Pricing Options**: Fixed price or sum of selected products with full locale-aware formatting - **Multi-language Support**: Fully translated in 6 locales (de_DE, de_CH, fr_CH, it_CH + informal variants) - **Modern UI**: Clean interface built with Twig templates and vanilla JavaScript -- **CI/CD**: Automated release workflow for Gitea +- **Tested**: 57 unit tests with PHPUnit, Brain Monkey, and Mockery +- **CI/CD**: Automated release workflow with test gate for Gitea ## Requirements @@ -118,6 +119,16 @@ This project was created with AI assistance (Claude.AI) and follows WordPress an composer install ``` +### Running Tests + +The plugin includes a PHPUnit test suite with Brain Monkey for WordPress function mocking: + +```bash +vendor/bin/phpunit --testdox +``` + +Tests run without a WordPress installation. WooCommerce classes are provided as minimal stubs in `tests/stubs/`. + ### Translation Generate POT file: diff --git a/composer.json b/composer.json index 60e57fe..85041e9 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,16 @@ "Magdev\\WcComposableProduct\\": "includes/" } }, + "require-dev": { + "brain/monkey": "^2.7", + "mockery/mockery": "^1.6", + "phpunit/phpunit": "^9.6" + }, + "autoload-dev": { + "psr-4": { + "Magdev\\WcComposableProduct\\Tests\\": "tests/" + } + }, "config": { "optimize-autoloader": true, "sort-packages": true diff --git a/composer.lock b/composer.lock index 2d2c93d..93b0a46 100644 --- a/composer.lock +++ b/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": "1342d597ec95bd7abf806825a199cae0", + "content-hash": "b1604d49fcc5b210c5bcc61f22c43b8e", "packages": [ { "name": "symfony/deprecation-contracts", @@ -243,16 +243,16 @@ }, { "name": "twig/twig", - "version": "v3.22.2", + "version": "v3.23.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "946ddeafa3c9f4ce279d1f34051af041db0e16f2" + "reference": "a64dc5d2cc7d6cafb9347f6cd802d0d06d0351c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/946ddeafa3c9f4ce279d1f34051af041db0e16f2", - "reference": "946ddeafa3c9f4ce279d1f34051af041db0e16f2", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/a64dc5d2cc7d6cafb9347f6cd802d0d06d0351c9", + "reference": "a64dc5d2cc7d6cafb9347f6cd802d0d06d0351c9", "shasum": "" }, "require": { @@ -306,7 +306,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.22.2" + "source": "https://github.com/twigphp/Twig/tree/v3.23.0" }, "funding": [ { @@ -318,10 +318,2059 @@ "type": "tidelift" } ], - "time": "2025-12-14T11:28:47+00:00" + "time": "2026-01-23T21:00:41+00:00" + } + ], + "packages-dev": [ + { + "name": "antecedent/patchwork", + "version": "2.2.3", + "source": { + "type": "git", + "url": "https://github.com/antecedent/patchwork.git", + "reference": "8b6b235f405af175259c8f56aea5fc23ab9f03ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/antecedent/patchwork/zipball/8b6b235f405af175259c8f56aea5fc23ab9f03ce", + "reference": "8b6b235f405af175259c8f56aea5fc23ab9f03ce", + "shasum": "" + }, + "require": { + "php": ">=7.1.0" + }, + "require-dev": { + "phpunit/phpunit": ">=4" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignas Rudaitis", + "email": "ignas.rudaitis@gmail.com" + } + ], + "description": "Method redefinition (monkey-patching) functionality for PHP.", + "homepage": "https://antecedent.github.io/patchwork/", + "keywords": [ + "aop", + "aspect", + "interception", + "monkeypatching", + "redefinition", + "runkit", + "testing" + ], + "support": { + "issues": "https://github.com/antecedent/patchwork/issues", + "source": "https://github.com/antecedent/patchwork/tree/2.2.3" + }, + "time": "2025-09-17T09:00:56+00:00" + }, + { + "name": "brain/monkey", + "version": "2.7.0", + "source": { + "type": "git", + "url": "https://github.com/Brain-WP/BrainMonkey.git", + "reference": "ea3aeb3d559ba3c0930b3f4d210b665a4c044d83" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Brain-WP/BrainMonkey/zipball/ea3aeb3d559ba3c0930b3f4d210b665a4c044d83", + "reference": "ea3aeb3d559ba3c0930b3f4d210b665a4c044d83", + "shasum": "" + }, + "require": { + "antecedent/patchwork": "^2.1.17", + "mockery/mockery": "~1.3.6 || ~1.4.4 || ~1.5.1 || ^1.6.10", + "php": ">=5.6.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", + "phpcompatibility/php-compatibility": "^9.3.0", + "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.49 || ^9.6.30" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev", + "dev-version/1": "1.x-dev" + } + }, + "autoload": { + "files": [ + "inc/api.php" + ], + "psr-4": { + "Brain\\Monkey\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Giuseppe Mazzapica", + "email": "giuseppe.mazzapica@gmail.com", + "homepage": "https://gmazzap.me", + "role": "Developer" + } + ], + "description": "Mocking utility for PHP functions and WordPress plugin API", + "keywords": [ + "Monkey Patching", + "interception", + "mock", + "mock functions", + "mockery", + "patchwork", + "redefinition", + "runkit", + "test", + "testing" + ], + "support": { + "issues": "https://github.com/Brain-WP/BrainMonkey/issues", + "source": "https://github.com/Brain-WP/BrainMonkey" + }, + "time": "2026-02-05T09:22:14+00:00" + }, + { + "name": "doctrine/instantiator", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "23da848e1a2308728fe5fdddabf4be17ff9720c7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/23da848e1a2308728fe5fdddabf4be17ff9720c7", + "reference": "23da848e1a2308728fe5fdddabf4be17ff9720c7", + "shasum": "" + }, + "require": { + "php": "^8.4" + }, + "require-dev": { + "doctrine/coding-standard": "^14", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^10.5.58" + }, + "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/2.1.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": "2026-01-05T06:47:08+00:00" + }, + { + "name": "hamcrest/hamcrest-php", + "version": "v2.1.1", + "source": { + "type": "git", + "url": "https://github.com/hamcrest/hamcrest-php.git", + "reference": "f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487", + "reference": "f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "replace": { + "cordoval/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "kodova/hamcrest-php": "*" + }, + "require-dev": { + "phpunit/php-file-iterator": "^1.4 || ^2.0 || ^3.0", + "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "classmap": [ + "hamcrest" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": [ + "test" + ], + "support": { + "issues": "https://github.com/hamcrest/hamcrest-php/issues", + "source": "https://github.com/hamcrest/hamcrest-php/tree/v2.1.1" + }, + "time": "2025-04-30T06:54:44+00:00" + }, + { + "name": "mockery/mockery", + "version": "1.6.12", + "source": { + "type": "git", + "url": "https://github.com/mockery/mockery.git", + "reference": "1f4efdd7d3beafe9807b08156dfcb176d18f1699" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mockery/mockery/zipball/1f4efdd7d3beafe9807b08156dfcb176d18f1699", + "reference": "1f4efdd7d3beafe9807b08156dfcb176d18f1699", + "shasum": "" + }, + "require": { + "hamcrest/hamcrest-php": "^2.0.1", + "lib-pcre": ">=7.0", + "php": ">=7.3" + }, + "conflict": { + "phpunit/phpunit": "<8.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.5 || ^9.6.17", + "symplify/easy-coding-standard": "^12.1.14" + }, + "type": "library", + "autoload": { + "files": [ + "library/helpers.php", + "library/Mockery.php" + ], + "psr-4": { + "Mockery\\": "library/Mockery" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Pádraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "https://github.com/padraic", + "role": "Author" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "https://davedevelopment.co.uk", + "role": "Developer" + }, + { + "name": "Nathanael Esayeas", + "email": "nathanael.esayeas@protonmail.com", + "homepage": "https://github.com/ghostwriter", + "role": "Lead Developer" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework", + "homepage": "https://github.com/mockery/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "support": { + "docs": "https://docs.mockery.io/", + "issues": "https://github.com/mockery/mockery/issues", + "rss": "https://github.com/mockery/mockery/releases.atom", + "security": "https://github.com/mockery/mockery/security/advisories", + "source": "https://github.com/mockery/mockery" + }, + "time": "2024-05-16T03:13:13+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.7.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82", + "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82", + "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.7.0" + }, + "time": "2025-12-06T11:56:16+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": "phpunit/php-code-coverage", + "version": "9.2.32", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/85402a822d1ecf1db1096959413d35e1c37cf1a5", + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "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": "^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" + }, + "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": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "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/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-08-22T04:23:01+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "3.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" + }, + "dist": { + "type": "zip", + "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.34", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "b36f02317466907a230d3aa1d34467041271ef4a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b36f02317466907a230d3aa1d34467041271ef4a", + "reference": "b36f02317466907a230d3aa1d34467041271ef4a", + "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.10", + "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.34" + }, + "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": "2026-01-27T05:45:00+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.10", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "e4df00b9b3571187db2831ae9aada2c6efbd715d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e4df00b9b3571187db2831ae9aada2c6efbd715d", + "reference": "e4df00b9b3571187db2831ae9aada2c6efbd715d", + "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.10" + }, + "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": "2026-01-24T09:22:56+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": "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" } ], - "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": {}, diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..00ac83f --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,24 @@ + + + + + tests/Unit + + + + + + includes + + + diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..d1b343a --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,75 @@ + 100, + 'get_name' => 'Test Product', + 'get_type' => 'simple', + 'get_price' => '10.00', + 'get_regular_price' => '10.00', + 'get_price_html' => '$10.00', + 'get_permalink' => 'https://example.com/product/test', + 'get_image_id' => 1, + 'get_stock_quantity' => null, + 'get_stock_status' => 'instock', + 'is_purchasable' => true, + 'is_in_stock' => true, + 'managing_stock' => false, + 'backorders_allowed' => false, + ]; + + $config = array_merge($defaults, $overrides); + $mock = \Mockery::mock('WC_Product'); + + foreach ($config as $method => $return) { + $mock->shouldReceive($method)->andReturn($return)->byDefault(); + } + + return $mock; + } +} diff --git a/tests/Unit/Admin/ProductDataTest.php b/tests/Unit/Admin/ProductDataTest.php new file mode 100644 index 0000000..a32183f --- /dev/null +++ b/tests/Unit/Admin/ProductDataTest.php @@ -0,0 +1,108 @@ +add_product_data_tab()')); + self::assertNotFalse(has_action('woocommerce_product_data_panels', 'Magdev\WcComposableProduct\Admin\ProductData->add_product_data_panel()')); + self::assertNotFalse(has_action('woocommerce_process_product_meta_composable', 'Magdev\WcComposableProduct\Admin\ProductData->save_product_data()')); + self::assertNotFalse(has_action('woocommerce_product_options_general_product_data', 'Magdev\WcComposableProduct\Admin\ProductData->add_general_fields()')); + } + + public function testAddProductDataTab_AddsComposableTab(): void + { + $productData = new ProductData(); + $tabs = $productData->add_product_data_tab([]); + + $this->assertArrayHasKey('composable', $tabs); + $this->assertSame('composable_product_data', $tabs['composable']['target']); + $this->assertContains('show_if_composable', $tabs['composable']['class']); + $this->assertSame(21, $tabs['composable']['priority']); + } + + public function testSaveProductData_SavesAllFields(): void + { + $_POST = [ + '_composable_selection_limit' => '5', + '_composable_pricing_mode' => 'fixed', + '_composable_include_unpublished' => 'yes', + '_composable_criteria_type' => 'tag', + '_composable_categories' => ['1', '2'], + '_composable_tags' => ['3', '4'], + '_composable_skus' => 'SKU-1, SKU-2', + ]; + + Functions\expect('absint')->andReturnUsing(function ($val) { + return abs((int) $val); + }); + Functions\expect('sanitize_text_field')->andReturnUsing(function ($val) { + return $val; + }); + Functions\expect('sanitize_textarea_field')->andReturnUsing(function ($val) { + return $val; + }); + + Functions\expect('update_post_meta')->times(7); + + $productData = new ProductData(); + $productData->save_product_data(42); + } + + public function testSaveProductData_DefaultsWhenPostEmpty(): void + { + // No POST data at all + Functions\expect('absint')->andReturnUsing(function ($val) { + return abs((int) $val); + }); + Functions\expect('sanitize_text_field')->andReturnUsing(function ($val) { + return $val; + }); + Functions\expect('sanitize_textarea_field')->andReturnUsing(function ($val) { + return $val; + }); + + Functions\expect('update_post_meta') + ->with(42, '_composable_selection_limit', \Mockery::any())->once(); + Functions\expect('update_post_meta') + ->with(42, '_composable_pricing_mode', '')->once(); + Functions\expect('update_post_meta') + ->with(42, '_composable_include_unpublished', '')->once(); + Functions\expect('update_post_meta') + ->with(42, '_composable_criteria_type', 'category')->once(); + Functions\expect('update_post_meta') + ->with(42, '_composable_categories', [])->once(); + Functions\expect('update_post_meta') + ->with(42, '_composable_tags', [])->once(); + Functions\expect('update_post_meta') + ->with(42, '_composable_skus', '')->once(); + + $productData = new ProductData(); + $productData->save_product_data(42); + } +} diff --git a/tests/Unit/Admin/SettingsTest.php b/tests/Unit/Admin/SettingsTest.php new file mode 100644 index 0000000..e64ce01 --- /dev/null +++ b/tests/Unit/Admin/SettingsTest.php @@ -0,0 +1,84 @@ +assertSame('composable_products', $settings->get_id()); + } + + public function testGetSettings_ReturnsExpectedFieldIds(): void + { + Functions\expect('apply_filters') + ->once() + ->with('wc_composable_settings', \Mockery::type('array')) + ->andReturnUsing(function ($hook, $settings) { + return $settings; + }); + + $settings = new Settings(); + $fields = $settings->get_settings(); + + // Extract all field IDs + $ids = array_column($fields, 'id'); + + $this->assertContains('wc_composable_settings', $ids); + $this->assertContains('wc_composable_default_limit', $ids); + $this->assertContains('wc_composable_default_pricing', $ids); + $this->assertContains('wc_composable_include_unpublished', $ids); + $this->assertContains('wc_composable_show_images', $ids); + $this->assertContains('wc_composable_show_prices', $ids); + $this->assertContains('wc_composable_show_total', $ids); + } + + public function testGetSettings_HasCorrectFieldTypes(): void + { + Functions\expect('apply_filters') + ->once() + ->andReturnUsing(function ($hook, $settings) { + return $settings; + }); + + $settings = new Settings(); + $fields = $settings->get_settings(); + + // Index fields by ID for easy lookup + $indexed = []; + foreach ($fields as $field) { + if (isset($field['id'])) { + $indexed[$field['id']] = $field; + } + } + + $this->assertSame('number', $indexed['wc_composable_default_limit']['type']); + $this->assertSame('select', $indexed['wc_composable_default_pricing']['type']); + $this->assertSame('checkbox', $indexed['wc_composable_include_unpublished']['type']); + $this->assertSame('checkbox', $indexed['wc_composable_show_images']['type']); + } + + public function testGetSettings_AppliesFilter(): void + { + Functions\expect('apply_filters') + ->once() + ->with('wc_composable_settings', \Mockery::type('array')) + ->andReturnUsing(function ($hook, $settings) { + return $settings; + }); + + $settings = new Settings(); + $settings->get_settings(); + } +} diff --git a/tests/Unit/CartHandlerTest.php b/tests/Unit/CartHandlerTest.php new file mode 100644 index 0000000..b740cff --- /dev/null +++ b/tests/Unit/CartHandlerTest.php @@ -0,0 +1,184 @@ +validate_add_to_cart()')); + self::assertNotFalse(has_filter('woocommerce_add_cart_item_data', 'Magdev\WcComposableProduct\CartHandler->add_cart_item_data()')); + self::assertNotFalse(has_filter('woocommerce_get_cart_item_from_session', 'Magdev\WcComposableProduct\CartHandler->get_cart_item_from_session()')); + self::assertNotFalse(has_filter('woocommerce_get_item_data', 'Magdev\WcComposableProduct\CartHandler->display_cart_item_data()')); + self::assertNotFalse(has_action('woocommerce_before_calculate_totals', 'Magdev\WcComposableProduct\CartHandler->calculate_cart_item_price()')); + self::assertNotFalse(has_action('woocommerce_single_product_summary', 'Magdev\WcComposableProduct\CartHandler->render_product_selector()')); + self::assertNotFalse(has_filter('woocommerce_is_purchasable', 'Magdev\WcComposableProduct\CartHandler->hide_default_add_to_cart()')); + } + + public function testHideDefaultAddToCart_ReturnsFalseForComposable(): void + { + $handler = new CartHandler(); + $product = $this->createProductMock(['get_type' => 'composable']); + + $result = $handler->hide_default_add_to_cart(true, $product); + $this->assertFalse($result); + } + + public function testHideDefaultAddToCart_PassesThroughForSimple(): void + { + $handler = new CartHandler(); + $product = $this->createProductMock(['get_type' => 'simple']); + + $result = $handler->hide_default_add_to_cart(true, $product); + $this->assertTrue($result); + } + + public function testValidateAddToCart_PassesThroughForNonComposable(): void + { + $product = $this->createProductMock(['get_type' => 'simple']); + Functions\expect('wc_get_product')->with(1)->andReturn($product); + + $handler = new CartHandler(); + $result = $handler->validate_add_to_cart(true, 1, 1); + + $this->assertTrue($result); + } + + public function testValidateAddToCart_ReturnsFalseWhenNoProductsSelected(): void + { + $product = $this->createProductMock(['get_type' => 'composable']); + Functions\expect('wc_get_product')->with(1)->andReturn($product); + Functions\expect('wc_add_notice')->once(); + + $_POST['composable_products'] = []; + + $handler = new CartHandler(); + $result = $handler->validate_add_to_cart(true, 1, 1); + + $this->assertFalse($result); + } + + public function testValidateAddToCart_ReturnsFalseWhenNoPostData(): void + { + $product = $this->createProductMock(['get_type' => 'composable']); + Functions\expect('wc_get_product')->with(1)->andReturn($product); + Functions\expect('wc_add_notice')->once(); + + // No $_POST['composable_products'] at all + $handler = new CartHandler(); + $result = $handler->validate_add_to_cart(true, 1, 1); + + $this->assertFalse($result); + } + + public function testAddCartItemData_AddsSelectionsForComposable(): void + { + $product = $this->createProductMock(['get_type' => 'composable']); + Functions\expect('wc_get_product')->with(1)->andReturn($product); + Functions\expect('absint')->andReturnUsing(function ($val) { + return abs((int) $val); + }); + + $_POST['composable_products'] = ['101', '102']; + + $handler = new CartHandler(); + $result = $handler->add_cart_item_data([], 1); + + $this->assertArrayHasKey('composable_products', $result); + $this->assertSame([101, 102], $result['composable_products']); + $this->assertArrayHasKey('unique_key', $result); + } + + public function testAddCartItemData_PassesThroughForNonComposable(): void + { + $product = $this->createProductMock(['get_type' => 'simple']); + Functions\expect('wc_get_product')->with(1)->andReturn($product); + + $handler = new CartHandler(); + $result = $handler->add_cart_item_data(['existing' => 'data'], 1); + + $this->assertSame(['existing' => 'data'], $result); + } + + public function testGetCartItemFromSession_RestoresComposableProducts(): void + { + $handler = new CartHandler(); + $result = $handler->get_cart_item_from_session( + ['data' => 'test'], + ['composable_products' => [101, 102]] + ); + + $this->assertSame([101, 102], $result['composable_products']); + } + + public function testGetCartItemFromSession_PassesThroughWithoutComposableData(): void + { + $handler = new CartHandler(); + $result = $handler->get_cart_item_from_session( + ['data' => 'test'], + [] + ); + + $this->assertArrayNotHasKey('composable_products', $result); + } + + public function testDisplayCartItemData_FormatsProductNames(): void + { + $mock1 = $this->createProductMock(['get_name' => 'Product A']); + $mock2 = $this->createProductMock(['get_name' => 'Product B']); + + Functions\expect('wc_get_product') + ->andReturnUsing(function ($id) use ($mock1, $mock2) { + return match ($id) { + 101 => $mock1, + 102 => $mock2, + default => false, + }; + }); + + $handler = new CartHandler(); + $result = $handler->display_cart_item_data( + [], + ['composable_products' => [101, 102]] + ); + + $this->assertCount(1, $result); + $this->assertStringContainsString('Product A', $result[0]['value']); + $this->assertStringContainsString('Product B', $result[0]['value']); + } + + public function testDisplayCartItemData_ReturnsEmptyForNonComposable(): void + { + $handler = new CartHandler(); + $result = $handler->display_cart_item_data([], []); + + $this->assertSame([], $result); + } +} diff --git a/tests/Unit/PluginTest.php b/tests/Unit/PluginTest.php new file mode 100644 index 0000000..a836c20 --- /dev/null +++ b/tests/Unit/PluginTest.php @@ -0,0 +1,72 @@ +getProperty('instance'); + $property->setAccessible(true); + $property->setValue(null, null); + } + + public function testInstance_ReturnsSingleton(): void + { + $instance1 = Plugin::instance(); + $instance2 = Plugin::instance(); + + $this->assertSame($instance1, $instance2); + } + + public function testInstance_ReturnsPluginClass(): void + { + $instance = Plugin::instance(); + + $this->assertInstanceOf(Plugin::class, $instance); + } + + public function testAddProductType_AddsComposableToTypes(): void + { + $plugin = Plugin::instance(); + $types = $plugin->add_product_type([]); + + $this->assertArrayHasKey('composable', $types); + } + + public function testProductClass_ReturnsCustomClassForComposable(): void + { + $plugin = Plugin::instance(); + $class = $plugin->product_class('WC_Product', 'composable'); + + $this->assertSame('Magdev\WcComposableProduct\ProductType', $class); + } + + public function testProductClass_PassesThroughForOtherTypes(): void + { + $plugin = Plugin::instance(); + $class = $plugin->product_class('WC_Product', 'simple'); + + $this->assertSame('WC_Product', $class); + } + + public function testGetTwig_ReturnsTwigEnvironment(): void + { + $plugin = Plugin::instance(); + + $this->assertInstanceOf(\Twig\Environment::class, $plugin->get_twig()); + } +} diff --git a/tests/Unit/ProductTypeTest.php b/tests/Unit/ProductTypeTest.php new file mode 100644 index 0000000..3ca5a61 --- /dev/null +++ b/tests/Unit/ProductTypeTest.php @@ -0,0 +1,218 @@ + $value) { + $product->update_meta_data($key, $value); + } + return $product; + } + + public function testGetType_ReturnsComposable(): void + { + $product = $this->createProductType(); + $this->assertSame('composable', $product->get_type()); + } + + public function testIsPurchasable_ReturnsTrue(): void + { + $product = $this->createProductType(); + $this->assertTrue($product->is_purchasable()); + } + + public function testIsSoldIndividually_ReturnsTrue(): void + { + $product = $this->createProductType(); + $this->assertTrue($product->is_sold_individually()); + } + + public function testGetSelectionLimit_UsesProductMeta(): void + { + Functions\expect('absint')->once()->andReturnUsing(function ($val) { + return abs((int) $val); + }); + + $product = $this->createProductType(['_composable_selection_limit' => '3']); + $this->assertSame(3, $product->get_selection_limit()); + } + + public function testGetSelectionLimit_FallsBackToGlobalDefault(): void + { + Functions\expect('get_option') + ->once() + ->with('wc_composable_default_limit', 5) + ->andReturn(7); + + Functions\expect('absint')->once()->andReturnUsing(function ($val) { + return abs((int) $val); + }); + + $product = $this->createProductType(); + $this->assertSame(7, $product->get_selection_limit()); + } + + public function testGetSelectionLimit_FallsBackToHardDefault(): void + { + Functions\expect('get_option') + ->once() + ->with('wc_composable_default_limit', 5) + ->andReturn(5); + + Functions\expect('absint')->once()->andReturnUsing(function ($val) { + return abs((int) $val); + }); + + $product = $this->createProductType(); + $this->assertSame(5, $product->get_selection_limit()); + } + + public function testGetPricingMode_UsesProductMeta(): void + { + $product = $this->createProductType(['_composable_pricing_mode' => 'fixed']); + $this->assertSame('fixed', $product->get_pricing_mode()); + } + + public function testGetPricingMode_FallsBackToGlobalDefault(): void + { + Functions\expect('get_option') + ->once() + ->with('wc_composable_default_pricing', 'sum') + ->andReturn('sum'); + + $product = $this->createProductType(); + $this->assertSame('sum', $product->get_pricing_mode()); + } + + public function testShouldIncludeUnpublished_PerProductYes(): void + { + $product = $this->createProductType(['_composable_include_unpublished' => 'yes']); + $this->assertTrue($product->should_include_unpublished()); + } + + public function testShouldIncludeUnpublished_PerProductNo(): void + { + $product = $this->createProductType(['_composable_include_unpublished' => 'no']); + $this->assertFalse($product->should_include_unpublished()); + } + + public function testShouldIncludeUnpublished_FallsBackToGlobalYes(): void + { + Functions\expect('get_option') + ->once() + ->with('wc_composable_include_unpublished', 'no') + ->andReturn('yes'); + + $product = $this->createProductType(); + $this->assertTrue($product->should_include_unpublished()); + } + + public function testShouldIncludeUnpublished_FallsBackToGlobalNo(): void + { + Functions\expect('get_option') + ->once() + ->with('wc_composable_include_unpublished', 'no') + ->andReturn('no'); + + $product = $this->createProductType(); + $this->assertFalse($product->should_include_unpublished()); + } + + public function testGetSelectionCriteria_DefaultsToCategory(): void + { + $product = $this->createProductType(); + $criteria = $product->get_selection_criteria(); + + $this->assertSame('category', $criteria['type']); + $this->assertSame([], $criteria['categories']); + $this->assertSame([], $criteria['tags']); + $this->assertSame('', $criteria['skus']); + } + + public function testGetSelectionCriteria_UsesProductMeta(): void + { + $product = $this->createProductType([ + '_composable_criteria_type' => 'tag', + '_composable_tags' => [5, 10], + ]); + $criteria = $product->get_selection_criteria(); + + $this->assertSame('tag', $criteria['type']); + $this->assertSame([5, 10], $criteria['tags']); + } + + public function testCalculateComposedPrice_FixedMode(): void + { + $product = $this->createProductType(['_composable_pricing_mode' => 'fixed']); + + // Set regular price via the stub's data property + $reflection = new \ReflectionClass($product); + $dataProp = $reflection->getProperty('data'); + $dataProp->setAccessible(true); + $data = $dataProp->getValue($product); + $data['regular_price'] = '25.00'; + $dataProp->setValue($product, $data); + + $price = $product->calculate_composed_price([101, 102]); + $this->assertSame(25.0, $price); + } + + public function testCalculateComposedPrice_SumMode(): void + { + Functions\expect('get_option') + ->with('wc_composable_default_pricing', 'sum') + ->andReturn('sum'); + + $mock1 = $this->createProductMock(['get_price' => '5.00']); + $mock2 = $this->createProductMock(['get_price' => '7.50']); + + Functions\expect('wc_get_product') + ->andReturnUsing(function ($id) use ($mock1, $mock2) { + return match ($id) { + 101 => $mock1, + 102 => $mock2, + default => false, + }; + }); + + $product = $this->createProductType(); + $price = $product->calculate_composed_price([101, 102]); + + $this->assertSame(12.5, $price); + } + + public function testCalculateComposedPrice_SumMode_SkipsInvalidProducts(): void + { + Functions\expect('get_option') + ->with('wc_composable_default_pricing', 'sum') + ->andReturn('sum'); + + $mock1 = $this->createProductMock(['get_price' => '5.00']); + + Functions\expect('wc_get_product') + ->andReturnUsing(function ($id) use ($mock1) { + return match ($id) { + 101 => $mock1, + default => false, + }; + }); + + $product = $this->createProductType(); + $price = $product->calculate_composed_price([101, 999]); + + $this->assertSame(5.0, $price); + } +} diff --git a/tests/Unit/StockManagerTest.php b/tests/Unit/StockManagerTest.php new file mode 100644 index 0000000..f7d412a --- /dev/null +++ b/tests/Unit/StockManagerTest.php @@ -0,0 +1,226 @@ +manager = new StockManager(); + } + + // --- validate_stock_availability --- + + public function testValidateStock_ReturnsTrueWhenAllInStock(): void + { + $mock = $this->createProductMock([ + 'managing_stock' => false, + 'is_in_stock' => true, + ]); + + Functions\expect('wc_get_product')->with(1)->andReturn($mock); + Functions\expect('wc_get_product')->with(2)->andReturn($mock); + + $result = $this->manager->validate_stock_availability([1, 2]); + $this->assertTrue($result); + } + + public function testValidateStock_ReturnsTrueWhenNotManagingStock(): void + { + $mock = $this->createProductMock(['managing_stock' => false]); + + Functions\expect('wc_get_product')->with(1)->andReturn($mock); + + $result = $this->manager->validate_stock_availability([1]); + $this->assertTrue($result); + } + + public function testValidateStock_ReturnsErrorForOutOfStock(): void + { + $mock = $this->createProductMock([ + 'managing_stock' => true, + 'is_in_stock' => false, + 'get_name' => 'Widget', + ]); + + Functions\expect('wc_get_product')->with(1)->andReturn($mock); + + $result = $this->manager->validate_stock_availability([1]); + $this->assertIsString($result); + $this->assertStringContainsString('Widget', $result); + } + + public function testValidateStock_ReturnsErrorForInsufficientQuantity(): void + { + $mock = $this->createProductMock([ + 'managing_stock' => true, + 'is_in_stock' => true, + 'get_stock_quantity' => 1, + 'get_name' => 'Widget', + 'backorders_allowed' => false, + ]); + + Functions\expect('wc_get_product')->with(1)->andReturn($mock); + + $result = $this->manager->validate_stock_availability([1], 5); + $this->assertIsString($result); + $this->assertStringContainsString('Widget', $result); + } + + public function testValidateStock_PassesWhenBackordersAllowed(): void + { + // When stock_quantity is null the insufficient-stock check is skipped, + // and the backorders_allowed() branch is reached. + $mock = $this->createProductMock([ + 'managing_stock' => true, + 'is_in_stock' => true, + 'get_stock_quantity' => null, + 'backorders_allowed' => true, + ]); + + Functions\expect('wc_get_product')->with(1)->andReturn($mock); + + $result = $this->manager->validate_stock_availability([1], 5); + $this->assertTrue($result); + } + + public function testValidateStock_SkipsNullProducts(): void + { + Functions\expect('wc_get_product')->with(999)->andReturn(false); + + $result = $this->manager->validate_stock_availability([999]); + $this->assertTrue($result); + } + + // --- get_product_stock_info --- + + public function testGetProductStockInfo_ReturnsCorrectStructure(): void + { + $mock = $this->createProductMock([ + 'is_in_stock' => true, + 'get_stock_quantity' => 10, + 'backorders_allowed' => false, + 'get_stock_status' => 'instock', + 'managing_stock' => true, + ]); + + Functions\expect('wc_get_product')->with(1)->andReturn($mock); + + $info = $this->manager->get_product_stock_info(1); + + $this->assertTrue($info['in_stock']); + $this->assertSame(10, $info['stock_quantity']); + $this->assertFalse($info['backorders_allowed']); + $this->assertSame('instock', $info['stock_status']); + $this->assertTrue($info['managing_stock']); + $this->assertTrue($info['has_enough_stock']); + } + + public function testGetProductStockInfo_ReturnsFallbackForInvalidProduct(): void + { + Functions\expect('wc_get_product')->with(999)->andReturn(false); + + $info = $this->manager->get_product_stock_info(999); + + $this->assertFalse($info['in_stock']); + $this->assertSame(0, $info['stock_quantity']); + $this->assertFalse($info['backorders_allowed']); + $this->assertSame('outofstock', $info['stock_status']); + } + + public function testGetProductStockInfo_HasEnoughStockTrueWhenNotManaging(): void + { + $mock = $this->createProductMock([ + 'managing_stock' => false, + 'get_stock_quantity' => null, + ]); + + Functions\expect('wc_get_product')->with(1)->andReturn($mock); + + $info = $this->manager->get_product_stock_info(1, 100); + $this->assertTrue($info['has_enough_stock']); + } + + public function testGetProductStockInfo_HasEnoughStockFalseWhenInsufficient(): void + { + $mock = $this->createProductMock([ + 'managing_stock' => true, + 'get_stock_quantity' => 2, + ]); + + Functions\expect('wc_get_product')->with(1)->andReturn($mock); + + $info = $this->manager->get_product_stock_info(1, 5); + $this->assertFalse($info['has_enough_stock']); + } + + // --- prevent_composable_stock_reduction --- + + public function testPreventStockReduction_ReturnsFalseForComposableItem(): void + { + $productMock = $this->createProductMock(['get_type' => 'composable']); + + $itemMock = \Mockery::mock('WC_Order_Item_Product'); + $itemMock->shouldReceive('get_product')->andReturn($productMock); + + $orderMock = \Mockery::mock('WC_Order'); + $orderMock->shouldReceive('get_items')->andReturn([$itemMock]); + + $result = $this->manager->prevent_composable_stock_reduction(true, $orderMock); + $this->assertFalse($result); + } + + public function testPreventStockReduction_PassesThroughForNonComposable(): void + { + $productMock = $this->createProductMock(['get_type' => 'simple']); + + $itemMock = \Mockery::mock('WC_Order_Item_Product'); + $itemMock->shouldReceive('get_product')->andReturn($productMock); + + $orderMock = \Mockery::mock('WC_Order'); + $orderMock->shouldReceive('get_items')->andReturn([$itemMock]); + + $result = $this->manager->prevent_composable_stock_reduction(true, $orderMock); + $this->assertTrue($result); + } + + // --- store_selected_products_in_order --- + + public function testStoreSelectedProducts_AddsMetaWhenPresent(): void + { + $itemMock = \Mockery::mock('WC_Order_Item_Product'); + $itemMock->shouldReceive('add_meta_data') + ->once() + ->with('_composable_products', [1, 2], true); + + $this->manager->store_selected_products_in_order( + $itemMock, + 'cart_key', + ['composable_products' => [1, 2]] + ); + } + + public function testStoreSelectedProducts_DoesNothingWithoutData(): void + { + $itemMock = \Mockery::mock('WC_Order_Item_Product'); + $itemMock->shouldNotReceive('add_meta_data'); + + $this->manager->store_selected_products_in_order( + $itemMock, + 'cart_key', + [] + ); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..127bded --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,33 @@ +cart_contents; + } + + public function set_cart_contents($contents) { + $this->cart_contents = $contents; + } +} diff --git a/tests/stubs/class-wc-data.php b/tests/stubs/class-wc-data.php new file mode 100644 index 0000000..4cdcd00 --- /dev/null +++ b/tests/stubs/class-wc-data.php @@ -0,0 +1,35 @@ + 0) { + $this->id = (int) $id; + } + } + + public function get_id() { + return $this->id; + } + + public function set_id($id) { + $this->id = (int) $id; + } + + public function get_meta($key, $single = true, $context = 'view') { + return $this->meta_data[$key] ?? ($single ? '' : []); + } + + public function update_meta_data($key, $value, $meta_id = 0) { + $this->meta_data[$key] = $value; + } + + public function save() { + return $this->get_id(); + } +} diff --git a/tests/stubs/class-wc-order-item-product.php b/tests/stubs/class-wc-order-item-product.php new file mode 100644 index 0000000..67ed12f --- /dev/null +++ b/tests/stubs/class-wc-order-item-product.php @@ -0,0 +1,28 @@ +product; + } + + public function set_product($product) { + $this->product = $product; + } + + public function get_quantity() { + return $this->quantity; + } + + public function set_quantity($quantity) { + $this->quantity = $quantity; + } + + public function add_meta_data($key, $value, $unique = false) { + $this->meta_data[$key] = $value; + } +} diff --git a/tests/stubs/class-wc-order.php b/tests/stubs/class-wc-order.php new file mode 100644 index 0000000..4a82c81 --- /dev/null +++ b/tests/stubs/class-wc-order.php @@ -0,0 +1,24 @@ +items; + } + + public function set_items($items) { + $this->items = $items; + } + + public function add_order_note($note) { + $this->order_notes[] = $note; + } + + public function get_order_notes() { + return $this->order_notes; + } +} diff --git a/tests/stubs/class-wc-product.php b/tests/stubs/class-wc-product.php new file mode 100644 index 0000000..72f866a --- /dev/null +++ b/tests/stubs/class-wc-product.php @@ -0,0 +1,88 @@ + '', + 'price' => '', + 'regular_price' => '', + 'status' => 'publish', + ]; + + public function get_type() { + return 'simple'; + } + + public function get_name($context = 'view') { + return $this->data['name'] ?? ''; + } + + public function get_price($context = 'view') { + return $this->data['price'] ?? ''; + } + + public function get_regular_price($context = 'view') { + return $this->data['regular_price'] ?? ''; + } + + public function get_price_html() { + return ''; + } + + public function get_permalink() { + return ''; + } + + public function get_image_id($context = 'view') { + return 0; + } + + public function get_stock_quantity($context = 'view') { + return null; + } + + public function get_stock_status($context = 'view') { + return 'instock'; + } + + public function get_children() { + return []; + } + + public function is_type($type) { + return $this->get_type() === $type; + } + + public function is_purchasable() { + return true; + } + + public function is_in_stock() { + return true; + } + + public function managing_stock() { + return false; + } + + public function backorders_allowed() { + return false; + } + + public function is_sold_individually() { + return false; + } + + public function set_price($price) { + $this->data['price'] = $price; + } + + public function set_stock_quantity($quantity) { + } + + public function supports($feature) { + return in_array($feature, $this->supports, true); + } +} diff --git a/tests/stubs/class-wc-settings-page.php b/tests/stubs/class-wc-settings-page.php new file mode 100644 index 0000000..008bd02 --- /dev/null +++ b/tests/stubs/class-wc-settings-page.php @@ -0,0 +1,29 @@ +id; + } + + public function get_label() { + return $this->label; + } + + public function get_settings() { + return []; + } + + public function output() { + } + + public function save() { + } +} diff --git a/wc-composable-product.php b/wc-composable-product.php index b43c8a8..c36a46a 100644 --- a/wc-composable-product.php +++ b/wc-composable-product.php @@ -4,7 +4,7 @@ * Plugin Name: WooCommerce Composable Products * Plugin URI: https://src.bundespruefstelle.ch/magdev/wc-composable-product * Description: Create composable products where customers select a limited number of items from a configurable set - * Version: 1.3.0 + * Version: 1.3.1 * Author: Marco Graetsch * Author URI: https://src.bundespruefstelle.ch/magdev * License: GPL v3 or later @@ -20,7 +20,7 @@ defined('ABSPATH') || exit; // Define plugin constants -define('WC_COMPOSABLE_PRODUCT_VERSION', '1.3.0'); +define('WC_COMPOSABLE_PRODUCT_VERSION', '1.3.1'); define('WC_COMPOSABLE_PRODUCT_FILE', __FILE__); define('WC_COMPOSABLE_PRODUCT_PATH', plugin_dir_path(__FILE__)); define('WC_COMPOSABLE_PRODUCT_URL', plugin_dir_url(__FILE__));