Skip to content

Expectation on "times" required for withArgs #52

Description

@coreyworrell

What am I doing wrong here?

class Example
{
  public function __construct()
  {
    add_filter('template_include', [$this, 'template']);
  }
  
  public function template(string $template): string
  {
    return 'something';
  }
}

class ExampleTest extends TestCase
{
  protected function setUp(): void
  {
    parent::setUp();
    Brain\Monkey\setUp();
  }
  
  protected function tearDown(): void
  {
    Brain\Monkey\tearDown();
    parent::tearDown();
  }
  
  public function testExample()
  {
    Brain\Monkey\Filters\expectAdded('template_include')
      ->with('Example->template()');
    new Example;
  }
}

Returns

There was 1 error:

1) ExampleTest::testExample
Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_0::add_filter_template_include([0 => object(Example), 1 => 'template'], 10, 1). Either the method was unexpected or its arguments matched no expected argument list for this method

/.../vendor/mockery/mockery/library/Mockery/ExpectationDirector.php:92
/.../vendor/brain/monkey/src/Hook/HookExpectationExecutor.php:127
/.../vendor/brain/monkey/src/Hook/HookExpectationExecutor.php:64
/.../vendor/brain/monkey/inc/wp-hook-functions.php:35
/.../src/Example.php:24 (add_filter('template_include', [$this, 'template']))
/.../tests/ExampleTest.php:50 (new Example)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions