ExtensionTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Tests\Component\DependencyInjection\Extension;
  11. use Symfony\Component\DependencyInjection\Extension\Extension;
  12. require_once __DIR__.'/../Fixtures/includes/ProjectExtension.php';
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. class ExtensionTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @covers Symfony\Component\DependencyInjection\Extension\Extension::load
  18. */
  19. public function testLoad()
  20. {
  21. $extension = new \ProjectExtension();
  22. try {
  23. $extension->load('foo', array(), new ContainerBuilder());
  24. $this->fail('->load() throws an InvalidArgumentException if the tag does not exist');
  25. } catch (\Exception $e) {
  26. $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag does not exist');
  27. $this->assertEquals('The tag "project:foo" is not defined in the "project" extension.', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag does not exist');
  28. }
  29. $extension->load('bar', array('foo' => 'bar'), $config = new ContainerBuilder());
  30. $this->assertEquals(array('project.parameter.bar' => 'bar', 'project.parameter.foo' => 'bar'), $config->getParameterBag()->all(), '->load() calls the method tied to the given tag');
  31. }
  32. /**
  33. * @dataProvider getKeyNormalizationTests
  34. */
  35. public function testNormalizeKeys($denormalized, $normalized)
  36. {
  37. $this->assertSame($normalized, Extension::normalizeKeys($denormalized));
  38. }
  39. public function getKeyNormalizationTests()
  40. {
  41. return array(
  42. array(
  43. array('foo-bar' => 'foo'),
  44. array('foo_bar' => 'foo'),
  45. ),
  46. array(
  47. array('foo-bar_moo' => 'foo'),
  48. array('foo-bar_moo' => 'foo'),
  49. ),
  50. array(
  51. array('foo-bar' => null, 'foo_bar' => 'foo'),
  52. array('foo-bar' => null, 'foo_bar' => 'foo'),
  53. ),
  54. array(
  55. array('foo-bar' => array('foo-bar' => 'foo')),
  56. array('foo_bar' => array('foo_bar' => 'foo')),
  57. ),
  58. array(
  59. array('foo_bar' => array('foo-bar' => 'foo')),
  60. array('foo_bar' => array('foo_bar' => 'foo')),
  61. )
  62. );
  63. }
  64. }