[wp-trac] [WordPress Trac] #53010: Tests: introduce namespacing for the test classes

WordPress Trac noreply at wordpress.org
Mon Aug 2 21:14:08 UTC 2021


#53010: Tests: introduce namespacing for the test classes
------------------------------+-------------------------------------
 Reporter:  jrf               |       Owner:  hellofromTonya
     Type:  task (blessed)    |      Status:  assigned
 Priority:  normal            |   Milestone:  5.9
Component:  Build/Test Tools  |     Version:
 Severity:  normal            |  Resolution:
 Keywords:  2nd-opinion       |     Focuses:  docs, coding-standards
------------------------------+-------------------------------------
Changes (by azaozz):

 * keywords:   => 2nd-opinion


Comment:

 > As the WordPress Core test suite is used not only by Core, but also by
 plugins and themes for integration tests, the test class namespacing
 should be reserved for ...

 Yeah, I'm not really sure introducing "partial" namespacing will have any
 benefits. As far as I understand it will create more of a "messy"
 situation where some names can be repeated and other cannot. This doesn't
 seem helpful to anybody.

 Looking at the benefits of namespacing
 [https://www.php.net/manual/en/language.namespaces.rationale.php as
 mentioned in the PHP manual], they aren't very appealing in many cases:

    1. Name collisions between code you create, and internal PHP
 classes/functions/constants or third-party classes/functions/constants.
    2. Ability to alias (or shorten) Extra_Long_Names designed to alleviate
 the first problem, improving readability of source code.

 So, at the basic level namespaces are good when:
 1. You want to name your function or class the same as an existing built-
 in function or class.
 2. You want to avoid using longer, more descriptive names.

 Both of these cases would signify a bad naming practice making the code
 less readable (confusing names) and less self-documenting.

 Looking at the "benefits" listed in this ticket description:

 1. This seems to be a non-issue. Finding a class or a function works very
 well in all IDEs and IDE type text editors I've seen. Most of them would
 also auto-complete the name for you.
 2. "Shorted file names" are not better! :) That's a disadvantage if
 anything.
 3. Has there ever been a need to mock PHP built-in functions in "local"
 code? What would that accomplish?
 4. This is a non-issue too. It will probably be easier to read and
 understand if the multiple test classes are named accordingly to what they
 do, i.e. self-documenting, descriptive names not short, non-descriptive,
 repeating names.

 In that terms I don't think introducing partial namespaces in the WP PHP
 tests is a good idea.

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


More information about the wp-trac mailing list