|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespaceSymfony\Bundle\FrameworkBundle\Tests\DependencyInjection; |
| 13 | + |
| 14 | +useSymfony\Bundle\FrameworkBundle\DependencyInjection\Configuration; |
| 15 | +useSymfony\Component\Config\Definition\Processor; |
| 16 | + |
| 17 | +class ConfigurationTestextends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | +/** |
| 20 | + * @dataProvider getTestConfigTreeData |
| 21 | + */ |
| 22 | +publicfunctiontestConfigTree($options,$results) |
| 23 | + { |
| 24 | +$processor =newProcessor(); |
| 25 | +$configuration =newConfiguration(array()); |
| 26 | +$config =$processor->processConfiguration($configuration,array($options)); |
| 27 | + |
| 28 | +$this->assertEquals($results,$config); |
| 29 | + } |
| 30 | + |
| 31 | +publicfunctiongetTestConfigTreeData() |
| 32 | + { |
| 33 | +returnarray( |
| 34 | +array(array('secret' =>'s3cr3t'),array('secret' =>'s3cr3t','trusted_proxies' =>array(),'trust_proxy_headers' =>false,'ide' =>NULL,'annotations' =>array('cache' =>'file','file_cache_dir' =>'%kernel.cache_dir%/annotations','debug' =>false))), |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | +/** |
| 39 | + * @dataProvider getTestValidTrustedProxiesData |
| 40 | + */ |
| 41 | +publicfunctiontestValidTrustedProxies($options,$results) |
| 42 | + { |
| 43 | +$processor =newProcessor(); |
| 44 | +$configuration =newConfiguration(array()); |
| 45 | +$config =$processor->processConfiguration($configuration,array($options)); |
| 46 | + |
| 47 | +$this->assertEquals($results,$config); |
| 48 | + } |
| 49 | + |
| 50 | +publicfunctiongetTestValidTrustedProxiesData() |
| 51 | + { |
| 52 | +returnarray( |
| 53 | +array(array('secret' =>'s3cr3t','trusted_proxies' =>array('127.0.0.1')),array('secret' =>'s3cr3t','trusted_proxies' =>array('127.0.0.1'),'trust_proxy_headers' =>false,'ide' =>NULL,'annotations' =>array('cache' =>'file','file_cache_dir' =>'%kernel.cache_dir%/annotations','debug' =>false))), |
| 54 | +array(array('secret' =>'s3cr3t','trusted_proxies' =>array('::1')),array('secret' =>'s3cr3t','trusted_proxies' =>array('::1'),'trust_proxy_headers' =>false,'ide' =>NULL,'annotations' =>array('cache' =>'file','file_cache_dir' =>'%kernel.cache_dir%/annotations','debug' =>false))), |
| 55 | +array(array('secret' =>'s3cr3t','trusted_proxies' =>array('127.0.0.1','::1')),array('secret' =>'s3cr3t','trusted_proxies' =>array('127.0.0.1','::1'),'trust_proxy_headers' =>false,'ide' =>NULL,'annotations' =>array('cache' =>'file','file_cache_dir' =>'%kernel.cache_dir%/annotations','debug' =>false))), |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | +/** |
| 60 | + * @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException |
| 61 | + */ |
| 62 | +publicfunctiontestInvalidTypeTrustedProxies() |
| 63 | + { |
| 64 | +$processor =newProcessor(); |
| 65 | +$configuration =newConfiguration(array()); |
| 66 | +$config =$processor->processConfiguration($configuration,array(array('secret' =>'s3cr3t','trusted_proxies' =>'Not an IP address'))); |
| 67 | + } |
| 68 | + |
| 69 | +/** |
| 70 | + * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
| 71 | + */ |
| 72 | +publicfunctiontestInvalidValueTrustedProxies() |
| 73 | + { |
| 74 | +$processor =newProcessor(); |
| 75 | +$configuration =newConfiguration(array()); |
| 76 | +$config =$processor->processConfiguration($configuration,array(array('secret' =>'s3cr3t','trusted_proxies' =>array('Not an IP address')))); |
| 77 | + } |
| 78 | +} |