My Test includes the wp_verify_nonce and implemented that in OOP environment. Now the problem is: If verifyNonce() has no arguemnts passed, then i want to expect return false due to the function:
verifyNonce():
public function verifyNonce( $nonce ) {
if( ! function_exists( 'wp_verify_nonce') || empty( $nonce ) || !is_string( $nonce ) ) return false;
return wp_verify_nonce( $nonce, $this->action );
}
If $nonce is empty then it should return false since i passed this the if condition!
Now here i'm expecting that when there is no arguements passed, then it should return false:
testVerifyNonce():
public function testVerifyNonce() {
$action = 'my_action';
$nonce = '4832552f';
$myWPNonce = new test\MY_WP_Nonces( $action );
\WP_Mock::userFunction( 'wp_verify_nonce', array(
'times' => 3,
'return_in_order' => array(false, 1, 2)
) );
$this->assertFalse( $myWPNonce->verifyNonce() );
$this->assertEquals( 1, $myWPNonce->verifyNonce( $nonce ) );
$this->assertEquals( 2, $myWPNonce->verifyNonce( $nonce ) );
}
Here's the output of my bash console:
PHPUnit 5.1.7 by Sebastian Bergmann and contributors.
..E.... 7 / 7 (100%)
Time: 206 ms, Memory: 8.00Mb
There was 1 error:
1) MYWPNonce_Test::testVerifyNonce
Missing argument 1 for Mywpnonces\src\wpnonce\MY_WP_Nonces::verifyNonce(), called in /mnt/c/Users/hm/Desktop/Github/Mywpnonces/src/tests/wpnonceTest.php on line 76 and defined
/mnt/c/Users/hm/Desktop/Github/Mywpnonces/src/wpnonce.php:37
/mnt/c/Users/hm/Desktop/Github/Mywpnonces/src/tests/wpnonceTest.php:76
FAILURES!
Tests: 7, Assertions: 6, Errors: 1.