| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Copyright 2011 Johannes M. Schmitt <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * you may not use this file except in compliance with the License. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * You may obtain a copy of the License at | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * http://www.apache.org/licenses/LICENSE-2.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Unless required by applicable law or agreed to in writing, software | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * See the License for the specific language governing permissions and | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * limitations under the License. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | namespace JMS\SerializerBundle\Tests\DependencyInjection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use JMS\SerializerBundle\DependencyInjection\Configuration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use JMS\SerializerBundle\JMSSerializerBundle; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Symfony\Component\Config\Definition\Processor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Symfony\Component\DependencyInjection\ContainerBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | class ConfigurationTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     private function getContainer(array $configs = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $container = new ContainerBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $container->setParameter('kernel.debug', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $container->setParameter('kernel.bundles', array('JMSSerializerBundle' => 'JMS\SerializerBundle\JMSSerializerBundle')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $bundle = new JMSSerializerBundle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $extension = $bundle->getContainerExtension(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $extension->load($configs, $container); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return $container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     public function testConfig() | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $ref = new JMSSerializerBundle(); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $container = $this->getContainer([ | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |                 'metadata' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |                     'directories' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |                         [ | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                             'namespace_prefix' => 'JMSSerializerBundleNs1', | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |                             'path' => '@JMSSerializerBundle', | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |                         ], | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |                         [ | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |                             'namespace_prefix' => 'JMSSerializerBundleNs2', | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |                             'path' => '@JMSSerializerBundle/Resources/config', | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |                         ], | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |                     ] | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |                 ] | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $directories = $container->getDefinition('jms_serializer.metadata.file_locator')->getArgument(0); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $this->assertEquals($ref->getPath(), $directories['JMSSerializerBundleNs1']); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         $this->assertEquals($ref->getPath().'/Resources/config', $directories['JMSSerializerBundleNs2']); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     public function testContextDefaults() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $processor = new Processor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $config = $processor->processConfiguration(new Configuration(true), []); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->assertArrayHasKey('context', $config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->assertArrayHasKey('attributes', $config['context']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->assertTrue(is_array($config['context']['attributes'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->assertEmpty($config['context']['attributes']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $this->assertArrayHasKey('groups', $config['context']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $this->assertSame(['Default'], $config['context']['groups']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->assertArrayHasKey('version', $config['context']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->assertNull($config['context']['version']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $this->assertArrayHasKey('serialize_null', $config['context']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $this->assertFalse($config['context']['serialize_null']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |  |