Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Two times `@var \Drupal\Composer\VendorHardening\Config
` is used when this is incorrect namespace.
Also, `use Drupal\Composer\VendorHardening\Config
` is used once with the incorrect namespace.
The correct namespace is
\Drupal\Composer\Plugin\VendorHardening\Config
Proposed resolution
Correct the namespace
Remaining tasks
patch and review
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#6 | 3162479-6.patch | 2.95 KB | tedbow |
#6 | interdiff-4-6.txt | 1.88 KB | tedbow |
#2 | 3162479-2.patch | 1.07 KB | tedbow |
Comments
Comment #2
tedbow#3088730: Include 'composer' directory in phpcs scans as related but this error I don't think is caught by phpcs. I tested with another file in core.
Here is a fix.
Comment #3
tedbowComment #4
Kristen PolThanks for issue and patch.
1) Patch applies cleanly.
2) Tests pass.
3) See that
composer/Plugin/VendorHardening/Config.php
hasnamespace Drupal\Composer\Plugin\VendorHardening
which is what is noted in the issue summary.4) Searching for
@var \Drupal\Composer\VendorHardening\Config
returns:which are the items addressed in patch.
5) Searching for other uses of
Drupal\Composer\VendorHardening\Config
shows this one:So how does this test even work? Shouldn't it error out? Maybe I'm missing something.
Seems to me that
VendorHardeningPluginTest.php
needs updating so back to needs work. If so, the issue summary needs to be updated as well.Comment #5
Kristen PolComment #6
tedbowInteresting I would have thought it would error out too. It is not because.
If you add to the test:
use Drupal\IamNotReal;
and then later
print "class=" . IamNotReal::class;
It will print
"class=Drupal\IamNotReal"
If you don't add the use statement it would print out
"class=Drupal\Tests\Composer\Plugin\VendorHardening\IamNotReal"
which just uses the namespace of the current class.
but in either case if you actually try
new IamNotReal();
it will errorError : Class 'Drupal\Tests\Composer\Plugin\VendorHardening\IamNotReal' not found
or the other namespace.I guess this because using
::class
doesn't actually check the class exists.\PHPUnit\Framework\TestCase::getMockBuilder()
until it actually has to check something like if the original class or interface has a constructor or method.I tried changing
\Drupal\Tests\rest\Unit\Plugin\views\style\SerializerTest
I changed
This worked fine because it the original code is
So it doesn't do anything with the mock except
disableOriginalConstructor()
In the same class if I try the same with
It will fail because there is no
getContentType()
method.In our test there is
getPathsForPackage
doesn't exist butsetMethods()
sets it so it doesn't fail. Commenting out->setMethods(['getPathsForPackage'])
make it fail.If you fix the class namespace in the use statement you don't need
setMethods()
.We could fix this in this issue but it seems like a bigger problem with this test.
Anyways I have included it.
Comment #7
Kristen PolWow! Super weird. Thanks for playing with that.
1) I updated the issue summary to cover the
use Drupal\Composer\VendorHardening\Config;
issue.2) After applying new patch, there are no more
Drupal\Composer\VendorHardening\Config
references in the code as expected and the 3 places are changed toDrupal\Composer\Plugin\VendorHardening\Config
.3) If this passes tests, this looks good to me other than I'm not sure if the
->setMethods()
should be fixed here but I'll let the maintainers decide.Comment #8
Kristen PolRTBC now that tests are green and based on my last comment.
Comment #9
alexpottCommitted and pushed 82097e2ee3 to 9.1.x and d0b69bf612 to 9.0.x and bf44721fd6 to 8.9.x. Thanks!
Backported to 8.9.x as this is tests and documentation.