Changeset 537
- Timestamp:
- 2008年10月04日 16時15分43秒 (2 months ago)
- Location:
- trunk
- Files:
-
- 3 moved
-
src/Piece/ORM/Config/Reader.php (moved) (moved from trunk/src/Piece/ORM/Config/ConfigFactory.php) (8 diffs)
-
tests/Piece/ORM/Config/ReaderTest (moved) (moved from trunk/tests/Piece/ORM/Config/ConfigFactoryTest)
-
tests/Piece/ORM/Config/ReaderTest.php (moved) (moved from trunk/tests/Piece/ORM/Config/ConfigFactoryTest.php) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Piece/ORM/Config/Reader.php
r526 r537 45 45 require_once 'spyc.php5'; 46 46 47 // {{{ Piece::ORM::Config:: ConfigFactory47 // {{{ Piece::ORM::Config::Reader 48 48 49 49 /** … … 56 56 * @since Class available since Release 0.1.0 57 57 */ 58 class ConfigFactory58 class Reader 59 59 { 60 60 … … 77 77 */ 78 78 79 private $_configDirectory; 80 79 81 /**#@-*/ 80 82 … … 84 86 85 87 // }}} 86 // {{{ factory() 88 // {{{ __construct() 89 90 /** 91 * @param string $configDirectory 92 */ 93 public function __construct($configDirectory = null) 94 { 95 $this->_configDirectory = $configDirectory; 96 } 97 98 // }}} 99 // {{{ read() 87 100 88 101 /** 89 102 * Creates a Piece::ORM::Config object from a configuration file or a cache. 90 103 * 91 * @param string $configDirectory92 104 * @return Piece::ORM::Config 93 105 * @throws Piece::ORM::Exception 94 106 */ 95 public static function factory($configDirectory = null)96 { 97 if (is_null($ configDirectory)) {107 public function read() 108 { 109 if (is_null($this->_configDirectory)) { 98 110 return new Config(); 99 111 } 100 112 101 if (!file_exists($ configDirectory)) {102 throw new Exception("The configuration directory [ $configDirectory] is not found.");103 } 104 105 $dslFile = " $configDirectory/piece-orm-config.yaml";113 if (!file_exists($this->_configDirectory)) { 114 throw new Exception("The configuration directory [ {$this->_configDirectory} ] is not found."); 115 } 116 117 $dslFile = "{$this->_configDirectory}/piece-orm-config.yaml"; 106 118 if (!file_exists($dslFile)) { 107 119 throw new Exception("The configuration file [ $dslFile ] is not found."); … … 113 125 114 126 if (is_null(Registry::getContext()->getCacheDirectory())) { 115 return self::_createConfigurationFromFile($dslFile);127 return $this->_createConfigurationFromFile($dslFile); 116 128 } 117 129 … … 122 134 E_USER_WARNING 123 135 ); 124 return self::_createConfigurationFromFile($dslFile);136 return $this->_createConfigurationFromFile($dslFile); 125 137 } 126 138 … … 132 144 E_USER_WARNING 133 145 ); 134 return self::_createConfigurationFromFile($dslFile);135 } 136 137 return self::_getConfiguration($dslFile);146 return $this->_createConfigurationFromFile($dslFile); 147 } 148 149 return $this->_getConfiguration($dslFile); 138 150 } 139 151 … … 183 195 E_USER_WARNING 184 196 ); 185 return self::_createConfigurationFromFile($dslFile);197 return $this->_createConfigurationFromFile($dslFile); 186 198 } 187 199 188 200 if (!$config) { 189 $config = self::_createConfigurationFromFile($dslFile);201 $config = $this->_createConfigurationFromFile($dslFile); 190 202 $result = $cache->save($config); 191 203 if (::PEAR::isError($result)) { -
trunk/tests/Piece/ORM/Config/ReaderTest.php
r526 r537 38 38 namespace Piece::ORM::Config; 39 39 40 use Piece::ORM::Config:: ConfigFactory;40 use Piece::ORM::Config::Reader; 41 41 use Piece::ORM::Context; 42 42 use Piece::ORM::Context::Registry; … … 44 44 require_once 'spyc.php5'; 45 45 46 // {{{ Piece::ORM::Config:: ConfigFactoryTest46 // {{{ Piece::ORM::Config::ReaderTest 47 47 48 48 /** 49 * Some tests for Piece::ORM::Config:: ConfigFactory.49 * Some tests for Piece::ORM::Config::Reader. 50 50 * 51 51 * @package Piece_ORM … … 55 55 * @since Class available since Release 0.1.0 56 56 */ 57 class ConfigFactoryTest extends ::PHPUnit_Framework_TestCase57 class ReaderTest extends ::PHPUnit_Framework_TestCase 58 58 { 59 59 … … 102 102 public function testShouldCreateAnObjectWithoutConfigurationFile() 103 103 { 104 $this->assertType('Piece::ORM::Config', ConfigFactory::factory()); 104 $reader = new Reader(); 105 106 $this->assertType('Piece::ORM::Config', $reader->read()); 105 107 } 106 108 … … 110 112 public function testShouldRaiseAnExceptionWhenAGivenConfigurationDirectoryIsNotFound() 111 113 { 112 ConfigFactory::factory(dirname(__FILE__) . '/foo', $this->_cacheDirectory); 114 $reader = new Reader(dirname(__FILE__) . '/foo'); 115 $reader->read(); 113 116 } 114 117 … … 118 121 public function testShouldRaiseAnExceptionWhenAGivenConfigurationFileIsNotFound() 119 122 { 120 ConfigFactory::factory(dirname(__FILE__), $this->_cacheDirectory); 123 $reader = new Reader(dirname(__FILE__)); 124 $reader->read(); 121 125 } 122 126 123 127 public function testShouldCreateAnObjectEvenThoughAGivenCacheDirectoryIsNotFound() 124 128 { 125 $this->assertType('Piece::ORM::Config', 126 @ConfigFactory::factory($this->_cacheDirectory, 127 dirname(__FILE__) . '/foo') 128 ); 129 $reader = new Reader($this->_cacheDirectory); 130 131 $this->assertType('Piece::ORM::Config', $reader->read()); 129 132 } 130 133 … … 132 135 { 133 136 $dsl = ::Spyc::YAMLLoad("{$this->_cacheDirectory}/piece-orm-config.yaml"); 134 $config = ConfigFactory::factory($this->_cacheDirectory, $this->_cacheDirectory); 137 $reader = new Reader($this->_cacheDirectory); 138 $config = $reader->read(); 135 139 136 140 $this->assertEquals(2, count($dsl['databases'])); … … 151 155 $oldDirectory = getcwd(); 152 156 chdir("{$this->_cacheDirectory}/CacheIDsShouldBeUniqueInOneCacheDirectory1"); 153 ConfigFactory::factory('.', $this->_cacheDirectory); 157 $reader = new Reader('.'); 158 $reader->read(); 154 159 155 160 $this->assertEquals(1, $this->_getCacheFileCount($this->_cacheDirectory)); 156 161 157 162 chdir("{$this->_cacheDirectory}/CacheIDsShouldBeUniqueInOneCacheDirectory2"); 158 ConfigFactory::factory('.', $this->_cacheDirectory); 163 $reader = new Reader('.'); 164 $reader->read(); 159 165 160 166 $this->assertEquals(2, $this->_getCacheFileCount($this->_cacheDirectory));
