Giter VIP home page Giter VIP logo

Comments (15)

Nyholm avatar Nyholm commented on August 29, 2024

Oh, very true. Can you update the documentation to warn about this?

from symfony-bundle-test.

umpirsky avatar umpirsky commented on August 29, 2024

Done #19.

Is there a way to detect if service is private and skip it in the smoke test?

from symfony-bundle-test.

Nyholm avatar Nyholm commented on August 29, 2024

Not sure what you mean. You decide yourself what services you will "force make" public. And you decide what services you want to test.

from symfony-bundle-test.

umpirsky avatar umpirsky commented on August 29, 2024

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. argument_metadata_factory, annotation_reader... a number of them). For all this services $container->has($id) is true, but $container->get($id) throws deprecation that service is private and you should not access it (Symfony 3.4).

I don't see elegant solution for this.

from symfony-bundle-test.

Nyholm avatar Nyholm commented on August 29, 2024

When I testing my third party bundles I always do something like this:
https://github.com/SymfonyTest/symfony-bundle-test#write-a-test

Example: https://github.com/php-translation/symfony-bundle/blob/0.6.1/Tests/Functional/BundleInitializationTest.php

from symfony-bundle-test.

umpirsky avatar umpirsky commented on August 29, 2024

It's not generic. I have a smoke test that iterates $container->getServiceIds().

from symfony-bundle-test.

Nyholm avatar Nyholm commented on August 29, 2024

Hm... So you want to test AppBundle. Or all services in the kernel. And you just want to instantiate the services, right?

from symfony-bundle-test.

umpirsky avatar umpirsky commented on August 29, 2024

Yes, all public services in the kernel. But I get private too, and can't distinguish them.

from symfony-bundle-test.

Nyholm avatar Nyholm commented on August 29, 2024

For that you just need to build the container, right?

Upon building the container Symfony will try to resolve all dependencies.

from symfony-bundle-test.

umpirsky avatar umpirsky commented on August 29, 2024

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:

Remaining deprecation triggered by GenericServicesTest::testServiceInstantiation:
    The "argument_metadata_factory" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.

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 has() returns true to private services as well.

from symfony-bundle-test.

Nyholm avatar Nyholm commented on August 29, 2024

Interesting.
I just looked at the source. Maybe you could create your own container that extends Container. That would allow you to extract all public services and aliases.

from symfony-bundle-test.

umpirsky avatar umpirsky commented on August 29, 2024

Yes, I was thinking same, do that only in test env.

from symfony-bundle-test.

umpirsky avatar umpirsky commented on August 29, 2024

Fixed with:

-        foreach ($container->getServiceIds() as $serviceId) {
+        foreach (array_diff($container->getServiceIds(), array_keys($container->getRemovedIds())) as $serviceId) {

from symfony-bundle-test.

Nyholm avatar Nyholm commented on August 29, 2024

Great!

from symfony-bundle-test.

Nyholm avatar Nyholm commented on August 29, 2024

On other news: symfony/symfony#26499

from symfony-bundle-test.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.