Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dkmyta committed Feb 7, 2025
1 parent 66de498 commit 94f2355
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,8 @@ public function render_page() {
*
* @param \WP_User $user The user.
* @param string $token The token.
*
* @return void
*/
public function render_content( \WP_User $user, string $token ): void {
public function render_content( \WP_User $user, string $token ) {
$transient_key = Config::TRANSIENT_PREFIX . "_error_{$user->ID}";
$error_message = get_transient( $transient_key );
delete_transient( $transient_key );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,19 @@ public function test_render_page_checks_2fa_code_successfully(): void {
$user->user_pass = 'pw';
$user->add_cap( 'publish_posts' );

$sut = $this->createPartialMock( Password_Detection::class, array( 'redirect_and_exit', 'load_user' ) );
$sut = $this->createPartialMock( Password_Detection::class, array( 'load_user', 'redirect_and_exit', 'render_content' ) );
$sut->expects( $this->once() )
->method( 'load_user' )
->with( 123 )
->willReturn( $user );
$sut->expects( $this->once() )
->method( 'redirect_and_exit' )
->with( 'http://example.org/wp-admin/' );
$sut->expects( $this->once() )
->method( 'render_content' )
->willReturn( null );

$calls = 0;
$calls = 0;
$call_counter = function () use ( &$calls ) {
++$calls;
return false;
Expand Down Expand Up @@ -249,11 +252,14 @@ public function test_render_page_sets_transient_error_if_2fa_code_is_wrong(): vo
$user->user_pass = 'pw';
$user->add_cap( 'publish_posts' );

$sut = $this->createPartialMock( Password_Detection::class, array( 'load_user' ) );
$sut = $this->createPartialMock( Password_Detection::class, array( 'load_user', 'render_content' ) );
$sut->expects( $this->once() )
->method( 'load_user' )
->with( 123 )
->willReturn( $user );
$sut->expects( $this->once() )
->method( 'render_content' )
->willReturn( null );

$sut->render_page();

Expand Down

0 comments on commit 94f2355

Please sign in to comment.