当我从浏览器运行该服务时,它可以工作,但是如果我执行测试文件,我会收到此错误:
1) Api\Domain\Tests\ServiceTest::testSetUp
RuntimeException: A facade root has not been set.
/WWW/api/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:210
/WWW/api/src/Api/Infrastructure/Domain/Model/SolrBaseRepository.php:30
/WWW/api/src/Api/Infrastructure/Domain/Model/SolrBaseRepository.php:30
/WWW/api/src/Api/Domain/Tests/ServiceTest.php:80
文件配置:config/solr.php
return array(
'endpoint' => array(
'localhost' => array(
'host' => '192.168.1.100',
'port' => 8080,
'path' => '/solr/clients/',
)
)
);
Solr 基础存储库:
use Illuminate\Support\Facades\Config;
abstract class SolrBaseRepository
protected $client;
/**
* SolrBaseRepository constructor.
*/
public function __construct(){
$this->client = new \Solarium\Client(Config::get('solr'));
}
}
如果我改变
$this->client = new \Solarium\Client(Config::get('solr'));
经过
$this->client = new \Solarium\Client(array(
'endpoint' => array(
'localhost' => array(
'host' => '192.168.1.100',
'port' => 8080,
'path' => '/solr/clients/',
)
)
));
测试有效。服务测试:Api/Domain/Tests/ServiceTest.php
class ServiceTest extends \PHPUnit_Framework_TestCase{
public function testSetUp()
{
$this->setUp();
$this->solrServicesRepository = New SolrServicesRepository();
}
}
我试图解决它从这个页面添加到我的ServiceTest.php:
use \Illuminate\Container\Container as Container;
use \Illuminate\Support\Facades\Facade as Facade;
/**
* Setup a new app instance container
*
* @var Illuminate\Container\Container
*/
$app = new Container();
$app->singleton('app', 'Illuminate\Container\Container');
/**
* Set $app as FacadeApplication handler
*/
Facade::setFacadeApplication($app);
但这对 mi 不起作用。