Skip to content

Instantly share code, notes, and snippets.

@ericmann
Created March 27, 2013 17:23
Show Gist options
  • Save ericmann/5256251 to your computer and use it in GitHub Desktop.
Save ericmann/5256251 to your computer and use it in GitHub Desktop.
<?php
class MyTestClass extends PHPUnit_Framework_TestCase {
public function setUp() {
\WP_Mock::setUp();
}
public function tearDown() {
\WP_Mock::tearDown();
}
public function test_content_filter() {
\WP_Mock::onFilter( 'the_content' )->with( 'Windows Rocks!' )->reply( 'Apple Rocks!' );
$content = 'Windows Rocks!';
$filtered = apply_filters( 'the_content', $content );
$this->assertEquals( 'Apple Rocks!', $filtered );
}
/**
* Our special_action function must actually invoke the 'special_action' action when it's done.
* function special_action() {
* // ... do stuff
* do_action( 'special_action' );
* }
*/
public function test_method_has_action() {
$hook_intercept = \Mockery::mock( 'intercept' );
$hook_intercept->shouldReceive( 'intercepted' );
\WP_Mock::onAction( 'special_action' )->with( null )->perform( array( $hook_intercept, 'intercepted' ) );
// If this function does not call `do_action( 'special_action' )`, the test will fail.
special_action();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment