【发布时间】:2016-08-01 02:29:36
【问题描述】:
在我的本地 Windows PC 上,我正在运行 XAMPP,它正在提供一个测试页(例如 http://localhost/testsite/testpage.html)
现在在同一台机器上,我运行了一个 laravel 5.2 实例,其中有一个名为 testroute 的命名路由。
我写了一个phpunit测试用例
public function testBasicExample1() {
$this->visit('testroute')->see('Something'); //Passes
}
public function testBasicExample2() {
$this->visit('http://www.google.com')->see('Google'); //Passes
}
public function testBasicExample3() {
$this->visit('http://localhost/testsite/testpage.html')->see('Something Else');
//Fails as it is unable to reach the desired page (Received status code [404])
}
在 TestCase.php 中
$baseUrl = 'http://localhost:8000';
在.env APP_URL=http://localhost:8000
知不知道phpunit中无法访问localhost站点?
更新:
我发现即使http://www.google.com 也不起作用,它正在重定向到 laravel 的欢迎路线。 (测试通过,因为该页面中也有文本“Google”)。基本上它试图评估http://localhost:8000/www.google.com 并重定向到欢迎页面。
我不确定如何在 laravel 的 phpunit 中访问外部 url。
【问题讨论】:
-
你试过
$this->visit('http://localhost:8000/testsite/testpage.html')吗? -
这对我没有在 localhost:8000 上运行的测试站点有何帮助?我在 localhost:80 即 xampp 上运行测试站点。顺便说一句,我测试过,它不起作用。
标签: unit-testing laravel xampp phpunit laravel-5.2