parsedown-extra icon indicating copy to clipboard operation
parsedown-extra copied to clipboard

Update composer.json

Open wuwx opened this issue 3 years ago • 12 comments

fix composer with warning:

Class ParsedownExtraTest located in ./vendor/erusev/parsedown-extra/test/ParsedownExtraTest.php does not comply with psr-0 autoloading standard. Skipping.

wuwx avatar Mar 14 '21 13:03 wuwx

@erusev We need this merge!

LazyTechwork avatar Apr 19 '21 07:04 LazyTechwork

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.

erusev avatar Apr 19 '21 09:04 erusev

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

Wiejeben avatar Jul 29 '21 08:07 Wiejeben

@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

daftspunk avatar Aug 18 '21 02:08 daftspunk

Can anyone explain why the same issue doesn't occur with Parsedown, which also uses psr-0? Would help me understand the problem. Thanks!

erusev avatar Oct 25 '21 08:10 erusev

the warning is about ParsedownExtraTest not ParsedownExtra, so the change is not related to the warning message.

cebe avatar Nov 24 '21 00:11 cebe

@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,

  1. create a src/ directory
  2. move Parsedown.php inside src/
  3. 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 avatar Nov 24 '21 01:11 daftspunk

@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.

cebe avatar Nov 25 '21 00:11 cebe

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?

erusev avatar Nov 30 '21 11:11 erusev

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.

daftspunk avatar Dec 01 '21 04:12 daftspunk

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 avatar Dec 06 '21 09:12 erusev

@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

daftspunk avatar Dec 06 '21 22:12 daftspunk