有人在虚拟主机上使用代码接收吗?如果是这样,你是如何让它工作的?
我有两台测试机,一台 WAMP,一台 Ubuntu,都设置了虚拟主机。当我运行一个非常基本的代码接收验收测试时,我得到的响应看起来像是在尝试转到默认页面,而不是我的虚拟主机的索引页面。
我的虚拟主机叫做test;我的/etc/hosts
文件的一部分如下所示:
127.0.0.1 test
/etc/apache2/sites-enabled/test
看起来像这样:
<VirtualHost *:80>
ServerName test
DocumentRoot '/home/joel/projects/web/test'
<Directory '/home/joel/projects/web/test'>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
我几乎只是使用默认的验收套件设置文件;唯一的变化是在以下位置输入我的虚拟机的名称tests/acceptance.suite.yml
:
class_name: WebGuy
modules:
enabled:
- PhpBrowser
- WebHelper
config:
PhpBrowser:
url: 'http://test'
在/home/joel/projects/web/test/index.html
中,我有一个非常简单的网页:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
Hello, World!
</body>
</html>
我可以在我尝试的任何浏览器中成功加载此页面,包括 wget 和 curl。
我的codeception测试也很简单。在tests/acceptance/WelcomeCept.php
:
<?php
$I = new WebGuy($scenario);
$I->amOnPage('/');
$I->see('Hello');
当我尝试运行这个测试时,我得到这个输出:
Codeception PHP Testing Framework v1.6.6
Powered by PHPUnit 3.7.24 by Sebastian Bergmann.
Suite unit started
Suite functional started
Suite acceptance started
Running WelcomeCept.php - Failed
Time: 15 ms, Memory: 20.25Mb
There was 1 failure:
---------
1) WelcomeCept.php
Ups, I couldn't see "Hello",
Failed asserting that
--> It works! This is the default web page for this server. The web server software is running but no content has been added, yet.
--> contains "hello".
Scenario Steps:
2. I see "Hello"
1. I am on page "/"
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
我的默认网页(127.0.0.1)确实返回“它可以工作!” 消息,但虚拟主机的任何内容都会转到“Hello, World”页面。知道为什么 codeception 不会进入我的虚拟主机吗?关于如何追踪导致问题的任何想法?
谢谢!
——乔尔
编辑:
我想到了。in 中需要端口号tests/acceptance.suite.yml
,因此这不起作用:
config:
PhpBrowser:
url: 'http://test'
但这确实有效:
config:
PhpBrowser:
url: 'http://test:80'
这似乎没有记录在任何地方,而且不直观,所以我提出了一个拉取请求以默认端口 80。这可能很快就不是问题了。