我只是无法弄清楚我的phpunit测试在同一命名空间中找不到类的原因。php无法在同一命名空间中找到类
composer.json
"autoload": {
"psr-4": {
"LeonLombard\\OandaApi\\": ["src"]
}
},
"autoload-dev": {
"psr-4": {
"LeonLombard\\OandaApi\\": ["tests"]
}
},
的src/OandaApi.php
<?php namespace LeonLombard\OandaApi;
class OandaApi
{
}
测试/ OandaApiTest.php
<?php namespace LeonLombard\OandaApi;
class OandaApiTest extends \PHPUnit_Framework_TestCase
{
public function testGetAnInstrumentListWithDefaultOptions()
{
$oandaApi = new OandaApi();
}
}
测试/ phpunit.xml
<phpunit
bootsrap="../vendor/autoload.php"
>
<testsuites>
<testsuite name="All Tests">
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>
这是我得到的错误,当我运行phpunit --config tests/phpunit.xml
:
致命错误:类 'LeonLombard \ OandaApi \ OandaApi' 没有找到/用户/ leonlombard /网站/oanda-api/tests/OandaApiTest.php on line 7
任何想法,将不胜感激。我看过其他类似设置的帖子,不知道他们为什么会工作,而不是我的。
谢谢。
感谢您的建议。但是,我确实尝试过,并没有奏效。请阅读该链接以确保我对PSR-4的理解没有遗漏。 –
我删除了所有的代码,并开始从一开始的步骤,现在它正在工作。不知道我错过了什么,但可以证实Brijesh的建议是好的。 –