Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#42098 closed enhancement (fixed)

Simplify output tests with expectOutputString()

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

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 9 years ago.

Download all attachments as: .zip

Change History (5)

@birgire
9 years ago

#1 @birgire
9 years 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
9 years ago

  • Milestone Awaiting Review5.0
  • Owner set to johnbillion
  • Status newreviewing

#3 @johnbillion
9 years ago

  • Resolutionfixed
  • Status reviewingclosed

In 42382:

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

Props birgire
Fixes #42098

#4 @jorbin
8 years ago

  • Milestone 5.05.1
Note: See TracTickets for help on using tickets.