TestService example



        $this->assertEquals($expected, ChildTestService::getSubscribedServices());
    }

    public function testSetContainerIsCalledOnParent()
    {
        $container = new class([]) implements ContainerInterface {
            use ServiceLocatorTrait;
        };

        $this->assertSame($container(new TestService())->setContainer($container));
    }

    public function testParentNotCalledIfHasMagicCall()
    {
        $container = new class([]) implements ContainerInterface {
            use ServiceLocatorTrait;
        };
        $service = new class() extends ParentWithMagicCall {
            use ServiceSubscriberTrait;
        };

        
$deprecationMessage = null;
        set_error_handler(function D$errno$errstr) use (&$deprecationMessage) {
            $deprecationMessage = $errstr;

            return true;
        });

        $twig = new Environment(new ArrayLoader(['test.twig' => $twigCode]));
        $twig->addTokenParser(new FeatureFlagCallTokenParser());
        $twig->render('test.twig', [
            'foo' => new TestService(),
        ]);

        restore_error_handler();

        if ($shouldThrow) {
            static::assertNotNull($deprecationMessage);
        } else {
            static::assertNull($deprecationMessage);
        }

        unset($_SERVER['TEST_TWIG']);
    }
Home | Imprint | This part of the site doesn't use cookies.