WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 8 days ago

#42098 closed enhancement (fixed)

Simplify output tests with expectOutputString()

Reported by: birgire Owned by: johnbillion
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: Cc:

Description

PHPUnit has methods to test output, e.g.:

expectOutputString()
expectOutputRegex()

https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.output

We could use them to simplify tests.

Example:

Before:

ob_start();
the_post_thumbnail();
$actual = ob_get_clean();
$this->assertEquals( '', $actual );

After:

$this->expectOutputString( '' );
the_post_thumbnail();


Currently used in files:

tests/phpunit/tests/general/template.php
tests/phpunit/tests/general/document-title.php
tests/phpunit/tests/general/resourceHints.php
tests/phpunit/tests/oembed/WpEmbed.php

We could scope this ticket to e.g. the files:

tests/phpunit/tests/post/thumbnails.php
tests/phpunit/tests/post/listPages.php
tests/phpunit/tests/user/listAuthors.php
tests/phpunit/tests/functions/getArchives.php
tests/phpunit/tests/taxonomy.php

to begin with.

Attachments (1)

42098.diff (5.3 KB) - added by birgire 2 months ago.

Download all attachments as: .zip

Change History (4)

@birgire
2 months ago

#1 @birgire
2 months ago

  • Keywords has-patch added

In 42098.diff simplifies output tests in:

tests/phpunit/tests/post/thumbnails.php
tests/phpunit/tests/post/listPages.php
tests/phpunit/tests/user/listAuthors.php
tests/phpunit/tests/functions/getArchives.php
tests/phpunit/tests/taxonomy.php

#2 @johnbillion
8 days ago

  • Milestone changed from Awaiting Review to 5.0
  • Owner set to johnbillion
  • Status changed from new to reviewing

#3 @johnbillion
8 days ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 42382:

Build/Test tools: Switch to PHPUnit's expectOutputString() method instead of manually using output buffers for output assertions.

Props birgire
Fixes #42098

Note: See TracTickets for help on using tickets.