Commit 8d6c23d
# Summary <!-- Required -->
This PR implements a fix for an issue I discovered when using multiple
`onFilter` calls with the `withAnyArgs` method.
<img width="807" alt="Screenshot 2025-03-12 at 18 47 52"
src="https://github.com/user-attachments/assets/3c1bb38a-830a-4a4a-907c-a61b7f0d8e11"
/>
### Closes: #258
## Details <!-- Optional -->
While writing some unit test cases using the `withAnyArgs` method, I
came across issues for multiple `onFilter` calls introduced into the
tests. At the moment, if a single `onFilter` call is used alongside
`withAnyArgs`, it works correctly, but for multiple cases, it doesn't
correctly pass the tests. The expected behaviour should be that this
works for both single and multiple use cases using the `withAnyArgs`.
This PR fixes this issue correctly.
<img width="587" alt="Screenshot 2025-03-12 at 19 42 19"
src="https://github.com/user-attachments/assets/46cfd651-62a7-455b-9b58-257d38a78b84"
/>
---
Run tests:
```php
vendor/bin/phpunit ./tests/Unit/WP_MockTest.php
```
## Contributor checklist <!-- Required -->
- [x] I agree to follow this project's [**Code of
Conduct**](https://github.com/10up/.github/blob/trunk/CODE_OF_CONDUCT.md).
- [x] I have updated the documentation accordingly
- [x] I have added tests to cover changes introduced by this pull
request
- [x] All new and existing tests pass
## Testing <!-- Required -->
```php
public function testMultipleOnFilterPassesWithAnyArgs(): void
{
WP_Mock::bootstrap();
/** @phpstan-ignore-next-line */
WP_Mock::onFilter('testFilter1')
->withAnyArgs()
->reply('Filtered value 1');
/** @phpstan-ignore-next-line */
WP_Mock::onFilter('testFilter2')
->withAnyArgs()
->reply('Filtered value 2');
/** @phpstan-ignore-next-line */
WP_Mock::onFilter('testFilter3')
->withAnyArgs()
->reply('Filtered value 3');
$filtered_value1 = apply_filters('testFilter1', 'Original value 1');
$filtered_value2 = apply_filters('testFilter2', 'Original value 2');
$filtered_value3 = apply_filters('testFilter3', 'Original value 3');
$this->assertSame('Filtered value 1', $filtered_value1);
$this->assertSame('Filtered value 2', $filtered_value2);
$this->assertSame('Filtered value 3', $filtered_value3);
Mockery::close();
}
```
Run test, it should pass successfully multiple times using the
`withAnyArgs` method:
```bash
composer run test
```
<!-- List any configuration requirements for testing. -->
### Reviewer checklist <!-- Required -->
<!-- The following checklist is for the reviewer: add any steps that may
be relevant while reviewing this pull request -->
- [x] Code changes review
- [ ] Documentation changes review
- [x] Unit tests pass
- [x] Static analysis passes
---------
Co-authored-by: Ashley Gibson <99189195+agibson-godaddy@users.noreply.github.com>
1 parent f25b589 commit 8d6c23d
2 files changed
Lines changed: 42 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
365 | 404 | | |
0 commit comments