Bug report
I've started migrating code to use \WP_Mock\Functions::type() #254 but have run into an unusual failure.
When using \WP_Mock\Functions::type() in an array in \WP_Mock::expectActionAdded(), if the method name is used twice, it fails.
Replication steps
protected function wpMockSetStrictModeForTest(): void {
$property = new \ReflectionProperty( 'WP_Mock', '__strict_mode' );
$property->setAccessible( true );
$property->setValue( true );
}
// Fails.
public function testMultipleActionsTypeSameMethod(): void
{
$this->wpMockSetStrictModeForTest();
\WP_Mock::expectActionAdded(
'init',
array( \WP_Mock\Functions::type( \WP_Mock\Tests\Mocks\SampleClass::class ), 'action' )
);
\WP_Mock::expectActionAdded(
'init',
array( \WP_Mock\Functions::type( \WP_Mock\Tests\Mocks\SampleSubClass::class ), 'action' )
);
add_action( 'init', array( new \WP_Mock\Tests\Mocks\SampleClass(), 'action' ) );
add_action( 'init', array( new \WP_Mock\Tests\Mocks\SampleSubClass(), 'action' ) );
$this->assertConditionsMet();
}
// Passes.
public function testMultipleActionsTypeDistinctMethod(): void
{
$this->wpMockSetStrictModeForTest();
\WP_Mock::expectActionAdded(
'init',
array( \WP_Mock\Functions::type( \WP_Mock\Tests\Mocks\SampleClass::class ), 'action' )
);
\WP_Mock::expectActionAdded(
'init',
array( \WP_Mock\Functions::type( \WP_Mock\Tests\Mocks\SampleSubClass::class ), 'action2' )
);
add_action( 'init', array( new \WP_Mock\Tests\Mocks\SampleClass(), 'action' ) );
add_action( 'init', array( new \WP_Mock\Tests\Mocks\SampleSubClass(), 'action2' ) );
$this->assertConditionsMet();
}
phpunit --filter=testMultipleActions
Expected behavior
The method name should have no effect on the assertion.
// Passes.
public function testMultipleActionsAnyInstance(): void
{
$this->wpMockSetStrictModeForTest();
\WP_Mock::expectActionAdded(
'init',
array( new AnyInstance( \WP_Mock\Tests\Mocks\SampleClass::class ), 'action' )
);
\WP_Mock::expectActionAdded(
'init',
array( new AnyInstance( \WP_Mock\Tests\Mocks\SampleSubClass::class ), 'action' ),
);
add_action( 'init', array( new \WP_Mock\Tests\Mocks\SampleClass(), 'action' ) );
add_action( 'init', array( new \WP_Mock\Tests\Mocks\SampleSubClass(), 'action' ) );
$this->assertConditionsMet();
}
I haven't taken time to try fix this yet. Maybe @badasswp might know quickly what's up.
Bug report
I've started migrating code to use
\WP_Mock\Functions::type()#254 but have run into an unusual failure.When using
\WP_Mock\Functions::type()in an array in\WP_Mock::expectActionAdded(), if the method name is used twice, it fails.Replication steps
phpunit --filter=testMultipleActionsExpected behavior
The method name should have no effect on the assertion.
I haven't taken time to try fix this yet. Maybe @badasswp might know quickly what's up.