简体   繁体   English

Silex 2升级后,WebTestCase失败

[英]WebTestCase fails after Silex 2 upgrade

I have the following base lass for controller tests: 我对控制器测试有以下基本要求:

public function createApplication() {
     include __DIR__ . '../web/index_dev.php';

     $app['debug'] = true;
     $app['session.test'] = true;
     $app['helper'] = function ($app) {
            return new TestHelper($app);
     }; // fails!!

     return $app;
  }

  public function setUp() {
     parent::setUp();

     $this->client = parent::createClient();
 }

At Silex 1.3 it worked fine, but after upgrade for v2 it fails at marked line. 在Silex 1.3上,它可以正常工作,但是在v2升级后,它在标记行上失败。 Once I comment it - everything is fine. 一旦我发表评论-一切都很好。

UPD#1: I figured out why it fails: Cannot override frozen service "helper". UPD#1:我发现了失败的原因: Cannot override frozen service "helper". I understand the meaning of error, but can't understand how to fix it. 我了解错误的含义,但不知道如何解决。 It isa test case, so I need to replace it with mock/test implementation of object, but can't.. 这是一个测试用例,所以我需要用对象的模拟/测试实现替换它,但是不能。

Your problem is the upgrade of the Pimple container. 您的问题是Pimple容器的升级。 The Pimple version of Silex 2 freezes services once you get them . 一旦获得服务,Silex 2的Pimple版本将冻结服务

So your problem is that you are getting the 'helper' service previously on your code. 因此,您的问题是您先前在代码上获得了“帮助程序”服务。 You should refactor your code so that you won't get the service when booting your application. 您应该重构代码,以便在启动应用程序时不会获得该服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM