【问题标题】:PHPUnit + Symfony: Crawler Follow Redirects Causes SegFaultPHPUnit + Symfony:爬虫跟随重定向导致 SegFault
【发布时间】:2016-04-06 23:38:51
【问题描述】:

我设置了一个简单的 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();,我会得到一个段错误。确实没有迹象表明段错误发生在哪里。

其他注意事项:如果我只运行此测试父类中的测试(2 个测试),即使用 --filter [THE CLASS],它运行良好。如果我尝试运行此测试以及整个套件(约 15 个测试),我会遇到段错误。

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

【问题讨论】:

    标签: php unit-testing symfony phpunit


    【解决方案1】:

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

    我建议您使用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()
        {
            // ...
        }
    }
    

    希望有帮助

    【讨论】:

    • 不错的一个。也为我解决了 seg 错误 :) 谢谢 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 2013-11-30
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多