由於自動加載器無法解析Doctrine \ ORM \ Mapping \ Table,因此我對composer的自動加載感到煩惱。 因爲我已經創建學說實體類典型註解的單元測試:自動加載無法正確使用供應商目錄中的autoloader.php
<?php
namespace OmniSearchTest\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Picture
*
* @ORM\Table(name="picture")
* @ORM\Entity
*/
class Picture
{
,並通過使用該實體創建一個新的實體管理器。但即時得到消息:
Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@Doctrine\ORM\Mapping\Table" in class OmniSearchTest\Entity\Picture does not exist, or could not be auto-loaded.
對於一些單元測試
首先,我有以下項目結構:
/src
/OmniSearch
SomeClass.php
/tests
/OmniSearchTest
SomeClassTest.php
/composer.json
/phpunit.xml.dist
我composer.json看起來是這樣的:
{
/* ... */
"require": {
"php": ">=5.4",
"doctrine/orm": "2.*"
},
"require-dev": {
"phpunit/phpunit": "4.*"
},
"autoload": {
"psr-0": {
"OmniSearch\\": "src/"
}
},
"autoload-dev": {
"psr-0": {
"OmniSearchTest\\": "tests/"
}
}
}
雖然我的phpunit看起來非常像這樣:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
strict="true"
verbose="true">
<testsuites>
<testsuite name="omnisearch">
<directory>./tests/OmniSearchTest</directory>
</testsuite>
</testsuites>
</phpunit>
我從自動加載工作正常的另一個zf2項目中截掉了這個項目。林不知道,因爲自動生成的autoload_namespaces.php包含的映射關係究竟是什麼出了問題:
'Doctrine\\ORM\\' => array($vendorDir . '/doctrine/orm/lib'),
whohaaaa,你說得對......我已經創建了一個測試目錄中的bootstrap.php和修改phpunit.xml來引導這個文件 – torsten 2014-09-19 19:11:35
我只是用作曲家的autoload.php從'供應商'目錄,它的工作(我甚至不使用bootstrap.php):'$ loader = require_once __DIR __。'/ vendor/autoload.php'; AnnotationRegistry :: registerLoader(數組($ loader,'loadClass'));' – 2014-11-23 21:40:30