-
Notifications
You must be signed in to change notification settings - Fork 27
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
Accessing private services #18
Comments
Oh, very true. Can you update the documentation to warn about this? |
Done #19. Is there a way to detect if service is private and skip it in the smoke test? |
Not sure what you mean. You decide yourself what services you will "force make" public. And you decide what services you want to test. |
Yes, but when you write smoke test, like this for example https://gist.github.com/Maff-/c9d2c1592a746da85d5b, you iterate Symfony private services and vendors private services (e.g. I don't see elegant solution for this. |
When I testing my third party bundles I always do something like this: |
It's not generic. I have a smoke test that iterates |
Hm... So you want to test AppBundle. Or all services in the kernel. And you just want to instantiate the services, right? |
Yes, all public services in the kernel. But I get private too, and can't distinguish them. |
For that you just need to build the container, right? Upon building the container Symfony will try to resolve all dependencies. |
The test is as simple as: class GenericServicesTest extends TestCase
{
public function testServiceInstantiation()
{
foreach ($container->getServiceIds() as $serviceId) {
$this->assertNotNull($client->getContainer()->get($serviceId));
}
}
} Container is already built and everything works fine until you enable deprecations. Then you get:
I was trying with: class GenericServicesTest extends TestCase
{
public function testServiceInstantiation()
{
foreach ($container->getServiceIds() as $serviceId) {
+ if (!$container->has($serviceId)) {
+ continue;
+ }
+
$this->assertNotNull($client->getContainer()->get($serviceId));
}
}
} But |
Interesting. |
Yes, I was thinking same, do that only in test env. |
Fixed with: - foreach ($container->getServiceIds() as $serviceId) {
+ foreach (array_diff($container->getServiceIds(), array_keys($container->getRemovedIds())) as $serviceId) { |
Great! |
On other news: symfony/symfony#26499 |
This means that in tests accessing private services will not be caught as an error? I find this dangerous.
The text was updated successfully, but these errors were encountered: