2

I want to test this function:

static protected function getContainerInterface()
{
    global $kernel;
    if (get_class($kernel) == 'AppCache') {
        /** @var \AppCache $cache */
        $cache = $kernel;
        $kernel = $cache->getKernel();
    }
    return $kernel->getContainer();
}

And got an error: Call to a member function getContainer() on null triggered by this string:

return $kernel->getContainer();

How can I pass global $kernel object to crawler( that is instance of FunctionalTester) in codeception ?

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
sirKrono
  • 46
  • 4
  • 1
    Is this a method called "interface"? This is not an interface. An interface is a keyword in PHP and shouldn't be used like this at all. – John Dee Apr 21 '18 at 22:27
  • Joe, I agree. Thanks for advice. I'm 'enjoying myself' rewriting legacy project and there are many interesting things, such an 'interface caller' is only one in a long row. – sirKrono Apr 23 '18 at 09:21

1 Answers1

2

A global variable is a bad practice. I can assume that when running tests, codeception creates its own test kernel and this kernel can not be used globally. This place needs to be refactored

Alexey Bril
  • 479
  • 4
  • 14