Created
January 15, 2016 04:19
-
-
Save sirbrillig/55fa8901c0363023b612 to your computer and use it in GitHub Desktop.
Throw Exception in WP_Mock when handle_function fails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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