ArrayTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. * @group Zend_Config
  41. */
  42. class Zend_Config_Writer_ArrayTest extends PHPUnit_Framework_TestCase
  43. {
  44. protected $_tempName;
  45. public function setUp()
  46. {
  47. $this->_tempName = tempnam(dirname(__FILE__) . '/temp', 'tmp');
  48. }
  49. public function tearDown()
  50. {
  51. @unlink($this->_tempName);
  52. }
  53. public function testNoFilenameSet()
  54. {
  55. $writer = new Zend_Config_Writer_Array(array('config' => new Zend_Config(array())));
  56. try {
  57. $writer->write();
  58. $this->fail('An expected Zend_Config_Exception has not been raised');
  59. } catch (Zend_Config_Exception $expected) {
  60. $this->assertContains('No filename was set', $expected->getMessage());
  61. }
  62. }
  63. public function testNoConfigSet()
  64. {
  65. $writer = new Zend_Config_Writer_Array(array('filename' => $this->_tempName));
  66. try {
  67. $writer->write();
  68. $this->fail('An expected Zend_Config_Exception has not been raised');
  69. } catch (Zend_Config_Exception $expected) {
  70. $this->assertContains('No config was set', $expected->getMessage());
  71. }
  72. }
  73. public function testFileNotWritable()
  74. {
  75. $writer = new Zend_Config_Writer_Array(array('config' => new Zend_Config(array()), 'filename' => '/../../../'));
  76. try {
  77. $writer->write();
  78. $this->fail('An expected Zend_Config_Exception has not been raised');
  79. } catch (Zend_Config_Exception $expected) {
  80. $this->assertContains('Could not write to file', $expected->getMessage());
  81. }
  82. }
  83. public function testWriteAndRead()
  84. {
  85. $config = new Zend_Config(array('test' => 'foo'));
  86. $writer = new Zend_Config_Writer_Array(array('config' => $config, 'filename' => $this->_tempName));
  87. $writer->write();
  88. $config = new Zend_Config(include $this->_tempName);
  89. $this->assertEquals('foo', $config->test);
  90. }
  91. public function testArgumentOverride()
  92. {
  93. $config = new Zend_Config(array('test' => 'foo'));
  94. $writer = new Zend_Config_Writer_Array();
  95. $writer->write($this->_tempName, $config);
  96. $config = new Zend_Config(include $this->_tempName);
  97. $this->assertEquals('foo', $config->test);
  98. }
  99. }