[wp-trac] [WordPress Trac] #53010: Tests: introduce namespacing for the test classes
WordPress Trac
noreply at wordpress.org
Wed Sep 18 19:55:22 UTC 2024
#53010: Tests: introduce namespacing for the test classes
-------------------------------------------------+-------------------------
Reporter: jrf | Owner:
| hellofromTonya
Type: task (blessed) | Status: assigned
Priority: normal | Milestone: Future
| Release
Component: Build/Test Tools | Version:
Severity: normal | Resolution:
Keywords: 2nd-opinion has-patch has-unit- | Focuses: docs,
tests | coding-standards
-------------------------------------------------+-------------------------
Comment (by hellofromTonya):
Hey @azaozz, fast-forwarding to today, this proposal is now part of #62004
"Test suite: update the tests for PHPUnit 10/11 and get ready for PHPUnit
12".
As I pointed out in comment:37, the renaming and splitting are now
requirements.
Replying to [comment:16 azaozz]:
> May be missing something but it seems the proposed "File paths" suggest
that each class should be split in up to 50 separate files, one per
method. Is that correct?
>
> If yes, could you please explain what are the benefits of having such
"file and directory layout" with several thousands of files instead of
100-200? Seems this would trigger a lot of needless disk i/o and slow down
running of the tests as most of the files will have to be loaded every
time the tests are run.
Let's start with the splitting of tests into 1 function / method per test
class / file.
Test coverage changes in PHPUnit are now the primary driver for splitting
the tests. The
[https://core.trac.wordpress.org/ticket/62004#Problem4:coversattributesareonlysupportedatclasslevelx2
full explanation is found here].
tl;dr
>we don't just need to split the test classes up by class, in actual fact,
we'll need to split them up to individual test classes for each method in
a class to still be able to measure code coverage correctly.
What are the test coverage changes driving this effort?
[https://core.trac.wordpress.org/ticket/62004#Problem4:coversattributesareonlysupportedatclasslevelx2
The full explanation is found here].
Replying to [comment:16 azaozz]:
> Also seems this is not recommended (compatible?) by [https://www.php-
fig.org/psr/psr-4/ PSR4]. It states that:
>
> A fully qualified class name has the following form:
> `\<NamespaceName>(\<SubNamespaceNames>)*\<ClassName>`
>
> (where "The terminating class name corresponds to a file name ending in
`.php`.").
Fast-forwarding to today,
[https://core.trac.wordpress.org/ticket/62004#Problem5:noneofthetestclassescomplywithPHPUnitnamingconventions
the recommendation now is to fully compatible with PHPUnit naming
conventions, which are "comply largely with PSR4 file name regulations"].
Why is renaming a requirement?
[https://core.trac.wordpress.org/ticket/62004#Problem5:noneofthetestclassescomplywithPHPUnitnamingconventions
As explained here], tests will not run on PHPUnit 11+ if they do not
comply with the naming conventions:
1. Class name` [SomethingUnderTest]Test` - take note of the Test suffix.
2. The file name for the test class MUST match the class name EXACTLY in a
case-sensitive manner.
An example:
Consider the test class `Tests_Compat_ArrayKeyLast` which is located in a
file named called `tests/compat/arrayKeyLast.php`.
What needs to change?
1. This class will need to be renamed to `Compat_ArrayKeyLast_Test`.
2. The file will need to be renamed to
`tests/compat/Compat_ArrayKeyLast_Test.php`.
Does that make sense?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53010#comment:39>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list