private function getContainerForConfig(array $configs, KernelInterface $kernel = null)
 {
     if (null === $kernel) {
         $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
         $kernel->expects($this->any())->method('getBundles')->will($this->returnValue(array()));
     }
     $bundle = new JMSSerializerBundle($kernel);
     $extension = $bundle->getContainerExtension();
     $container = new ContainerBuilder();
     $container->setParameter('kernel.debug', true);
     $container->setParameter('kernel.cache_dir', sys_get_temp_dir());
     $container->setParameter('kernel.bundles', array());
     $container->set('annotation_reader', new AnnotationReader());
     $container->set('service_container', $container);
     $container->set('translator', $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface'));
     $extension->load($configs, $container);
     $bundle->build($container);
     $container->getCompilerPassConfig()->setOptimizationPasses(array(new ResolveDefinitionTemplatesPass()));
     $container->getCompilerPassConfig()->setRemovingPasses(array());
     $container->compile();
     return $container;
 }
Beispiel #2
0
 private function getSerializer()
 {
     $container = new ContainerBuilder();
     $container->set('annotation_reader', new AnnotationReader());
     $container->set('translator', new IdentityTranslator(new MessageSelector()));
     $container->setParameter('kernel.debug', true);
     $container->setParameter('kernel.cache_dir', sys_get_temp_dir());
     $container->setParameter('kernel.bundles', array());
     $extension = new JMSSerializerExtension();
     $extension->load(array(array()), $container);
     $bundle = new JMSSerializerBundle();
     $bundle->build($container);
     $container->getCompilerPassConfig()->setOptimizationPasses(array(new ResolveDefinitionTemplatesPass()));
     $container->getCompilerPassConfig()->setRemovingPasses(array());
     $container->compile();
     return $container->get('serializer');
 }
 /**
  * @test jms serializer configuration
  */
 public function jmsSerializers()
 {
     $this->loadExtension(['serializers' => ['default' => ['jms' => ['format' => 'xml']]]], false);
     $jmsBundle = new JMSSerializerBundle();
     $jmsBundle->getContainerExtension()->load([], $this->container);
     $jmsBundle->build($this->container);
     $id = EventBandExtension::getSerializerId('default');
     $this->assertTrue($this->container->hasDefinition($id));
     $this->container->getDefinition($id)->setPublic(true);
     $this->container->compile();
     $serializer = $this->container->get($id);
     $this->assertInstanceOf('EventBand\\Serializer\\Jms\\JmsEventContainerSerializer', $serializer);
     $this->assertEquals('xml', $this->container->getDefinition($id)->getArgument(1));
 }