Open mgubala-edge1s opened 1 year ago
hey @mgubala-edge1s thanks for getting in touch - support for PHP 8.1 should already exist as WP_Mock should work also in PHP 8.2 with the recent Mockery updates. As for PHPUnit 10, it's definitely under the radar but unfortunately can't give you an estimate for when support will be ready.
@mgubala-edge1s @unfulvio-godaddy From what I can tell phpunit 10 is already supported. If you install phpunit 10 and then you install 10up/wp_mock it will install the version 0.4.2 of 10up/wp_mock. This happens because the requirements for this version where PHPUnit >= 7 and now the later versions lock to PHPUnit v9. I only noticed this now when I was trying to debug an issue with php stubs for phpstan. It seems that the php stubs loaded were from 10up/wp_mock but version 0.4.2 which had incorrect docblocks for add_action instead of the stubs I wanted to use that were https://github.com/php-stubs/wordpress-stubs. I was able to fix that in my phpstan config by pointing to the correct stubs so they get loaded before 10up/wp_mock runs.
But regardless I am running the following versions of things (with phpunit 10 and do not seem to have any issues with 10up/wp_mock but I have not extensively used all the features, mostly just mocking functions, and expecting actions/filters)
10up/wp_mock 0.4.2 A mocking library to take the pain out of unit testing for WordPress
antecedent/patchwork 2.1.26 Method redefinition (monkey-patching) functionality for PHP.
brianium/paratest v7.3.1 Parallel testing for PHP
mockery/mockery 1.6.6 Mockery is a simple yet flexible PHP mock object framework
pestphp/pest v2.24.2 The elegant PHP Testing Framework.
pestphp/pest-plugin v2.1.1 The Pest plugin manager
pestphp/pest-plugin-arch v2.4.1 The Arch plugin for Pest PHP.
phpstan/phpdoc-parser 1.24.2 PHPDoc parser with support for nullable, intersection and generic types
phpunit/php-code-coverage 10.1.7 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator 4.1.0 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker 4.0.0 Invoke callables with a timeout
phpunit/php-text-template 3.0.1 Simple template engine.
phpunit/php-timer 6.0.0 Utility class for timing
phpunit/phpunit 10.4.2 The PHP Unit Testing framework.
I was able to get 1.0.0 installed with this in my composer.json and everything still appears to be working with phpunit 10.
"require-dev": {
"pestphp/pest": "^2.24",
"mockery/mockery": "^1.6",
"php-mock/php-mock-mockery": "^1.4",
"phpunit/phpunit": "10.4.2 as 9.6.0",
"10up/wp_mock": "^1.0.0"
},
To be honest I dont understand why composer wont install 1.0.0. The below extract from composer.json will install 0.4.2
"require-dev": {
"phpunit/phpunit": "^10",
"donatj/mock-webserver": "v2.7.1",
"wp-cli/wp-cli-bundle": "*",
"10up/wp_mock": "@dev"
}
If I change to wp_mock "1.0.0" the composer update fails with the message .
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires 10up/wp_mock 1.0.0 -> satisfiable by 10up/wp_mock[1.0.0].
- 10up/wp_mock 1.0.0 requires phpunit/phpunit ^9.6 -> found phpunit/phpunit[9.6.0, ..., 9.6.15] but it conflicts with your root composer.json require (^10).
Honestly semantic versioning means 10 exceeds ^9.6 and it should proceed..
@Narimm That is not how caret constraints work
https://jubianchi.github.io/semver-check/#/^9.6/10.0.0
My solution above is still working above
@tobeycodes solution seems the correct one for the time being
We will eventually support PHPUnit 10 natively -- please check this PR for helping with 8.3 (which PHPUnit 10 supports as well): https://github.com/10up/wp_mock/pull/237
That PR is looking good. It would be interesting if the project that consumes wp_mock can require php-stubs/wordpress-stubs that matches their WP version. I am not familiar enough to know if composer the best way to do that though.
I did play around with PHP Unit 10 on the trunk version of wp_mock and there are definitely some breaking changes that need to be resolved in wp_mock. When running the test suite some things are failing. I am guessing that within my specific project these features are not being used so the issues go unoticed, so I would definitely use my solution above with caution.
the stubs are only a dev dependency in WP Mock for PHPStan mostly so if you require WP_Mock, you are not including the stubs in your projects you can add those in your dev dependencies in your project's composer -- indeed there should be some compat work for achieving full PhpUnit 10 support
What should I do to make WP_Mock working well with PHPUnit 10?
Has there been any movement with PHPUnit 10? I'd like to use my current wp-env
setup with this, but they already use PHPUnit 10 in that Docker container.
@tobeycodes solution seems the correct one for the time being
We will eventually support PHPUnit 10 natively -- please check this PR for helping with 8.3 (which PHPUnit 10 supports as well): #237
https://github.com/10up/wp_mock/pull/237 was merged 10 months ago, what's left to do from there?
Feature request
WP_Mock is not compatible with PHPUnit 10 / PHP 8.1.
Proposed solution
Make it compatible. Maybe You have it already in plans?