PropelExtensionTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\Framework\PropelBundle\Tests\DependencyInjection;
  11. use Symfony\Framework\PropelBundle\Tests\TestCase;
  12. use Symfony\Framework\PropelBundle\DependencyInjection\PropelExtension;
  13. use Symfony\Components\DependencyInjection\BuilderConfiguration;
  14. class PropelExtensionTest extends TestCase
  15. {
  16. public function testConfigLoad()
  17. {
  18. $configuration = new BuilderConfiguration();
  19. $loader = new PropelExtension();
  20. try {
  21. $configuration = $loader->configLoad(array(), $configuration);
  22. $this->fail();
  23. } catch (\Exception $e) {
  24. $this->assertInstanceOf('InvalidArgumentException', $e, '->configLoad() throws an \InvalidArgumentException if the Propel path is not set.');
  25. }
  26. $configuration = $loader->configLoad(array('path' => '/propel'), $configuration);
  27. $this->assertEquals('/propel', $configuration->getParameter('propel.path'), '->configLoad() sets the Propel path');
  28. $configuration = $loader->configLoad(array(), $configuration);
  29. $this->assertEquals('/propel', $configuration->getParameter('propel.path'), '->configLoad() sets the Propel path');
  30. }
  31. public function testDbalLoad()
  32. {
  33. $configuration = new BuilderConfiguration();
  34. $loader = new PropelExtension();
  35. $configuration = $loader->dbalLoad(array(), $configuration);
  36. $this->assertEquals('Propel', $configuration->getParameter('propel.class'), '->dbalLoad() loads the propel.xml file if not already loaded');
  37. // propel.dbal.default_connection
  38. $this->assertEquals('default', $configuration->getParameter('propel.dbal.default_connection'), '->dbalLoad() overrides existing configuration options');
  39. $configuration = $loader->dbalLoad(array('default_connection' => 'foo'), $configuration);
  40. $this->assertEquals('foo', $configuration->getParameter('propel.dbal.default_connection'), '->dbalLoad() overrides existing configuration options');
  41. $configuration = $loader->dbalLoad(array(), $configuration);
  42. $this->assertEquals('foo', $configuration->getParameter('propel.dbal.default_connection'), '->dbalLoad() overrides existing configuration options');
  43. $configuration = new BuilderConfiguration();
  44. $loader = new PropelExtension();
  45. $configuration = $loader->dbalLoad(array('password' => 'foo'), $configuration);
  46. $arguments = $configuration->getDefinition('propel.configuration')->getArguments();
  47. $config = $arguments[0];
  48. $this->assertEquals('foo', $config['datasources']['default']['connection']['password']);
  49. $this->assertEquals('root', $config['datasources']['default']['connection']['user']);
  50. $configuration = $loader->dbalLoad(array('user' => 'foo'), $configuration);
  51. $this->assertEquals('foo', $config['datasources']['default']['connection']['password']);
  52. $this->assertEquals('root', $config['datasources']['default']['connection']['user']);
  53. }
  54. }