parsedown-extra
parsedown-extra copied to clipboard
Update composer.json
fix composer with warning:
Class ParsedownExtraTest located in ./vendor/erusev/parsedown-extra/test/ParsedownExtraTest.php does not comply with psr-0 autoloading standard. Skipping.
@erusev We need this merge!
Thanks for the PR.
How can I reproduce the issue? When I do composer require erusev/parsedown-extra
, I get no warning; I'm on composer 2.0.12
.
It happens specifically on composer dumpautoload
:
$ composer --version
Composer version 2.1.5 2021-07-23 10:35:47
$ composer dumpautoload
Generating optimized autoload files
Class ParsedownExtraTest located in ./vendor/erusev/parsedown-extra/test/ParsedownExtraTest.php does not comply with psr-0 autoloading standard. Skipping.
I believe its because the test classes don't have namespaces.
https://github.com/erusev/parsedown-extra/issues/156 https://github.com/erusev/parsedown-extra/issues/162
@erusev
This occurs specifically with the composer optimizer. You can replicate this by generating the autoloader with the optimize flag set -o
composer dump-autoload -o
Should output
Class ParsedownExtraTest located in ~/vendor/erusev/parsedown-extra\test\ParsedownExtraTest.php does not comply with psr-0 autoloading standard. Skipping.
Hope this helps
Can anyone explain why the same issue doesn't occur with Parsedown, which also uses psr-0
? Would help me understand the problem. Thanks!
the warning is about ParsedownExtraTest
not ParsedownExtra
, so the change is not related to the warning message.
@erusev
I believe PSR is wanting ParsedownTest
to be in the namespace test
since it resides in a directory of that name.
\test\ParsedownTest
Most other libraries will place the source files in the src directory and then instruct PSR to look inside there. That way the tests and other materials are kept out of the way.
So basically,
- create a src/ directory
- move Parsedown.php inside src/
- update composer.json to find the source file in there, eg:
"psr-0": {"Parsedown": "src"}
I haven't tested this, but it is the theoretical fix. I hope this helps.
@daftspunk this has nothing to do with Parsedown
or ParsedownExtra
class.
To fix this, namespaces of the classes in tests/
directory could be adjusted to use another autoloading strategy, e.g. putting them into a test\
namespace.
I still don't understand why the same issue doesn't occur with Parsedown, and now I have one more question, perhaps it's related:
Why does composer require erusev/parsedown-extra
add dev files to the vendor folder, including:tests/
, .travis.yml
, phpunit.xml.dist
? This doesn't happen for parsedown
(composer require erusev/parsedown
). What's different in parsedown-extra
?
Hey @erusev. Me again. I note that in both repos you are implementing the use of .gitattributes which are being instructed to ignore the test/
folder.
This will have an interesting effect, via composer:
- if you install the "source" version of a package, the
test/
folder will be included - if you install the "dist" version of a package, the
test/
folder won't be delivered, this is because the zip/tarball is made using git directives
This is likely why you are seeing inconsistent outcomes with equivalent packages.
Hey @daftspunk thanks for sharing your thoughts, but I still don't understand it.
In an empty folder, run composer require erusev/parsedown-extra
and you get both parsedown
and parsedown-extra
in vendor/
. One of them (parsedown-extra
) has a test/
folder and the other one (parsedown
) doesn't.
Why is that?
@erusev
That's because the latest tagged version of parsedown-extra
(v0.8.1) does not contain the .gitattributes file. See here: https://github.com/erusev/parsedown-extra/tree/91ac3ff98f0cea243bdccc688df43810f044dcef