diff --git a/src/Stubs/5/Component/DependencyInjection/ServiceLocator.stubphp b/src/Stubs/5/Component/DependencyInjection/ServiceLocator.stubphp new file mode 100644 index 00000000..a6ea41a6 --- /dev/null +++ b/src/Stubs/5/Component/DependencyInjection/ServiceLocator.stubphp @@ -0,0 +1,29 @@ + + */ + public function getProvidedServices(): array; +} diff --git a/src/Stubs/6/Component/DependencyInjection/ServiceLocator.stubphp b/src/Stubs/6/Component/DependencyInjection/ServiceLocator.stubphp new file mode 100644 index 00000000..500174f1 --- /dev/null +++ b/src/Stubs/6/Component/DependencyInjection/ServiceLocator.stubphp @@ -0,0 +1,30 @@ + + */ + public function getProvidedServices(): array; +} diff --git a/tests/acceptance/acceptance/ServiceLocator.feature b/tests/acceptance/acceptance/ServiceLocator.feature new file mode 100644 index 00000000..01bccb5b --- /dev/null +++ b/tests/acceptance/acceptance/ServiceLocator.feature @@ -0,0 +1,71 @@ +@symfony-5 @symfony-6 +Feature: ServiceLocator + + Background: + Given I have Symfony plugin enabled + + Scenario: ServiceLocator will return tagged service + Given I have the following code + """ + $strategies */ + private ServiceLocator $strategies; + + /** @param ServiceLocator $strategies */ + public function __construct(ServiceLocator $strategies) + { + $this->strategies = $strategies; + } + + public function doSomethingWithStrategy(): void + { + $strategy = $this->strategies->get('random_string'); + /** @psalm-trace $strategy */ + } + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | Trace | $strategy: StrategyInterface | + And I see no other errors + + Scenario: Fixed the return type of getProvidedServices() + Given I have the following code + """ + $strategies */ + private ServiceLocator $strategies; + + /** @param ServiceLocator $strategies */ + public function __construct(ServiceLocator $strategies) + { + $this->strategies = $strategies; + } + + public function getAll(): void + { + $names = $this->strategies->getProvidedServices(); + /** @psalm-trace $names */ + } + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | Trace | $names: array | + And I see no other errors