PluginLoaderTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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_Loader
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 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. // Call Zend_Loader_PluginLoaderTest::main() if this source file is executed directly.
  23. if (!defined('PHPUnit_MAIN_METHOD')) {
  24. define('PHPUnit_MAIN_METHOD', 'Zend_Loader_PluginLoaderTest::main');
  25. }
  26. require_once 'Zend/Loader/PluginLoader.php';
  27. /**
  28. * Test class for Zend_Loader_PluginLoader.
  29. *
  30. * @category Zend
  31. * @package Zend_Loader
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Loader
  36. */
  37. class Zend_Loader_PluginLoaderTest extends PHPUnit_Framework_TestCase
  38. {
  39. protected $_includeCache;
  40. /**
  41. * Runs the test methods of this class.
  42. *
  43. * @return void
  44. */
  45. public static function main()
  46. {
  47. $suite = new PHPUnit_Framework_TestSuite("Zend_Loader_PluginLoaderTest");
  48. $result = PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. /**
  51. * Sets up the fixture, for example, open a network connection.
  52. * This method is called before a test is executed.
  53. *
  54. * @return void
  55. */
  56. public function setUp()
  57. {
  58. if (file_exists($this->_includeCache)) {
  59. unlink($this->_includeCache);
  60. }
  61. Zend_Loader_PluginLoader::setIncludeFileCache(null);
  62. $this->_includeCache = dirname(__FILE__) . '/_files/includeCache.inc.php';
  63. $this->libPath = realpath(dirname(__FILE__) . '/../../../library');
  64. $this->key = null;
  65. }
  66. /**
  67. * Tears down the fixture, for example, close a network connection.
  68. * This method is called after a test is executed.
  69. *
  70. * @return void
  71. */
  72. public function tearDown()
  73. {
  74. $this->clearStaticPaths();
  75. Zend_Loader_PluginLoader::setIncludeFileCache(null);
  76. if (file_exists($this->_includeCache)) {
  77. unlink($this->_includeCache);
  78. }
  79. }
  80. public function clearStaticPaths()
  81. {
  82. if (null !== $this->key) {
  83. $loader = new Zend_Loader_PluginLoader(array(), $this->key);
  84. $loader->clearPaths();
  85. }
  86. }
  87. public function testAddPrefixPathNonStatically()
  88. {
  89. $loader = new Zend_Loader_PluginLoader();
  90. $loader->addPrefixPath('Zend_View', $this->libPath . '/Zend/View')
  91. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
  92. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend');
  93. $paths = $loader->getPaths();
  94. $this->assertEquals(2, count($paths));
  95. $this->assertTrue(array_key_exists('Zend_View_', $paths));
  96. $this->assertTrue(array_key_exists('Zend_Loader_', $paths));
  97. $this->assertEquals(1, count($paths['Zend_View_']));
  98. $this->assertEquals(2, count($paths['Zend_Loader_']));
  99. }
  100. public function testAddPrefixPathMultipleTimes()
  101. {
  102. $loader = new Zend_Loader_PluginLoader();
  103. $loader->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
  104. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader');
  105. $paths = $loader->getPaths();
  106. $this->assertTrue(is_array($paths));
  107. $this->assertEquals(1, count($paths['Zend_Loader_']));
  108. }
  109. public function testAddPrefixPathStatically()
  110. {
  111. $this->key = 'foobar';
  112. $loader = new Zend_Loader_PluginLoader(array(), $this->key);
  113. $loader->addPrefixPath('Zend_View', $this->libPath . '/Zend/View')
  114. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
  115. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend');
  116. $paths = $loader->getPaths();
  117. $this->assertEquals(2, count($paths));
  118. $this->assertTrue(array_key_exists('Zend_View_', $paths));
  119. $this->assertTrue(array_key_exists('Zend_Loader_', $paths));
  120. $this->assertEquals(1, count($paths['Zend_View_']));
  121. $this->assertEquals(2, count($paths['Zend_Loader_']));
  122. }
  123. public function testAddPrefixPathThrowsExceptionWithNonStringPrefix()
  124. {
  125. $loader = new Zend_Loader_PluginLoader();
  126. try {
  127. $loader->addPrefixPath(array(), $this->libPath);
  128. $this->fail('addPrefixPath() should throw exception with non-string prefix');
  129. } catch (Exception $e) {
  130. }
  131. }
  132. public function testAddPrefixPathThrowsExceptionWithNonStringPath()
  133. {
  134. $loader = new Zend_Loader_PluginLoader();
  135. try {
  136. $loader->addPrefixPath('Foo_Bar', array());
  137. $this->fail('addPrefixPath() should throw exception with non-string path');
  138. } catch (Exception $e) {
  139. }
  140. }
  141. public function testRemoveAllPathsForGivenPrefixNonStatically()
  142. {
  143. $loader = new Zend_Loader_PluginLoader();
  144. $loader->addPrefixPath('Zend_View', $this->libPath . '/Zend/View')
  145. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
  146. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend');
  147. $paths = $loader->getPaths('Zend_Loader');
  148. $this->assertEquals(2, count($paths));
  149. $loader->removePrefixPath('Zend_Loader');
  150. $this->assertFalse($loader->getPaths('Zend_Loader'));
  151. }
  152. public function testRemoveAllPathsForGivenPrefixStatically()
  153. {
  154. $this->key = 'foobar';
  155. $loader = new Zend_Loader_PluginLoader(array(), $this->key);
  156. $loader->addPrefixPath('Zend_View', $this->libPath . '/Zend/View')
  157. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
  158. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend');
  159. $paths = $loader->getPaths('Zend_Loader');
  160. $this->assertEquals(2, count($paths));
  161. $loader->removePrefixPath('Zend_Loader');
  162. $this->assertFalse($loader->getPaths('Zend_Loader'));
  163. }
  164. public function testRemovePrefixPathThrowsExceptionIfPrefixNotRegistered()
  165. {
  166. $loader = new Zend_Loader_PluginLoader();
  167. try {
  168. $loader->removePrefixPath('Foo_Bar');
  169. $this->fail('Removing non-existent prefix should throw an exception');
  170. } catch (Exception $e) {
  171. }
  172. }
  173. public function testRemovePrefixPathThrowsExceptionIfPrefixPathPairNotRegistered()
  174. {
  175. $loader = new Zend_Loader_PluginLoader();
  176. $loader->addPrefixPath('Foo_Bar', realpath(dirname(__FILE__)));
  177. $paths = $loader->getPaths();
  178. $this->assertTrue(isset($paths['Foo_Bar_']));
  179. try {
  180. $loader->removePrefixPath('Foo_Bar', $this->libPath);
  181. $this->fail('Removing non-existent prefix/path pair should throw an exception');
  182. } catch (Exception $e) {
  183. }
  184. }
  185. public function testClearPathsNonStaticallyClearsPathArray()
  186. {
  187. $loader = new Zend_Loader_PluginLoader();
  188. $loader->addPrefixPath('Zend_View', $this->libPath . '/Zend/View')
  189. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
  190. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend');
  191. $paths = $loader->getPaths();
  192. $this->assertEquals(2, count($paths));
  193. $loader->clearPaths();
  194. $paths = $loader->getPaths();
  195. $this->assertEquals(0, count($paths));
  196. }
  197. public function testClearPathsStaticallyClearsPathArray()
  198. {
  199. $this->key = 'foobar';
  200. $loader = new Zend_Loader_PluginLoader(array(), $this->key);
  201. $loader->addPrefixPath('Zend_View', $this->libPath . '/Zend/View')
  202. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
  203. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend');
  204. $paths = $loader->getPaths();
  205. $this->assertEquals(2, count($paths));
  206. $loader->clearPaths();
  207. $paths = $loader->getPaths();
  208. $this->assertEquals(0, count($paths));
  209. }
  210. public function testClearPathsWithPrefixNonStaticallyClearsPathArray()
  211. {
  212. $loader = new Zend_Loader_PluginLoader();
  213. $loader->addPrefixPath('Zend_View', $this->libPath . '/Zend/View')
  214. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
  215. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend');
  216. $paths = $loader->getPaths();
  217. $this->assertEquals(2, count($paths));
  218. $loader->clearPaths('Zend_Loader');
  219. $paths = $loader->getPaths();
  220. $this->assertEquals(1, count($paths));
  221. }
  222. public function testClearPathsWithPrefixStaticallyClearsPathArray()
  223. {
  224. $this->key = 'foobar';
  225. $loader = new Zend_Loader_PluginLoader(array(), $this->key);
  226. $loader->addPrefixPath('Zend_View', $this->libPath . '/Zend/View')
  227. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend/Loader')
  228. ->addPrefixPath('Zend_Loader', $this->libPath . '/Zend');
  229. $paths = $loader->getPaths();
  230. $this->assertEquals(2, count($paths));
  231. $loader->clearPaths('Zend_Loader');
  232. $paths = $loader->getPaths();
  233. $this->assertEquals(1, count($paths));
  234. }
  235. public function testGetClassNameNonStaticallyReturnsFalseWhenClassNotLoaded()
  236. {
  237. $loader = new Zend_Loader_PluginLoader();
  238. $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
  239. $this->assertFalse($loader->getClassName('FormElement'));
  240. }
  241. public function testGetClassNameStaticallyReturnsFalseWhenClassNotLoaded()
  242. {
  243. $this->key = 'foobar';
  244. $loader = new Zend_Loader_PluginLoader(array(), $this->key);
  245. $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
  246. $this->assertFalse($loader->getClassName('FormElement'));
  247. }
  248. public function testLoadPluginNonStaticallyLoadsClass()
  249. {
  250. $loader = new Zend_Loader_PluginLoader();
  251. $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
  252. try {
  253. $className = $loader->load('FormButton');
  254. } catch (Exception $e) {
  255. $paths = $loader->getPaths();
  256. $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
  257. }
  258. $this->assertEquals('Zend_View_Helper_FormButton', $className);
  259. $this->assertTrue(class_exists('Zend_View_Helper_FormButton', false));
  260. $this->assertTrue($loader->isLoaded('FormButton'));
  261. }
  262. public function testLoadPluginStaticallyLoadsClass()
  263. {
  264. $this->key = 'foobar';
  265. $loader = new Zend_Loader_PluginLoader(array(), $this->key);
  266. $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
  267. try {
  268. $className = $loader->load('FormRadio');
  269. } catch (Exception $e) {
  270. $paths = $loader->getPaths();
  271. $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
  272. }
  273. $this->assertEquals('Zend_View_Helper_FormRadio', $className);
  274. $this->assertTrue(class_exists('Zend_View_Helper_FormRadio', false));
  275. $this->assertTrue($loader->isLoaded('FormRadio'));
  276. }
  277. public function testLoadThrowsExceptionIfFileFoundInPrefixButClassNotLoaded()
  278. {
  279. $loader = new Zend_Loader_PluginLoader();
  280. $loader->addPrefixPath('Foo_Helper', $this->libPath . '/Zend/View/Helper');
  281. try {
  282. $className = $loader->load('Doctype');
  283. $this->fail('Invalid prefix for a path should throw an exception');
  284. } catch (Exception $e) {
  285. }
  286. }
  287. public function testLoadThrowsExceptionIfNoHelperClassLoaded()
  288. {
  289. $loader = new Zend_Loader_PluginLoader();
  290. $loader->addPrefixPath('Foo_Helper', $this->libPath . '/Zend/View/Helper');
  291. try {
  292. $className = $loader->load('FooBarBazBat');
  293. $this->fail('Not finding a helper should throw an exception');
  294. } catch (Exception $e) {
  295. }
  296. }
  297. public function testGetClassAfterNonStaticLoadReturnsResolvedClassName()
  298. {
  299. $loader = new Zend_Loader_PluginLoader();
  300. $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
  301. try {
  302. $className = $loader->load('FormSelect');
  303. } catch (Exception $e) {
  304. $paths = $loader->getPaths();
  305. $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
  306. }
  307. $this->assertEquals($className, $loader->getClassName('FormSelect'));
  308. $this->assertEquals('Zend_View_Helper_FormSelect', $loader->getClassName('FormSelect'));
  309. }
  310. public function testGetClassAfterStaticLoadReturnsResolvedClassName()
  311. {
  312. $this->key = 'foobar';
  313. $loader = new Zend_Loader_PluginLoader(array(), $this->key);
  314. $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
  315. try {
  316. $className = $loader->load('FormCheckbox');
  317. } catch (Exception $e) {
  318. $paths = $loader->getPaths();
  319. $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
  320. }
  321. $this->assertEquals($className, $loader->getClassName('FormCheckbox'));
  322. $this->assertEquals('Zend_View_Helper_FormCheckbox', $loader->getClassName('FormCheckbox'));
  323. }
  324. public function testClassFilesAreSearchedInLifoOrder()
  325. {
  326. $loader = new Zend_Loader_PluginLoader(array());
  327. $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
  328. $loader->addPrefixPath('ZfTest', dirname(__FILE__) . '/_files/ZfTest');
  329. try {
  330. $className = $loader->load('FormSubmit');
  331. } catch (Exception $e) {
  332. $paths = $loader->getPaths();
  333. $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
  334. }
  335. $this->assertEquals($className, $loader->getClassName('FormSubmit'));
  336. $this->assertEquals('ZfTest_FormSubmit', $loader->getClassName('FormSubmit'));
  337. }
  338. /**
  339. * @group ZF-2741
  340. */
  341. public function testWin32UnderscoreSpacedShortNamesWillLoad()
  342. {
  343. $loader = new Zend_Loader_PluginLoader(array());
  344. $loader->addPrefixPath('Zend_Filter', $this->libPath . '/Zend/Filter');
  345. try {
  346. // Plugin loader will attempt to load "c:\path\to\library/Zend/Filter/Word\UnderscoreToDash.php"
  347. $className = $loader->load('Word_UnderscoreToDash');
  348. } catch (Exception $e) {
  349. $paths = $loader->getPaths();
  350. $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
  351. }
  352. $this->assertEquals($className, $loader->getClassName('Word_UnderscoreToDash'));
  353. }
  354. /**
  355. * @group ZF-4670
  356. */
  357. public function testIncludeCacheShouldBeNullByDefault()
  358. {
  359. $this->assertNull(Zend_Loader_PluginLoader::getIncludeFileCache());
  360. }
  361. /**
  362. * @group ZF-4670
  363. */
  364. public function testPluginLoaderShouldAllowSpecifyingIncludeFileCache()
  365. {
  366. $cacheFile = $this->_includeCache;
  367. $this->testIncludeCacheShouldBeNullByDefault();
  368. Zend_Loader_PluginLoader::setIncludeFileCache($cacheFile);
  369. $this->assertEquals($cacheFile, Zend_Loader_PluginLoader::getIncludeFileCache());
  370. }
  371. /**
  372. * @group ZF-4670
  373. * @expectedException Zend_Loader_PluginLoader_Exception
  374. */
  375. public function testPluginLoaderShouldThrowExceptionWhenPathDoesNotExist()
  376. {
  377. $cacheFile = dirname(__FILE__) . '/_filesDoNotExist/includeCache.inc.php';
  378. $this->testIncludeCacheShouldBeNullByDefault();
  379. Zend_Loader_PluginLoader::setIncludeFileCache($cacheFile);
  380. $this->fail('Should not allow specifying invalid cache file path');
  381. }
  382. /**
  383. * @group ZF-4670
  384. */
  385. public function testPluginLoaderShouldAppendIncludeCacheWhenClassIsFound()
  386. {
  387. $cacheFile = $this->_includeCache;
  388. Zend_Loader_PluginLoader::setIncludeFileCache($cacheFile);
  389. $loader = new Zend_Loader_PluginLoader(array());
  390. $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
  391. $loader->addPrefixPath('ZfTest', dirname(__FILE__) . '/_files/ZfTest');
  392. try {
  393. $className = $loader->load('CacheTest');
  394. } catch (Exception $e) {
  395. $paths = $loader->getPaths();
  396. $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
  397. }
  398. $this->assertTrue(file_exists($cacheFile));
  399. $cache = file_get_contents($cacheFile);
  400. $this->assertContains('CacheTest.php', $cache);
  401. }
  402. /**
  403. * @group ZF-5208
  404. */
  405. public function testStaticRegistryNamePersistsInDifferentLoaderObjects()
  406. {
  407. $loader1 = new Zend_Loader_PluginLoader(array(), "PluginLoaderStaticNamespace");
  408. $loader1->addPrefixPath("Zend_View_Helper", "Zend/View/Helper");
  409. $loader2 = new Zend_Loader_PluginLoader(array(), "PluginLoaderStaticNamespace");
  410. $this->assertEquals(array(
  411. "Zend_View_Helper_" => array("Zend/View/Helper/"),
  412. ), $loader2->getPaths());
  413. }
  414. /**
  415. * @group ZF-4697
  416. */
  417. public function testClassFilesGrabCorrectPathForLoadedClasses()
  418. {
  419. require_once 'Zend/View/Helper/DeclareVars.php';
  420. $reflection = new ReflectionClass('Zend_View_Helper_DeclareVars');
  421. $expected = $reflection->getFileName();
  422. $loader = new Zend_Loader_PluginLoader(array());
  423. $loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
  424. $loader->addPrefixPath('ZfTest', dirname(__FILE__) . '/_files/ZfTest');
  425. try {
  426. // Class in /Zend/View/Helper and not in /_files/ZfTest
  427. $className = $loader->load('DeclareVars');
  428. } catch (Exception $e) {
  429. $paths = $loader->getPaths();
  430. $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
  431. }
  432. $classPath = $loader->getClassPath('DeclareVars');
  433. $this->assertContains($expected, $classPath);
  434. }
  435. /**
  436. * @group ZF-7350
  437. */
  438. public function testPrefixesEndingInBackslashDenoteNamespacedClasses()
  439. {
  440. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  441. $this->markTestSkipped(__CLASS__ . '::' . __METHOD__ . ' requires PHP 5.3.0 or greater');
  442. return;
  443. }
  444. $loader = new Zend_Loader_PluginLoader(array());
  445. $loader->addPrefixPath('Zfns\\', dirname(__FILE__) . '/_files/Zfns');
  446. try {
  447. $className = $loader->load('Foo');
  448. } catch (Exception $e) {
  449. $paths = $loader->getPaths();
  450. $this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
  451. }
  452. $this->assertEquals('Zfns\\Foo', $className);
  453. $this->assertEquals('Zfns\\Foo', $loader->getClassName('Foo'));
  454. }
  455. /**
  456. * @group ZF-9721
  457. */
  458. public function testRemovePrefixPathThrowsExceptionIfPathNotRegisteredInPrefix()
  459. {
  460. try {
  461. $loader = new Zend_Loader_PluginLoader(array('My_Namespace_' => 'My/Namespace/'));
  462. $loader->removePrefixPath('My_Namespace_', 'ZF9721');
  463. $this->fail();
  464. } catch (Exception $e) {
  465. $this->assertTrue($e instanceof Zend_Loader_PluginLoader_Exception);
  466. $this->assertContains('Prefix My_Namespace_ / Path ZF9721', $e->getMessage());
  467. }
  468. $this->assertEquals(1, count($loader->getPaths('My_Namespace_')));
  469. }
  470. /**
  471. * @group ZF-11330
  472. */
  473. public function testLoadClassesWithBackslashInName()
  474. {
  475. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  476. $this->markTestSkipped(__CLASS__ . '::' . __METHOD__ . ' requires PHP 5.3.0 or greater');
  477. return;
  478. }
  479. $loader = new Zend_Loader_PluginLoader(array());
  480. $loader->addPrefixPath('Zfns\\', dirname(__FILE__) . '/_files/Zfns');
  481. try {
  482. $className = $loader->load('Foo\\Bar');
  483. } catch (Exception $e) {
  484. $this->fail(sprintf("Failed loading helper with backslashes in name"));
  485. }
  486. $this->assertEquals('Zfns\\Foo\\Bar', $className);
  487. }
  488. /**
  489. * @url https://github.com/zendframework/zf1/issues/152
  490. */
  491. public function testLoadClassesWithBackslashAndUnderscoreInName()
  492. {
  493. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  494. $this->markTestSkipped(__CLASS__ . '::' . __METHOD__ . ' requires PHP 5.3.0 or greater');
  495. return;
  496. }
  497. $loader = new Zend_Loader_PluginLoader(array());
  498. $loader->addPrefixPath('Zfns\\Foo_', dirname(__FILE__) . '/_files/Zfns/Foo');
  499. try {
  500. $className = $loader->load('Demo');
  501. } catch (Exception $e) {
  502. $this->fail(sprintf("Failed loading helper with backslashes and underscores in name"));
  503. }
  504. $this->assertEquals('Zfns\Foo_Demo', $className);
  505. }
  506. }
  507. // Call Zend_Loader_PluginLoaderTest::main() if this source file is executed directly.
  508. if (PHPUnit_MAIN_METHOD === 'Zend_Loader_PluginLoaderTest::main') {
  509. Zend_Loader_PluginLoaderTest::main();
  510. }