PHPUnit + Symfony:爬虫跟随重定向导致段错误

PHPUnit + Symfony: Crawler Follow Redirects Causes SegFault

我设置了一个简单的 PHPUnit/Symfony WebTestCase 来测试我们站点的登录表单。

$form = $crawler->filter("#register")->form();

// set form values

$crawler = $this->client->submit($form);

表单将提交到 /register,然后在成功时重定向到 /registered(失败时 200/OK 返回到 /register)。

如果我在上面的块之前使用 $this->client->followRedirects();,或者在提交之后使用 $this->client->followRedirect();,我会得到一个段错误。确实没有迹象表明段错误发生在哪里。

其他注意事项:如果我运行只是这个测试父class(2个测试)中的测试,即使用--filter [THE CLASS] 运行没问题。如果我尝试 运行 这个测试,连同完整套件(~15 个测试),我会遇到段错误。

我已经尝试使用 -d 标志为 phpunit 提供更多内存,但这并没有真正帮助。

问题可能出在控制器与其他组件一起工作时。

我建议您使用 Process Isolation in PHPUnit,这样您就可以 运行 在单独的 PHP 进程中进行关键测试。例如,您可以使用以下注释:

Indicates that all tests in a test class should be run in a separate PHP process:

/**
 * @runTestsInSeparateProcesses
 */
class MyTest extends PHPUnit_Framework_TestCase
{
    // ...
}

Indicates that a test should be run in a separate PHP process:

class MyTest extends PHPUnit_Framework_TestCase
{
    /**
     * @runInSeparateProcess
     */
    public function testInSeparateProcess()
    {
        // ...
    }
}

希望对您有所帮助