2017-01-21 48 views
0

當我嘗試使用自定義域這樣Laravel5.3的PHPUnit不工作

<?php 

abstract class TestCase extends Illuminate\Foundation\Testing\TestCase 
{ 
/** 
* The base URL to use while testing the application. 
* 
* @var string 
*/ 
protected $baseUrl = 'http://localhost'; 

protected $prefixDomain = ''; 

/** 
* Creates the application. 
* 
* @return \Illuminate\Foundation\Application 
*/ 
public function createApplication() 
{ 
    $app = require __DIR__.'/../bootstrap/app.php'; 

    $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); 
    $this->setBaseUrl(); 

    return $app; 
} 

protected function setBaseUrl() 
{ 
    $this->baseUrl = env('APP_URL', $this->baseUrl); 
    if ($this->prefixDomain) { 
     $this->baseUrl = substr_replace(
      $this->prefixDomain, 
      $this->baseUrl, 
      strlen('https://'), 
      0 
     ); 
    } 
} 

自定義域我設置「APP_URL」在.ENV文件

好像請求URI不權當我傾倒和光照明\路由\ RouteCollection.php死

/** 
* Find the first route matching a given request. 
* 
* @param \Illuminate\Http\Request $request 
* @return \Illuminate\Routing\Route 
* 
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException 
*/ 
public function match(Request $request) 
{ 
    dd($request); 
    $routes = $this->get($request->getMethod()); 

我希望這裏的輸出是「REQUEST_URI」 =>「/測試」,但實際上

enter image description here

在此先感謝您的幫助。

回答

0

看來我似乎解決了這個問題。 我應該已經添加的「http://」,以APP_URL

// .env 
APP_URL=http://domain.com 

我見過的代碼是在這裏

// Illuminate\Foundation\Testing\Concerns\[email protected] 
protected function prepareUrlForRequest($uri) 
{ 
    if (Str::startsWith($uri, '/')) { 
     $uri = substr($uri, 1); 
    } 

    if (! Str::startsWith($uri, 'http')) { 
     $uri = $this->baseUrl.'/'.$uri; 
    } 

    return trim($uri, '/'); 
} 

希望這將幫助我這樣的人!