Skip to content

Instantly share code, notes, and snippets.

@sirbrillig
Created January 15, 2016 04:19
Show Gist options
  • Save sirbrillig/55fa8901c0363023b612 to your computer and use it in GitHub Desktop.
Save sirbrillig/55fa8901c0363023b612 to your computer and use it in GitHub Desktop.
Throw Exception in WP_Mock when handle_function fails
<?php
class SomeClass {
public function do_something( $times ) {
$user = wp_get_current_user();
//...
return true;
}
}
class MyTestClass extends PHPUnit_Framework_TestCase {
public function setUp() {
\WP_Mock::setUp();
$this->something = new SomeClass();
}
public function tearDown() {
\WP_Mock::tearDown();
}
public function test_do_something() {
\WP_Mock::wpFunction( 'wp_get_current_user' );
$this->assertTrue( $this->something->do_something( 1 ) );
}
public function test_do_something_again() {
$this->assertTrue( $this->something->do_something( 2 ) ); // This should cause an error but does not if run after the previous test
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment