Commit graph

7 commits

Author SHA1 Message Date
Alangi Derick
8221a7a4f2 Remove array_unique() on expected classes in checkAutoLoadConf()
Sometimes classes can be loaded via autoload (PSR-4) and class_aliasing
and due to this calling array_unique() on expected classes will remove
one of these classes due to them sharing the same file (and array_unique()
works on array values).

Also allow for ::class suffixed classes to be namespaced (ie look for \
in the regexes)

Cleanup some of the regexes, remove redunant code (don't need multi cased
letters when we have /i), simplify them

Bug: T206728
Change-Id: I235274d579b1bfd12a448448ddf020546c9aa89b
2018-11-30 00:22:06 +00:00
Brad Jorsch
ca3789a271 AutoloadGenerator: Filter PSR4-compliant classes instead of ignoring directories
Per discussion in T166010, we're going to handle class aliases (e.g. for
BC) by including the class_alias() call in the same file as the target
class. When the target class is a PSR4-compliant class, we still need to
pick up that alias for inclusion in autoload.php.

Thus, instead of excluding whole directories, we need to process the
files and filter out only those found classes that are PSR4 compliant.

Bug: T204983
Change-Id: I1c516998df368531c90ea54acc5be8be96e1db6c
2018-09-20 15:15:27 -04:00
Hashar
afb2269cb9 Revert "Use pathinfo() in AutoLoaderStructureTest::testPSR4Completeness"
This reverts commit 634c2ec2af.

Reason for revert: that strips the PSR4 directories from the class.

Example:
$dir BlueSpiceFoundation/src/"
$file BlueSpiceFoundation/src/ConfigDefinition/IntSetting.php

$abbrFileName: IntSetting
$expectedClassName: BlueSpice\IntSetting

$abbrFileName should be relative to $dir and not just the filename.

Bug: T198077
Change-Id: Ie934e309fee0392439b4e26d86249f0650e5ea67
2018-06-25 12:38:07 +00:00
Antoine Musso
634c2ec2af Use pathinfo() in AutoLoaderStructureTest::testPSR4Completeness
When setting AutoloadNamespaces to './' in extension.json, the test
AutoLoaderStructureTest::testPSR4Completeness would fail. The directory
path is not made canonical while the file is, which causes the substr()
call being used to strip too many characters. For example:

  $dir : /mediawiki/extensions/Wikidata.org/./
  $file: /mediawiki/extensions/Wikidata.org/Hooks.php

$abbrFileName = substr( substr( $file, strlen( $dir ) ), 0, -4 );
>>> oks

Use pathinfo() to parse the filename. Yields 'Hooks' as expected.

Bug: T198077
Change-Id: Ia8a11d87788b32ddb426a16a61b410b05ff5f15e
2018-06-25 11:47:52 +00:00
Kunal Mehta
b5e6da43e4 Don't autoload classes in AutoloadStructureTest
Autoloading classes is a 100% accurate way to ensure the autoloader
worked, but there are cases where if optional dependencies aren't
installed, then autoloading the class will fail. We can re-implement the
logic behind the PSR-4 autoloader, and ensure that classes will be
autoloadable by turning the filename into a class name, and making sure
that class name is the one we found in the file.

Bug: T195823
Change-Id: I5df378180e567c257386482383ef73812592f989
2018-05-29 11:09:57 -07:00
Kunal Mehta
e7ae019fc0 AutoLoaderStructureTest: Allow PSR-4 directories to have files with 0 classes
Files like ServiceWiring.php can be safely located in a PSR-4 autoloaded
directory, because they have no classes.

Change-Id: I359b305df9071d6bc5afe4b5f29e762041f4aaef
2018-05-26 16:51:56 -07:00
Kunal Mehta
e298f548f6 Split AutoloaderTest into a structure and class test
AutoloaderTest covers the AutoLoader class, and AutoLoaderStructureTest
covers the structure part of the test.

Change-Id: Ic4e7bfd670e1c3413631bda31260cc1cc825b1a2
2018-05-26 16:16:02 -07:00
Renamed from tests/phpunit/structure/AutoLoaderTest.php (Browse further)