0

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. Once I comment it - everything is fine.

UPD#1: I figured out why it fails: 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..

nKognito
  • 6,297
  • 17
  • 77
  • 138

1 Answers1

0

Your problem is the upgrade of the Pimple container. The Pimple version of Silex 2 freezes services once you get them.

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.

mTorres
  • 3,590
  • 2
  • 25
  • 36
  • 1
    Hi, thanks for your reply. Actually, I got it already, question is - how to refactor event listeners such as `$app->error` or `$app->before`? This is part of boot process. In addition, what is the best practices of redefining objects during the tests? – nKognito Jun 07 '16 at 08:05
  • I would opt to have different config files depending on the environment (dev, prod, test). Define the environment early and then configure the services based on it, like the official [Silex Skeleton](https://github.com/silexphp/silex-skeleton). – mTorres Jun 09 '16 at 07:29