ExtensionTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Tests\Extension;
  11. class ExtensionTest extends \PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @dataProvider getResolvedEnabledFixtures
  15. */
  16. public function testIsConfigEnabledReturnsTheResolvedValue($enabled)
  17. {
  18. $pb = $this->getMockBuilder('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag')
  19. ->setMethods(array('resolveValue'))
  20. ->getMock()
  21. ;
  22. $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
  23. ->setMethods(array('getParameterBag'))
  24. ->getMock()
  25. ;
  26. $pb->expects($this->once())
  27. ->method('resolveValue')
  28. ->with($this->equalTo($enabled))
  29. ->will($this->returnValue($enabled))
  30. ;
  31. $container->expects($this->once())
  32. ->method('getParameterBag')
  33. ->will($this->returnValue($pb))
  34. ;
  35. $extension = $this->getMockBuilder('Symfony\Component\DependencyInjection\Extension\Extension')
  36. ->setMethods(array())
  37. ->getMockForAbstractClass()
  38. ;
  39. $r = new \ReflectionMethod('Symfony\Component\DependencyInjection\Extension\Extension', 'isConfigEnabled');
  40. $r->setAccessible(true);
  41. $r->invoke($extension, $container, array('enabled' => $enabled));
  42. }
  43. public function getResolvedEnabledFixtures()
  44. {
  45. return array(
  46. array(true),
  47. array(false)
  48. );
  49. }
  50. /**
  51. * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
  52. * @expectedExceptionMessage The config array has no 'enabled' key.
  53. */
  54. public function testIsConfigEnabledOnNonEnableableConfig()
  55. {
  56. $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
  57. ->getMock()
  58. ;
  59. $extension = $this->getMockBuilder('Symfony\Component\DependencyInjection\Extension\Extension')
  60. ->setMethods(array())
  61. ->getMockForAbstractClass()
  62. ;
  63. $r = new \ReflectionMethod('Symfony\Component\DependencyInjection\Extension\Extension', 'isConfigEnabled');
  64. $r->setAccessible(true);
  65. $r->invoke($extension, $container, array());
  66. }
  67. }