Skip to content

WebTestCase Client::getContainer null return type #25920

Closed
@soullivaneuh

Description

@soullivaneuh
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 4.0.3

According to this code part:

/**
* Returns the container.
*
* @return ContainerInterface|null Returns null when the Kernel has been shutdown or not started yet
*/
public function getContainer()
{
return $this->kernel->getContainer();
}

The container may be null if the kernel has been shutdown.

But this simply call $this->kernel->getContainer(); and according to the PHPDoc:

/**
* Gets the current container.
*
* @return ContainerInterface A ContainerInterface instance
*/
public function getContainer();

It should never return null, always a ContainerInterface.

This also make PHPStan yelling on web tests:

Calling method get() on possibly null value of type Symfony\Component\DependencyInjection\ContainerInterface|null.

If am I right, the PHPDoc of the Client must be corrected.

If it may return null, I suggest to throw an exception instead. This method should not called if the kernel is not booted AFAIK.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions