Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] update docblock to not expose the internal class #46496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2022

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented May 29, 2022

Q A
Branch? 6.1
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #46483
License MIT
Doc PR

The change was introduced in #44695 motivated by the idea to be able to use the getServiceIds() and getRemovedIds() methods which are Symfony-specific methods. Exposing the TestContainer has the drawback of static analysis tools complaining about making use of internal classes. Since the interesting methods are part of the base Container class which is not internal I propose to change the docblock to return an instance of this class instead.

@ddeboer
Copy link
Contributor

ddeboer commented May 30, 2022

Confirmed this resolves issue #46483.

@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit fe1759a into symfony:6.1 May 30, 2022
@xabbuh xabbuh deleted the issue-46483 branch May 30, 2022 11:54
@MaSpeng
Copy link

MaSpeng commented Jun 10, 2022

@xabbuh @ddeboer

The overall issue seems to be still present.

Due to the changes on the return types, psalm is not able anymore to infer the return types from Container::get. This becomes instantly visible when using the container in combination with (doctrine) repository classes inside functional tests using the KernelTestCase class.

ERROR: MixedAssignment - tests/Functional/Command/CommandTest.php:27:9 - Unable to determine the type that $entity is being assigned to (see https://psalm.dev/032)
        $entity = $entityRepository->find('_entity_id_');

ERROR: PossiblyNullReference - tests/Functional/Command/CommandTest.php:27:38 - Cannot call method get on possibly null value (see https://psalm.dev/083)
        $entity = $entityRepository->find('_entity_id_');

ERROR: MixedMethodCall - tests/Functional/Command/CommandTest.php:27:38 - Cannot determine the type of $entityRepository when calling method get (see https://psalm.dev/015)
        $entity = $entityRepository->find('_entity_id_');

  The type of get is sourced from here - vendor/symfony/dependency-injection/Container.php:193:99
    public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE): ?object

That's my snippet from my test case

use Prophecy\PhpUnit\ProphecyTrait;
use Company\Api\Command\Command;
use Company\Api\Entity\Entity;
use Company\Api\Repository\EntityRepository;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

class CommandTest extends KernelTestCase
{
    use ProphecyTrait;

    public function testExecute(): void
    {
        $container = self::getContainer();

        $entityRepository = $container->get(EntityRepository::class);

        $entity = $entityRepository->find('_entity_id_');

        // ...
    }
}

Removing the @return annotation at

seems to bring us back to the original behaviour without psalm producing errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants