Skip to content

Commit

Permalink
chore: update doc usage notes
Browse files Browse the repository at this point in the history
  • Loading branch information
badasswp committed Feb 1, 2025
1 parent 34b2e0f commit 3fed0cb
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/usage/mocking-wp-action-and-filter-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,45 @@ final class MyClassTest extends TestCase
$this->assertEquals('Default', (new MyClass())->filterContent());
}
}
```

## Asserting that an object has been passed

To assert that an object has been added as an argument, you can perform assertions referencing the object's class type.

Take the code below, for example:

```php
namespace MyPlugin;

use MyPlugin\NewFolder\NewClass;

class MyClass
{
public function filterContent() : string
{
return apply_filters('custom_content_filter', new NewClass());
}
}
```

We can do this:

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

use MyPlugin\MyClass;
use MyPlugin\NewFolder\NewClass;

final class MyClassTest extends TestCase
{
public function testAnonymousObject() : void
{
WP_Mock::expectFilter('custom_content_filter', WP_Mock\Functions::type(NewClass::class));

$this->assertInstanceOf(NewClass::class, (new MyClass())->filterContent());
$this->assertConditionsMet();
}
}
```

0 comments on commit 3fed0cb

Please sign in to comment.