作曲器自动加载无法找到类



不知怎么的,我不能让自动加载正常工作。我使用以下引导文件的phpunit。

<?php
$loader = require __DIR__ . "/../vendor/autoload.php";
$loader->add('myproj\example\', __DIR__ . "/../example/");
$loader->add('myproj\', __DIR__ . "/../src/");
var_dump($loader->getPrefixes());

据我所知,这个var_dump的输出显示注册应该是ok的。

Running "phpunit:test" (phpunit) task
Starting phpunit (target: test) in test
array(40) {
  ["phpDocumentorComposer"]=>
  array(2) {
    [0]=>
    string(70) "/data/myproj/vendor/phpdocumentor/unified-asset-installer/src"
    [1]=>
    string(76) "/data/myproj/vendor/phpdocumentor/unified-asset-installer/test/unit"
  }
  ["phpDocumentor"]=>
  array(10) {
    [0]=>
    string(66) "/data/myproj/vendor/phpdocumentor/reflection-docblock/src"
    [1]=>
    string(57) "/data/myproj/vendor/phpdocumentor/reflection/src"
    [2]=>
    string(64) "/data/myproj/vendor/phpdocumentor/reflection/tests/unit"
    [3]=>
    string(65) "/data/myproj/vendor/phpdocumentor/reflection/tests/mocks"
    [4]=>
    string(55) "/data/myproj/vendor/phpdocumentor/graphviz/src"
    [5]=>
    string(62) "/data/myproj/vendor/phpdocumentor/graphviz/tests/unit"
    [6]=>
    string(54) "/data/myproj/vendor/phpdocumentor/fileset/src"
    [7]=>
    string(61) "/data/myproj/vendor/phpdocumentor/fileset/tests/unit"
    [8]=>
    string(60) "/data/myproj/vendor/phpdocumentor/phpdocumentor/src"
    [9]=>
    string(67) "/data/myproj/vendor/phpdocumentor/phpdocumentor/tests/unit"
  }
  ["ZendStdlib"]=>
  array(1) {
    [0]=>
    string(54) "/data/myproj/vendor/zendframework/zend-stdlib"
  }
  ["ZendServiceManager"]=>
  array(1) {
    [0]=>
    string(62) "/data/myproj/vendor/zendframework/zend-servicemanager"
  }
  ["ZendSerializer"]=>
  array(1) {
    [0]=>
    string(58) "/data/myproj/vendor/zendframework/zend-serializer"
  }
  ["ZendMath"]=>
  array(1) {
    [0]=>
    string(52) "/data/myproj/vendor/zendframework/zend-math"
  }
  ["ZendJson"]=>
  array(1) {
    [0]=>
    string(52) "/data/myproj/vendor/zendframework/zend-json"
  }
  ["ZendI18n"]=>
  array(1) {
    [0]=>
    string(52) "/data/myproj/vendor/zendframework/zend-i18n"
  }
  ["ZendFilter"]=>
  array(1) {
    [0]=>
    string(54) "/data/myproj/vendor/zendframework/zend-filter"
  }
  ["ZendEventManager"]=>
  array(1) {
    [0]=>
    string(60) "/data/myproj/vendor/zendframework/zend-eventmanager"
  }
  ["ZendConfig"]=>
  array(1) {
    [0]=>
    string(54) "/data/myproj/vendor/zendframework/zend-config"
  }
  ["ZendCache"]=>
  array(1) {
    [0]=>
    string(53) "/data/myproj/vendor/zendframework/zend-cache"
  }
  ["Twig_"]=>
  array(1) {
    [0]=>
    string(42) "/data/myproj/vendor/twig/twig/lib"
  }
  ["SymfonyComponentYaml"]=>
  array(1) {
    [0]=>
    string(41) "/data/myproj/vendor/symfony/yaml"
  }
  ["SymfonyComponentValidator"]=>
  array(1) {
    [0]=>
    string(46) "/data/myproj/vendor/symfony/validator"
  }
  ["SymfonyComponentTranslation"]=>
  array(1) {
    [0]=>
    string(48) "/data/myproj/vendor/symfony/translation"
  }
  ["SymfonyComponentStopwatch"]=>
  array(1) {
    [0]=>
    string(46) "/data/myproj/vendor/symfony/stopwatch"
  }
  ["SymfonyComponentProcess"]=>
  array(1) {
    [0]=>
    string(44) "/data/myproj/vendor/symfony/process"
  }
  ["SymfonyComponentFinder"]=>
  array(1) {
    [0]=>
    string(43) "/data/myproj/vendor/symfony/finder"
  }
  ["SymfonyComponentFilesystem"]=>
  array(1) {
    [0]=>
    string(47) "/data/myproj/vendor/symfony/filesystem"
  }
  ["SymfonyComponentEventDispatcher"]=>
  array(1) {
    [0]=>
    string(53) "/data/myproj/vendor/symfony/event-dispatcher"
  }
  ["SymfonyComponentConsole"]=>
  array(1) {
    [0]=>
    string(44) "/data/myproj/vendor/symfony/console"
  }
  ["SymfonyComponentConfig"]=>
  array(1) {
    [0]=>
    string(43) "/data/myproj/vendor/symfony/config"
  }
  ["PsrLog"]=>
  array(1) {
    [0]=>
    string(36) "/data/myproj/vendor/psr/log"
  }
  ["Pimple"]=>
  array(1) {
    [0]=>
    string(46) "/data/myproj/vendor/pimple/pimple/lib"
  }
  ["PhpOption"]=>
  array(1) {
    [0]=>
    string(52) "/data/myproj/vendor/phpoption/phpoption/src"
  }
  ["PhpCollection"]=>
  array(1) {
    [0]=>
    string(60) "/data/myproj/vendor/phpcollection/phpcollection/src"
  }
  ["Parsedown"]=>
  array(1) {
    [0]=>
    string(45) "/data/myproj/vendor/erusev/parsedown"
  }
  ["PHPParser"]=>
  array(1) {
    [0]=>
    string(49) "/data/myproj/vendor/nikic/php-parser/lib"
  }
  ["Metadata"]=>
  array(1) {
    [0]=>
    string(45) "/data/myproj/vendor/jms/metadata/src"
  }
  ["KnpMenu"]=>
  array(1) {
    [0]=>
    string(49) "/data/myproj/vendor/knplabs/knp-menu/src"
  }
  ["JMSSerializer"]=>
  array(1) {
    [0]=>
    string(47) "/data/myproj/vendor/jms/serializer/src"
  }
  ["JMS"]=>
  array(1) {
    [0]=>
    string(47) "/data/myproj/vendor/jms/parser-lib/src"
  }
  ["DoctrineCommonLexer"]=>
  array(1) {
    [0]=>
    string(47) "/data/myproj/vendor/doctrine/lexer/lib"
  }
  ["DoctrineCommonAnnotations"]=>
  array(1) {
    [0]=>
    string(53) "/data/myproj/vendor/doctrine/annotations/lib"
  }
  ["CilexProviderConsole"]=>
  array(1) {
    [0]=>
    string(63) "/data/myproj/vendor/cilex/console-service-provider/src"
  }
  ["CilexProvider"]=>
  array(1) {
    [0]=>
    string(60) "/data/myproj/vendor/phpdocumentor/phpdocumentor/src"
  }
  ["Cilex"]=>
  array(1) {
    [0]=>
    string(44) "/data/myproj/vendor/cilex/cilex/src"
  }
  ["myprojexample"]=>
  array(1) {
    [0]=>
    string(38) "/data/myproj/test/../example/"
  }
  ["myproj"]=>
  array(1) {
    [0]=>
    string(34) "/data/myproj/test/../src/"
  }
}

我得到以下错误。

PHPUnit 4.1.4 by Sebastian Bergmann.
Fatal error: Command failed: PHP Fatal error:  Class 'myprojexampleNotificationCountChangedEvent' not found in /data/myproj/test/unit/DefaultDomainEventTest.php on line 14

我的文件夹结构在myproj文件夹中看起来像这样src/测试/单位/——DefaultDomainEventTest.php——bootstrap.php例子/——NotificationCountChangedEvent.php

NotificationCountChangedEvent.php的命名空间为myprojexamplesrc/中的所有类也以名称空间myproj开始,然后对于每个子文件夹,我使用子名称空间的文件夹名。

我错过了什么/为什么这不起作用

使用下面的引导解决了这个问题。注意addPsr4方法而不是add方法。

<?php
$loader = require realpath(__DIR__ . "/../vendor/autoload.php");
$loader->addPsr4('bkcqrs\example\', realpath(__DIR__ . "/../example/") . "/", true);
$loader->addPsr4('bkcqrs\', realpath(__DIR__ . "/../src/") . "/", true);

相关内容

  • 没有找到相关文章

最新更新