[wp-trac] [WordPress Trac] #50267: Getting code coverage from phpunit?

WordPress Trac noreply at wordpress.org
Sun Aug 23 13:24:58 UTC 2020


#50267: Getting code coverage from phpunit?
------------------------------+---------------------
 Reporter:  mmarco9           |       Owner:  (none)
     Type:  defect (bug)      |      Status:  new
 Priority:  normal            |   Milestone:  5.6
Component:  Build/Test Tools  |     Version:  5.1
 Severity:  minor             |  Resolution:
 Keywords:  has-patch         |     Focuses:
------------------------------+---------------------
Changes (by jrf):

 * keywords:   => has-patch
 * version:   => 5.1
 * milestone:  Awaiting Review => 5.6


Comment:

 @mmarco9 I've looked into this and you are completely right.

 The standard `phpunit.xml.dist` and `tests/phpunit/multisite.xml` files,
 both set the `WP_RUN_CORE_TESTS` constant.

 With the `WP_RUN_CORE_TESTS` constant in place, the source code used for
 the unit tests is in the `build` directory created by running `npm run
 build`, not in the `src` directory.

 This is loosely related to the changes made in #43055.

 I'm attaching two patches to this ticket:

 == Patch 1

 A patch fixing code coverage setup in the `phpunit.xml.dist` file to point
 to the `build` directory which make the config consistent with the
 `WP_RUN_CORE_TESTS` being set to `1` in the same config file.

 This patch included updating the list, as added in #43067 / #43240 /
 [42665], to be in line with the current code base and excluding the
 plugins and themes included with WP Core from being considered for code-
 coverage.

 If people locally have a `phpunit.xml` file which changes the
 `WP_RUN_CORE_TESTS` constant to `0`, they would also - in their local file
 - have to change the code coverage setup to use the `src` directory.

 == Patch 2

 A patch to fix a number of malformed `@covers` tags. These will throw
 warnings in higher PHPUnit versions and will at some point no longer
 record the coverage properly (I haven't dug in for the exact PHPUnit
 version numbers).

 As per the [https://phpunit.readthedocs.io/en/7.5/annotations.html#covers
 documentation of the `@covers` tag], global functions being covered should
 be prefixed with `::`. Also, the `()` behind the function name is
 redundant.

 This patch is a follow-up on #39235.

 I'd also recommend for tests covering classes to be explicit about the
 fact that these are global classes by adding a `\` at the start, i.e.
 `@covers \SomeClass`, not  `@covers SomeClass`, but that is not included
 in the current patch.



 @SergeyBiryukov These are the two patches I mentioned yesterday.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50267#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list