• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

10up / wp_mock / 13787625687 / 1
66%
master: 52%

Build:
Build:
LAST BUILD BRANCH: trunk
DEFAULT BRANCH: master
Ran 11 Mar 2025 12:08PM UTC
Files 22
Run time 3s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

11 Mar 2025 12:07PM UTC coverage: 66.01% (-0.4%) from 66.446%
13787625687.1

push

github

web-flow
Add support for `withAnyArgs` method for `onFilter` calls. (#256)

# Summary <!-- Required -->

This PR implements a new method called `withAnyArgs` for `onFilter`
calls. This method is particularly useful in test cases where we do not
care about the filter arguments passed in but just its return value like
so:

```php
WP_Mock::onFilter('custom_content_filter')
    ->withAnyArgs()
    ->reply('This is filtered')
```

### Closes: #156 

## Details <!-- Optional -->

I have introduced a static array called `$filtersWithAnyArgs` that
basically acts as an associative array for filter names mapped to random
integer values.

This array will help us store random integers at the point where the
`withAnyArgs` method is called, so that we can check for those later in
the `apply` method and accurately set our passed in args.

Run tests:

```php
vendor/bin/phpunit ./tests/Unit/WP_MockTest.php 
```

<img width="490" alt="Screenshot 2025-03-09 at 12 16 12"
src="https://github.com/user-attachments/assets/ad15136e-b3a6-4d77-a70e-e83a5a7c90e1"
/>

## 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 -->

Create class like so:

```php
namespace MyPlugin;

class MyClass
{
    public function filterContent() : string
    {
        return apply_filters('custom_content_filter', 'This is unfiltered');
    }
}
```

Create Test like so:

```php
use MyPlugin\MyClass;
use WP_Mock;
use WP_Mock\Tools\TestCase as TestCase;

final class MyClassTest extends TestCase
{
    public function testCanFilterContent() : void 
    {
        WP_Mock::onFilter('custom_content_filter')
            ->withAnyArgs()
            ->reply('This is filtered');

        $content = (new MyClass())->filt... (continued)

503 of 762 relevant lines covered (66.01%)

2.65 hits per line

Source Files on job 13787625687.1
  • Tree
  • List 22
  • Changed 1
  • Source Changed 0
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 13787625687
  • 268a7ada on github
  • Prev Job for on trunk (#13706662543.1)
  • Next Job for on trunk (#13787664706.1)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc