ArrayTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Config
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /**
  27. * Zend_Config
  28. */
  29. require_once 'Zend/Config.php';
  30. /**
  31. * Zend_Config_Writer_Array
  32. */
  33. require_once 'Zend/Config/Writer/Array.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Config
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Config_Writer_ArrayTest extends PHPUnit_Framework_TestCase
  42. {
  43. protected $_tempName;
  44. public function setUp()
  45. {
  46. $this->_tempName = tempnam(dirname(__FILE__) . '/temp', 'tmp');
  47. }
  48. public function tearDown()
  49. {
  50. @unlink($this->_tempName);
  51. }
  52. public function testNoFilenameSet()
  53. {
  54. $writer = new Zend_Config_Writer_Array(array('config' => new Zend_Config(array())));
  55. try {
  56. $writer->write();
  57. $this->fail('An expected Zend_Config_Exception has not been raised');
  58. } catch (Zend_Config_Exception $expected) {
  59. $this->assertContains('No filename was set', $expected->getMessage());
  60. }
  61. }
  62. public function testNoConfigSet()
  63. {
  64. $writer = new Zend_Config_Writer_Array(array('filename' => $this->_tempName));
  65. try {
  66. $writer->write();
  67. $this->fail('An expected Zend_Config_Exception has not been raised');
  68. } catch (Zend_Config_Exception $expected) {
  69. $this->assertContains('No config was set', $expected->getMessage());
  70. }
  71. }
  72. public function testFileNotWritable()
  73. {
  74. $writer = new Zend_Config_Writer_Array(array('config' => new Zend_Config(array()), 'filename' => '/../../../'));
  75. try {
  76. $writer->write();
  77. $this->fail('An expected Zend_Config_Exception has not been raised');
  78. } catch (Zend_Config_Exception $expected) {
  79. $this->assertContains('Could not write to file', $expected->getMessage());
  80. }
  81. }
  82. public function testWriteAndRead()
  83. {
  84. $config = new Zend_Config(array('test' => 'foo'));
  85. $writer = new Zend_Config_Writer_Array(array('config' => $config, 'filename' => $this->_tempName));
  86. $writer->write();
  87. $config = new Zend_Config(include $this->_tempName);
  88. $this->assertEquals('foo', $config->test);
  89. }
  90. public function testArgumentOverride()
  91. {
  92. $config = new Zend_Config(array('test' => 'foo'));
  93. $writer = new Zend_Config_Writer_Array();
  94. $writer->write($this->_tempName, $config);
  95. $config = new Zend_Config(include $this->_tempName);
  96. $this->assertEquals('foo', $config->test);
  97. }
  98. }