Phpunit 什么会导致痛风驱动程序不遵循重定向?

Phpunit 什么会导致痛风驱动程序不遵循重定向?,phpunit,mink,Phpunit,Mink,我有一个PHPUnit-Mink测试,它确保一些HTTP重定向已经就位 这被缩减了,但测试本质上看起来像是,testRedirect()由@dataProvider提供: class Testbase extends BrowserTestCase { public static $browsers = [ [ 'driver' => 'goutte', ], ]; public function testRedirect($from, $to)

我有一个PHPUnit-Mink测试,它确保一些HTTP重定向已经就位

这被缩减了,但测试本质上看起来像是,
testRedirect()
@dataProvider
提供:

class Testbase extends BrowserTestCase {

  public static $browsers = [
    [
      'driver' => 'goutte',
    ],
  ];

  public function testRedirect($from, $to) {
    $session = $this->getSession();
    $session->visit($from);

    $this->assertEquals(200, $session->getDriver()->getStatusCode(), sprintf('Final destination from %s was a 200', $to));
    $this->assertEquals($to, $session->getCurrentUrl(), sprintf('Redirected from %s to %s', $from, $to));
  }

}
这适用于在Web服务器本身上处理的重定向(例如,mod_rewrite重定向)。但是,我需要检查的一些重定向是由DNS提供商处理的(我不控制它,但我认为它是NetNames)

如果我用wget测试重定向,它看起来很好

$ wget --max-redirect=0 http://example1.com/
Resolving example1.com... A.B.C.D
Connecting to example1.com|A.B.C.D|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://example2.com/some/path?foo=bar [following]
0 redirections exceeded.
但是,当我从测试中转储响应时,标题是

Date: Thu, 06 Sep 2018 15:37:47 GMT
Content-Length: 94
X-Powered-By: Servlet/2.4 JSP/2.0
答案是

<head>
<title></title>
<meta name="revised" content="1.1.7">
</head>
<body></body>
但那没用


这是什么原因造成的?

我认为在接收端,主机头的情况很奇怪

我的测试提供程序有一些主机名,其中包含大写字符,例如“”。我必须将测试函数更新为

public function testRedirect($from, $to) {
  $parts = parse_url($from);
  $host = strtolower($parts['host']);

  $session = $this->getSession();
  $session->setRequestHeader('Host', $host);
  $session->visit($from);

  $this->assertEquals(200, $session->getDriver()->getStatusCode(), sprintf('Final destination from %s was a 200', $to));
  $this->assertEquals($to, $session->getCurrentUrl(), sprintf('Redirected from %s to %s', $from, $to));
}
强制主机标头为小写

public function testRedirect($from, $to) {
  $parts = parse_url($from);
  $host = strtolower($parts['host']);

  $session = $this->getSession();
  $session->setRequestHeader('Host', $host);
  $session->visit($from);

  $this->assertEquals(200, $session->getDriver()->getStatusCode(), sprintf('Final destination from %s was a 200', $to));
  $this->assertEquals($to, $session->getCurrentUrl(), sprintf('Redirected from %s to %s', $from, $to));
}