Author: maksim_ka Date: 2010-02-13 15:39:28 +0100 (Sat, 13 Feb 2010) New Revision: 28004
Modified: plugins/sfPhpunitPlugin/branches/1.2/lib/fixture/sfPhpunitFixture.php plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitSeleniumTestCase.php plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitTestCase.class.php Log: [sfPhpunitPlugin][sf1.2] fix path on windows Modified: plugins/sfPhpunitPlugin/branches/1.2/lib/fixture/sfPhpunitFixture.php =================================================================== --- plugins/sfPhpunitPlugin/branches/1.2/lib/fixture/sfPhpunitFixture.php 2010-02-13 14:24:29 UTC (rev 28003) +++ plugins/sfPhpunitPlugin/branches/1.2/lib/fixture/sfPhpunitFixture.php 2010-02-13 14:39:28 UTC (rev 28004) @@ -16,7 +16,11 @@ * @method array getFilesPackage(string $file) * @method array getFilesCommon(string $file) * @method array getFilesSymfony(string $file) - * + * @method array getFileOwn(string $file) + * @method array getFilePackage(string $file) + * @method array getFileCommon(string $file) + * @method array getFileSymfony(string $file) + * * @package sfPhpunitPlugin * @subpackage fixture * @author Maksim Kotlyar <[email protected]> @@ -93,12 +97,17 @@ */ public function getDir($fixture_type = self::OWN) { - return self::getFixtureDir($this->_aggregator, $fixture_type); + return $this->_fixPath( self::getFixtureDir($this->_aggregator, $fixture_type) ); } /** * return files that matched criteria. * + * Pay attention to that this method add fixture extension so you can search only for the fixture files. + * + * @param string patter of the files to search + * @param string fixture type it's one of this class constant + * * @return array */ public function getFiles($file = null, $fixture_type = self::OWN) @@ -107,23 +116,43 @@ return sfFinder::type('file')->name($pattern)->maxdepth(0)->in($this->getDir($fixture_type)); } - + /** - * It's a magic method for minimuzing - * - * You can use it in a following way: - * - * getCONSTANT($file) - * loadCONSTANT($file) - * getDirCONSTANT() - * getFilesCONSTANT($file) - * + * return files that matched criteria. + * + * @param string the file name. You need to be sure that this file exists. + * @param string fixture type it's one of this class constant + * + * @throws Exception if the file was not found + * + * @return string return absolute path to the needed file + */ + public function getFile($file = null, $fixture_type = self::OWN) + { + $items = sfFinder::type('file') + ->name($file)->maxdepth(0)->in($this->getDir($fixture_type)); + if (empty($items)) { + throw new Exception('The needed file `'.$file.'` is not exist in the dir `'.$this->getDir($fixture_type).'` or maybe name was misspeld'); + } + + return $this->_fixPath( array_shift($items) ); + } + + + protected function _fixPath($path) + { + return str_replace(array("\\", "/"), DIRECTORY_SEPARATOR, $path); + } + + /** + * It's a magic method for shirter method calls + * * @param string $name * @param array $args - * + * * @throws Exception if Invalid method name - * @throws Exception if trying access not exist fixture level - * + * @throws Exception if trying access not exist fixture level + * * @return mixed */ public function __call($name, $args) @@ -132,21 +161,24 @@ $method = 'getDir'; $args[0] = $source = str_replace('getDir', '', $name); } else if (false !== strstr($name, 'load')) { - $method = 'load'; - $args[1] = $source = str_replace('load', '', $name); - } else if (false !== strstr($name, 'getFiles')) { - $method = 'getFiles'; + $method = 'load'; + $args[1] = $source = str_replace('load', '', $name); + } else if (false !== strstr($name, 'getFiles')) { + $method = 'getFiles'; $args[1] = $source = str_replace('getFiles', '', $name); - } else { - throw new Exception('Invalid method call '.__CLASS__.'::'.$name); - } - - $sources = array(self::OWN, self::PACKAGE, self::COMMON, self::SYMFONY); - if (!in_array($source, $sources)) { - throw new Exception('Invalid fixture source level. Allowed values `'.implode('`, `', $sources).'` but given `'.$source.'`'); - } - - return call_user_func_array(array($this, $method), $args); + } else if (false !== strstr($name, 'getFile')) { + $method = 'getFile'; + $args[1] = $source = str_replace('getFile', '', $name); + } else { + throw new Exception('Invalid method call '.__CLASS__.'::'.$name); + } + + $sources = array(self::OWN, self::PACKAGE, self::COMMON, self::SYMFONY); + if (!in_array($source, $sources)) { + throw new Exception('Invalid fixture source level. Allowed values `'.implode('`, `', $sources).'` but given `'.$source.'`'); + } + + return call_user_func_array(array($this, $method), $args); } protected function _getOption($name) @@ -184,33 +216,33 @@ { return sfContext::getInstance()->getConfiguration()->getApplication(); } - + /** - * + * * @param sfPhpunitFixtureAggregator $aggregator It's very important that it should one of the `sfPhpunitFixtureAggregator` childs interface * @param array $options - * - * @throws Exception if the given aggregator does not implemented the base `sfPhpunitFixtureAggregator` interface - * @throws Exception if the concret `sfPhpunitFixtureAggregator` child's interface was not defined - * + * + * @throws Exception if the given aggregator does not implemented the base `sfPhpunitFixtureAggregator` interface + * @throws Exception if the concret `sfPhpunitFixtureAggregator` child's interface was not defined + * * @return sfPhpunitFixture */ public static function build($aggregator, array $options = array()) { - $map = array( + $map = array( 'sfPhpunitFixturePropel' => 'sfPhpunitFixturePropelAggregator', 'sfPhpunitFixtureDoctrine' => 'sfPhpunitFixtureDoctrineAggregator', 'sfPhpunitFixtureDbUnit' => 'sfPhpunitFixtureDbUnitAggregator'); - - if (!$aggregator instanceof sfPhpunitFixtureAggregator) { - throw new Exception('For using fixtures from the testcase or suite `'.get_class($aggregator).'` you have to implement one of the following interfaces `'.implode('`, `', $map).'`'); - } - - foreach ($map as $class => $agg_type) { - if ($aggregator instanceof $agg_type) return new $class($aggregator); - } - - throw new Exception('It does not have any sence to implement `sfPhpunitFixtureAggregator` interface. Please check this once againg and implement its child\'s interfaces `'.implode('`, `', $map).'`'); + + if (!$aggregator instanceof sfPhpunitFixtureAggregator) { + throw new Exception('For using fixtures from the testcase or suite `'.get_class($aggregator).'` you have to implement one of the following interfaces `'.implode('`, `', $map).'`'); + } + + foreach ($map as $class => $agg_type) { + if ($aggregator instanceof $agg_type) return new $class($aggregator); + } + + throw new Exception('It does not have any sence to implement `sfPhpunitFixtureAggregator` interface. Please check this once againg and implement its child\'s interfaces `'.implode('`, `', $map).'`'); } /** @@ -228,7 +260,7 @@ if (!method_exists($aggregator, $getFixtureDir)) { throw new Exception('The static method `'.get_class($aggregator).'::'.$getFixtureDir.'` does not exist and so cannot be called'); } - + $path = call_user_func(array($aggregator, $getFixtureDir)); if (!file_exists($path)) { throw new Exception('The '.$type.' level fixture dir `'.$path.'` does not exist.'); Modified: plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitSeleniumTestCase.php =================================================================== --- plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitSeleniumTestCase.php 2010-02-13 14:24:29 UTC (rev 28003) +++ plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitSeleniumTestCase.php 2010-02-13 14:39:28 UTC (rev 28004) @@ -7,11 +7,11 @@ implements sfPhpunitFixtureAggregator { /** - * + * * @var sfPhpunitFixture */ protected $_fixture; - + /** * Dev hook for custom "setUp" stuff * Overwrite it in your test class, if you have to execute stuff before a test is called. @@ -33,7 +33,7 @@ */ public function setUp() { - $this->_startFillDriverWithDefaultOptions(); + $this->_startFillDriverWithDefaultOptions(); $this->_start(); } @@ -44,35 +44,43 @@ { $this->_end(); } - + public function getPackageFixtureDir() { $reflection = new ReflectionClass($this); $path = dirname($reflection->getFileName()); - $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . DIRECTORY_SEPARATOR) + 8, 0); - return $path; + $replace = 'fixtures'.DIRECTORY_SEPARATOR; + $search = 'phpunit' . DIRECTORY_SEPARATOR; + + return substr_replace($path, $replace, strpos($path, $search) + 8, 0); } public function getOwnFixtureDir() { $reflection = new ReflectionClass($this); $path = str_replace('.php', '', $reflection->getFileName()); - $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . DIRECTORY_SEPARATOR) + 8, 0); - return $path; + $replace = 'fixtures'.DIRECTORY_SEPARATOR; + $search = 'phpunit' . DIRECTORY_SEPARATOR; + + return substr_replace($path, $replace, strpos($path, $search) + 8, 0); } public function getCommonFixtureDir() { - return sfConfig::get('sf_test_dir').'/phpunit/fixtures/common'; + $path = array(sfConfig::get('sf_test_dir'), 'phpunit', 'fixtures', 'common'); + + return implode(DIRECTORY_SEPARATOR,$path); } public function getSymfonyFixtureDir() { - return sfConfig::get('sf_data_dir').'/fixtures'; + $path = array(sfConfig::get('sf_data_dir'), 'fixtures'); + + return implode(DIRECTORY_SEPARATOR, $path); } - + /** * * @@ -82,7 +90,7 @@ { if (!$this->_fixture) $this->_initFixture(); - return is_null($id) ? $this->_fixture : $this->_fixture->get($id); + return is_null($id) ? $this->_fixture : $this->_fixture->get($id); } protected function _initFixture(array $options = array()) @@ -93,14 +101,17 @@ protected function _startFillDriverWithDefaultOptions() { $selenium_options = sfConfig::get('app_sfPhpunitPlugin_selenium', array()); - + foreach ($selenium_options['driver'] as $option => $value) { if (false === $value) continue; $setOption = explode('_', $option); $setOption = 'set'.implode(array_map('ucfirst', $setOption)); + + // @TODO validate options if (!method_exists($this->drivers[0], $setOption)) { - throw new Exception('Invalid selenium option `'.$option.'` provided. Please check the app.yml config file'); + // remove this Exception for option setSpeed(300); + // throw new Exception('Invalid selenium option `'.$option.'` provided. Please check the app.yml config file'); } $this->drivers[0]->$setOption($value); Modified: plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitTestCase.class.php =================================================================== --- plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitTestCase.class.php 2010-02-13 14:24:29 UTC (rev 28003) +++ plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitTestCase.class.php 2010-02-13 14:39:28 UTC (rev 28004) @@ -54,28 +54,36 @@ { $reflection = new ReflectionClass($this); $path = dirname($reflection->getFileName()); - $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . DIRECTORY_SEPARATOR) + 8, 0); - return $path; + $replace = 'fixtures'.DIRECTORY_SEPARATOR; + $search = 'phpunit' . DIRECTORY_SEPARATOR; + + return substr_replace($path, $replace, strpos($path, $search) + 8, 0); } public function getOwnFixtureDir() { $reflection = new ReflectionClass($this); $path = str_replace('.php', '', $reflection->getFileName()); - $path = substr_replace($path, 'fixtures/', strpos($path, 'phpunit' . DIRECTORY_SEPARATOR) + 8, 0); - return $path; + $replace = 'fixtures'.DIRECTORY_SEPARATOR; + $search = 'phpunit' . DIRECTORY_SEPARATOR; + + return substr_replace($path, $replace, strpos($path, $search) + 8, 0); } public function getCommonFixtureDir() { - return sfConfig::get('sf_test_dir').'/phpunit/fixtures/common'; + $path = array(sfConfig::get('sf_test_dir'), 'phpunit', 'fixtures', 'common'); + + return implode(DIRECTORY_SEPARATOR,$path); } public function getSymfonyFixtureDir() { - return sfConfig::get('sf_data_dir').'/fixtures'; + $path = array(sfConfig::get('sf_data_dir'), 'fixtures'); + + return implode(DIRECTORY_SEPARATOR, $path); } /** -- You received this message because you are subscribed to the Google Groups "symfony SVN" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-svn?hl=en.
