WordPress.org

Make WordPress Core

Changeset 52259


Ignore:
Timestamp:
11/27/2021 04:16:15 PM (7 weeks ago)
Author:
SergeyBiryukov
Message:

Tests: Use a simpler approach to test the output in some tests.

Instead of ignoring the output and catching it later with getActualOutput(), we can use expectOutputRegex() directly, which evaluates the output after the rest of the test code has run, if no unexpected errors were encountered.

Follow-up to [52173], [52253].

Props jrf.
See #53635, #53363.

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n.php

    r52253 r52259  
    408408        $this->factory()->post->create( $args );
    409409
    410         // Effectively ignore the output until retrieving it later via `getActualOutput()`.
    411         $this->expectOutputRegex( '`.`' );
    412 
    413410        $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do…';
     411        $this->expectOutputRegex( '/' . $expect . '/' );
     412
    414413        wp_dashboard_recent_drafts();
    415414
    416         $actual = $this->getActualOutput();
    417 
    418         restore_previous_locale();
    419 
    420         $this->assertMatchesRegularExpression( '/' . $expect . '/', $actual );
     415        restore_previous_locale();
    421416    }
    422417
     
    437432        $post = $this->factory()->post->create( $args );
    438433
    439         // Effectively ignore the output until retrieving it later via `getActualOutput()`.
    440         $this->expectOutputRegex( '`.`' );
    441 
    442434        $expect = 'Lorem ipsum dolor sit amet, consectetur …';
     435        $this->expectOutputRegex( '/' . $expect . '/' );
     436
    443437        wp_dashboard_recent_drafts();
    444438
    445         $actual = $this->getActualOutput();
    446 
    447         restore_previous_locale();
    448 
    449         $this->assertMatchesRegularExpression( '/' . $expect . '/', $actual );
     439        restore_previous_locale();
    450440    }
    451441
     
    466456        $this->factory()->post->create( $args );
    467457
    468         // Effectively ignore the output until retrieving it later via `getActualOutput()`.
    469         $this->expectOutputRegex( '`.`' );
    470 
    471458        $expect = str_repeat( 'あ', 40 ) . '…';
     459        $this->expectOutputRegex( '/' . $expect . '/' );
     460
    472461        wp_dashboard_recent_drafts();
    473462
    474         $actual = $this->getActualOutput();
    475 
    476         restore_previous_locale();
    477 
    478         $this->assertMatchesRegularExpression( '/' . $expect . '/', $actual );
     463        restore_previous_locale();
    479464    }
    480465
  • trunk/tests/phpunit/tests/widgets.php

    r52173 r52259  
    612612        );
    613613
    614         // Effectively ignore the output until retrieving it later via `getActualOutput()`.
    615         $this->expectOutputRegex( '`.`' );
     614        $this->expectOutputRegex( '/Test Title/' );
    616615
    617616        $widget->display_callback(
     
    625624        );
    626625
    627         $actual = $this->getActualOutput();
    628 
    629626        unregister_widget( $widget );
    630 
    631         $this->assertStringContainsString( 'Test Title', $actual );
    632627    }
    633628
Note: See TracChangeset for help on using the changeset viewer.