This is a follow up to
https://www.drupal.org/node/2782309#comment-11669209
In a PSR compliant way I want to find a better home for test specific traits.
A trait that can be used in Kernel, Function or maybe unit test for example the image module.
image
tests
src
Kernel
Functional
Unit
Trait <--- New Directory
I propose the trait directory is the ideal place to put ImageFieldCreationTrait but we need to makes changes for this to work.
Maybe phpunit is not the correct component for an autoloader discussion ... so please correct me.
Comments
Comment #2
martin107 commentedComment #3
pfrenssenMaybe we should call the directory
Traitsto be consistent withcore/tests/Drupal/Tests/Traits. I'm personally more in favor for the singularTraitthough.Comment #5
mile23Traits are supposed to be in module/tests/src/Traits/ with a namespace of Drupal\Tests\module\Traits\YourTraitHere.
That's how it's supposed to work, based on #2605664: [Needs change record updates] Align TestDiscovery and bootstrap.php's non-permissive loading of PSR-4 namespaces for traits Change record: https://www.drupal.org/node/2848889
An example here: #2803621: Break BrowserTestBase & children dependency on Simpletest, deprecate stub BC traits which has a change record that isn't published yet.
Comment #6
martin107 commented@Mile23, thanks for the definitive answer.. it is much appreciated.
cd core
find . -name *Trait.php | wc -l
120
ignoring the traits in core/modules/simpletest/src it will take a little effort :)
Thinking about the burden on the reviewer / committer.
Its seems wrong to break this into 20 or so small sub issues..
but if we follow cores's more conventional approach of ... fix it once and do it globally... It will be difficult to review.
That old chestnut...
I will start by doing the first 20 or so ... and others can dictate how I should proceed.
Comment #7
martin107 commentedI am happy to limit the scope of this issue to test traits [*TestTrait.php]
There are a couple of landmines here... for example BasicAuthTestTrait has a soon to be deprecated version and conventional trait already in its final resting place.
I think we should delay until
#2803621: Break BrowserTestBase & children dependency on Simpletest, deprecate stub BC traits
just to be safe
It will be disruptive and 8.5.x-dev was opening overnight...
./modules/basic_auth/src/Tests/BasicAuthTestTrait.php -- do not move
./modules/basic_auth/tests/src/Traits/BasicAuthTestTrait.php --- already in place.
./modules/book/tests/src/Functional/BookTestTrait.php
./modules/comment/src/Tests/CommentTestTrait.php
./modules/config/src/Tests/SchemaCheckTestTrait.php
./modules/field/src/Tests/EntityReference/EntityReferenceTestTrait.php
./modules/field_ui/src/Tests/FieldUiTestTrait.php
./modules/file/tests/src/Kernel/Migrate/d6/FileMigrationTestTrait.php
./modules/media/tests/src/Functional/MediaFunctionalTestTrait.php
./modules/migrate_drupal/src/Tests/StubTestTrait.php
./modules/rest/tests/src/Functional/AnonResourceTestTrait.php
./modules/rest/tests/src/Functional/BasicAuthResourceTestTrait.php
./modules/rest/tests/src/Functional/BcTimestampNormalizerUnixTestTrait.php
./modules/rest/tests/src/Functional/CookieResourceTestTrait.php
./modules/simpletest/src/SessionTestTrait.php
./modules/simpletest/tests/src/Traits/TestTrait.php
./modules/system/src/Tests/Entity/EntityDefinitionTestTrait.php
./modules/taxonomy/src/Tests/TaxonomyTestTrait.php
./modules/taxonomy/src/Tests/TaxonomyTranslationTestTrait.php
./modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php
./modules/taxonomy/tests/src/Functional/TaxonomyTranslationTestTrait.php
./modules/user/src/Tests/UserResetEmailTestTrait.php
./modules/views/tests/src/Unit/Plugin/HandlerTestTrait.php
./tests/Drupal/Tests/ConfigTestTrait.php
./tests/Drupal/Tests/SchemaCheckTestTrait.php
./tests/Drupal/Tests/SessionTestTrait.php
./tests/Drupal/Tests/Traits/Core/Config/SchemaConfigListenerTestTrait.php
Comment #8
martin107 commentedComment #10
kingdutchThe issue referenced in #7 has been fixed so I'm moving this back to Active. I think this would be cool to get in Drupal core because traits in Tests can be really useful and aren't always tied to a specific type of test :)
Comment #11
borisson_If we do this, we're going to have to deprecate all of those traits, that's not a big problem, we can't just move them.
Comment #12
mile23Sorry I was unclear in #5.
Traits which aren't shared between different types of tests can be anywhere as long as PSR-4 can find them. So leaving a trait in a \Functional\ namespace (or whatever applies) is fine, as long as only functional tests ever use it.
It's only the shared ones that should end up in \Traits\. Currently all the tests are working, so we don't need to move anything. If there are specific ones that need to be moved, we can move/deprecate them on a case-by-case basis.
Comment #24
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!