AutoloadGeneratorTest.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Autoload;
  12. use Composer\Autoload\AutoloadGenerator;
  13. use Composer\Package\Link;
  14. use Composer\Util\Filesystem;
  15. use Composer\Package\AliasPackage;
  16. use Composer\Package\Package;
  17. use Composer\TestCase;
  18. use Composer\Script\ScriptEvents;
  19. class AutoloadGeneratorTest extends TestCase
  20. {
  21. public $vendorDir;
  22. private $config;
  23. private $workingDir;
  24. private $im;
  25. private $repository;
  26. private $generator;
  27. private $fs;
  28. private $eventDispatcher;
  29. protected function setUp()
  30. {
  31. $this->fs = new Filesystem;
  32. $that = $this;
  33. $this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest-'.md5(uniqid('', true));
  34. $this->fs->ensureDirectoryExists($this->workingDir);
  35. $this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload';
  36. $this->ensureDirectoryExistsAndClear($this->vendorDir);
  37. $this->config = $this->getMock('Composer\Config');
  38. $this->config->expects($this->at(0))
  39. ->method('get')
  40. ->with($this->equalTo('vendor-dir'))
  41. ->will($this->returnCallback(function () use ($that) {
  42. return $that->vendorDir;
  43. }));
  44. $this->config->expects($this->at(1))
  45. ->method('get')
  46. ->with($this->equalTo('vendor-dir'))
  47. ->will($this->returnCallback(function () use ($that) {
  48. return $that->vendorDir;
  49. }));
  50. $this->origDir = getcwd();
  51. chdir($this->workingDir);
  52. $this->im = $this->getMockBuilder('Composer\Installer\InstallationManager')
  53. ->disableOriginalConstructor()
  54. ->getMock();
  55. $this->im->expects($this->any())
  56. ->method('getInstallPath')
  57. ->will($this->returnCallback(function ($package) use ($that) {
  58. $targetDir = $package->getTargetDir();
  59. return $that->vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : '');
  60. }));
  61. $this->repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
  62. $this->eventDispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
  63. ->disableOriginalConstructor()
  64. ->getMock();
  65. $this->generator = new AutoloadGenerator($this->eventDispatcher);
  66. }
  67. protected function tearDown()
  68. {
  69. chdir($this->origDir);
  70. if (is_dir($this->workingDir)) {
  71. $this->fs->removeDirectory($this->workingDir);
  72. }
  73. if (is_dir($this->vendorDir)) {
  74. $this->fs->removeDirectory($this->vendorDir);
  75. }
  76. }
  77. public function testMainPackageAutoloading()
  78. {
  79. $package = new Package('a', '1.0', '1.0');
  80. $package->setAutoload(array(
  81. 'psr-0' => array(
  82. 'Main' => 'src/',
  83. 'Lala' => array('src/', 'lib/'),
  84. ),
  85. 'psr-4' => array(
  86. 'Acme\Fruit\\' => 'src-fruit/',
  87. 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
  88. ),
  89. 'classmap' => array('composersrc/'),
  90. ));
  91. $this->repository->expects($this->once())
  92. ->method('getCanonicalPackages')
  93. ->will($this->returnValue(array()));
  94. $this->fs->ensureDirectoryExists($this->workingDir.'/composer');
  95. $this->fs->ensureDirectoryExists($this->workingDir.'/src');
  96. $this->fs->ensureDirectoryExists($this->workingDir.'/lib');
  97. $this->fs->ensureDirectoryExists($this->workingDir.'/src-fruit');
  98. $this->fs->ensureDirectoryExists($this->workingDir.'/src-cake');
  99. $this->fs->ensureDirectoryExists($this->workingDir.'/lib-cake');
  100. $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc');
  101. file_put_contents($this->workingDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
  102. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_1');
  103. // Assert that autoload_namespaces.php was correctly generated.
  104. $this->assertAutoloadFiles('main', $this->vendorDir.'/composer');
  105. // Assert that autoload_psr4.php was correctly generated.
  106. $this->assertAutoloadFiles('psr4', $this->vendorDir.'/composer', 'psr4');
  107. // Assert that autoload_classmap.php was correctly generated.
  108. $this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
  109. }
  110. public function testVendorDirSameAsWorkingDir()
  111. {
  112. $this->vendorDir = $this->workingDir;
  113. $package = new Package('a', '1.0', '1.0');
  114. $package->setAutoload(array(
  115. 'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
  116. 'psr-4' => array(
  117. 'Acme\Fruit\\' => 'src-fruit/',
  118. 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
  119. ),
  120. 'classmap' => array('composersrc/'),
  121. ));
  122. $this->repository->expects($this->once())
  123. ->method('getCanonicalPackages')
  124. ->will($this->returnValue(array()));
  125. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  126. $this->fs->ensureDirectoryExists($this->vendorDir.'/src/Main');
  127. file_put_contents($this->vendorDir.'/src/Main/Foo.php', '<?php namespace Main; class Foo {}');
  128. $this->fs->ensureDirectoryExists($this->vendorDir.'/composersrc');
  129. file_put_contents($this->vendorDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
  130. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_2');
  131. $this->assertAutoloadFiles('main3', $this->vendorDir.'/composer');
  132. $this->assertAutoloadFiles('psr4_3', $this->vendorDir.'/composer', 'psr4');
  133. $this->assertAutoloadFiles('classmap3', $this->vendorDir.'/composer', 'classmap');
  134. }
  135. public function testMainPackageAutoloadingAlternativeVendorDir()
  136. {
  137. $package = new Package('a', '1.0', '1.0');
  138. $package->setAutoload(array(
  139. 'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
  140. 'psr-4' => array(
  141. 'Acme\Fruit\\' => 'src-fruit/',
  142. 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
  143. ),
  144. 'classmap' => array('composersrc/'),
  145. ));
  146. $this->repository->expects($this->once())
  147. ->method('getCanonicalPackages')
  148. ->will($this->returnValue(array()));
  149. $this->vendorDir .= '/subdir';
  150. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  151. $this->fs->ensureDirectoryExists($this->workingDir.'/src');
  152. $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc');
  153. file_put_contents($this->workingDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
  154. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_3');
  155. $this->assertAutoloadFiles('main2', $this->vendorDir.'/composer');
  156. $this->assertAutoloadFiles('psr4_2', $this->vendorDir.'/composer', 'psr4');
  157. $this->assertAutoloadFiles('classmap2', $this->vendorDir.'/composer', 'classmap');
  158. }
  159. public function testMainPackageAutoloadingWithTargetDir()
  160. {
  161. $package = new Package('a', '1.0', '1.0');
  162. $package->setAutoload(array(
  163. 'psr-0' => array('Main\\Foo' => '', 'Main\\Bar' => ''),
  164. 'psr-4' => array(
  165. 'Acme\Fruit\\' => 'src-fruit/',
  166. 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
  167. ),
  168. 'classmap' => array('Main/Foo/src', 'lib'),
  169. 'files' => array('foo.php', 'Main/Foo/bar.php'),
  170. ));
  171. $package->setTargetDir('Main/Foo/');
  172. $this->repository->expects($this->once())
  173. ->method('getCanonicalPackages')
  174. ->will($this->returnValue(array()));
  175. $this->fs->ensureDirectoryExists($this->vendorDir.'/a');
  176. $this->fs->ensureDirectoryExists($this->workingDir.'/src');
  177. $this->fs->ensureDirectoryExists($this->workingDir.'/lib');
  178. file_put_contents($this->workingDir.'/src/rootfoo.php', '<?php class ClassMapFoo {}');
  179. file_put_contents($this->workingDir.'/lib/rootbar.php', '<?php class ClassMapBar {}');
  180. file_put_contents($this->workingDir.'/foo.php', '<?php class FilesFoo {}');
  181. file_put_contents($this->workingDir.'/bar.php', '<?php class FilesBar {}');
  182. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'TargetDir');
  183. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_target_dir.php', $this->vendorDir.'/autoload.php');
  184. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_target_dir.php', $this->vendorDir.'/composer/autoload_real.php');
  185. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_target_dir.php', $this->vendorDir.'/composer/autoload_files.php');
  186. $this->assertAutoloadFiles('classmap6', $this->vendorDir.'/composer', 'classmap');
  187. }
  188. public function testVendorsAutoloading()
  189. {
  190. $package = new Package('a', '1.0', '1.0');
  191. $packages = array();
  192. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  193. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  194. $packages[] = $c = new AliasPackage($b, '1.2', '1.2');
  195. $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
  196. $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
  197. $this->repository->expects($this->once())
  198. ->method('getCanonicalPackages')
  199. ->will($this->returnValue($packages));
  200. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  201. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  202. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib');
  203. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  204. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_5');
  205. $this->assertAutoloadFiles('vendors', $this->vendorDir.'/composer');
  206. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated, even if empty.");
  207. }
  208. public function testPSR0ToClassMapIgnoresNonExistingDir()
  209. {
  210. $package = new Package('a', '1.0', '1.0');
  211. $package->setAutoload(array('psr-0' => array('foo/bar/non/existing/')));
  212. $this->repository->expects($this->once())
  213. ->method('getCanonicalPackages')
  214. ->will($this->returnValue(array()));
  215. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
  216. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
  217. $this->assertEquals(
  218. array(),
  219. include $this->vendorDir.'/composer/autoload_classmap.php'
  220. );
  221. }
  222. public function testVendorsClassMapAutoloading()
  223. {
  224. $package = new Package('a', '1.0', '1.0');
  225. $packages = array();
  226. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  227. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  228. $a->setAutoload(array('classmap' => array('src/')));
  229. $b->setAutoload(array('classmap' => array('src/', 'lib/')));
  230. $this->repository->expects($this->once())
  231. ->method('getCanonicalPackages')
  232. ->will($this->returnValue($packages));
  233. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  234. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  235. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  236. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/lib');
  237. file_put_contents($this->vendorDir.'/a/a/src/a.php', '<?php class ClassMapFoo {}');
  238. file_put_contents($this->vendorDir.'/b/b/src/b.php', '<?php class ClassMapBar {}');
  239. file_put_contents($this->vendorDir.'/b/b/lib/c.php', '<?php class ClassMapBaz {}');
  240. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
  241. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
  242. $this->assertEquals(
  243. array(
  244. 'ClassMapBar' => $this->vendorDir.'/b/b/src/b.php',
  245. 'ClassMapBaz' => $this->vendorDir.'/b/b/lib/c.php',
  246. 'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
  247. ),
  248. include $this->vendorDir.'/composer/autoload_classmap.php'
  249. );
  250. $this->assertAutoloadFiles('classmap4', $this->vendorDir.'/composer', 'classmap');
  251. }
  252. public function testVendorsClassMapAutoloadingWithTargetDir()
  253. {
  254. $package = new Package('a', '1.0', '1.0');
  255. $packages = array();
  256. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  257. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  258. $a->setAutoload(array('classmap' => array('target/src/', 'lib/')));
  259. $a->setTargetDir('target');
  260. $b->setAutoload(array('classmap' => array('src/')));
  261. $this->repository->expects($this->once())
  262. ->method('getCanonicalPackages')
  263. ->will($this->returnValue($packages));
  264. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  265. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/target/src');
  266. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/target/lib');
  267. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  268. file_put_contents($this->vendorDir.'/a/a/target/src/a.php', '<?php class ClassMapFoo {}');
  269. file_put_contents($this->vendorDir.'/a/a/target/lib/b.php', '<?php class ClassMapBar {}');
  270. file_put_contents($this->vendorDir.'/b/b/src/c.php', '<?php class ClassMapBaz {}');
  271. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
  272. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
  273. $this->assertEquals(
  274. array(
  275. 'ClassMapBar' => $this->vendorDir.'/a/a/target/lib/b.php',
  276. 'ClassMapBaz' => $this->vendorDir.'/b/b/src/c.php',
  277. 'ClassMapFoo' => $this->vendorDir.'/a/a/target/src/a.php',
  278. ),
  279. include $this->vendorDir.'/composer/autoload_classmap.php'
  280. );
  281. }
  282. public function testClassMapAutoloadingEmptyDirAndExactFile()
  283. {
  284. $package = new Package('a', '1.0', '1.0');
  285. $packages = array();
  286. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  287. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  288. $packages[] = $c = new Package('c/c', '1.0', '1.0');
  289. $a->setAutoload(array('classmap' => array('')));
  290. $b->setAutoload(array('classmap' => array('test.php')));
  291. $c->setAutoload(array('classmap' => array('./')));
  292. $this->repository->expects($this->once())
  293. ->method('getCanonicalPackages')
  294. ->will($this->returnValue($packages));
  295. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  296. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  297. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
  298. $this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo');
  299. file_put_contents($this->vendorDir.'/a/a/src/a.php', '<?php class ClassMapFoo {}');
  300. file_put_contents($this->vendorDir.'/b/b/test.php', '<?php class ClassMapBar {}');
  301. file_put_contents($this->vendorDir.'/c/c/foo/test.php', '<?php class ClassMapBaz {}');
  302. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
  303. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
  304. $this->assertEquals(
  305. array(
  306. 'ClassMapBar' => $this->vendorDir.'/b/b/test.php',
  307. 'ClassMapBaz' => $this->vendorDir.'/c/c/foo/test.php',
  308. 'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
  309. ),
  310. include $this->vendorDir.'/composer/autoload_classmap.php'
  311. );
  312. $this->assertAutoloadFiles('classmap5', $this->vendorDir.'/composer', 'classmap');
  313. }
  314. public function testFilesAutoloadGeneration()
  315. {
  316. $package = new Package('a', '1.0', '1.0');
  317. $package->setAutoload(array('files' => array('root.php')));
  318. $packages = array();
  319. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  320. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  321. $packages[] = $c = new Package('c/c', '1.0', '1.0');
  322. $a->setAutoload(array('files' => array('test.php')));
  323. $b->setAutoload(array('files' => array('test2.php')));
  324. $c->setAutoload(array('files' => array('test3.php', 'foo/bar/test4.php')));
  325. $c->setTargetDir('foo/bar');
  326. $this->repository->expects($this->once())
  327. ->method('getCanonicalPackages')
  328. ->will($this->returnValue($packages));
  329. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a');
  330. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
  331. $this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo/bar');
  332. file_put_contents($this->vendorDir.'/a/a/test.php', '<?php function testFilesAutoloadGeneration1() {}');
  333. file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
  334. file_put_contents($this->vendorDir.'/c/c/foo/bar/test3.php', '<?php function testFilesAutoloadGeneration3() {}');
  335. file_put_contents($this->vendorDir.'/c/c/foo/bar/test4.php', '<?php function testFilesAutoloadGeneration4() {}');
  336. file_put_contents($this->workingDir.'/root.php', '<?php function testFilesAutoloadGenerationRoot() {}');
  337. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoload');
  338. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
  339. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php');
  340. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php');
  341. include $this->vendorDir . '/autoload.php';
  342. $this->assertTrue(function_exists('testFilesAutoloadGeneration1'));
  343. $this->assertTrue(function_exists('testFilesAutoloadGeneration2'));
  344. $this->assertTrue(function_exists('testFilesAutoloadGeneration3'));
  345. $this->assertTrue(function_exists('testFilesAutoloadGeneration4'));
  346. $this->assertTrue(function_exists('testFilesAutoloadGenerationRoot'));
  347. }
  348. public function testFilesAutoloadOrderByDependencies()
  349. {
  350. $package = new Package('a', '1.0', '1.0');
  351. $package->setAutoload(array('files' => array('root.php')));
  352. $package->setRequires(array(new Link('a', 'z/foo')));
  353. $package->setRequires(array(new Link('a', 'd/d')));
  354. $package->setRequires(array(new Link('a', 'e/e')));
  355. $packages = array();
  356. $packages[] = $z = new Package('z/foo', '1.0', '1.0');
  357. $packages[] = $b = new Package('b/bar', '1.0', '1.0');
  358. $packages[] = $d = new Package('d/d', '1.0', '1.0');
  359. $packages[] = $c = new Package('c/lorem', '1.0', '1.0');
  360. $packages[] = $e = new Package('e/e', '1.0', '1.0');
  361. $z->setAutoload(array('files' => array('testA.php')));
  362. $z->setRequires(array(new Link('z/foo', 'c/lorem')));
  363. $b->setAutoload(array('files' => array('testB.php')));
  364. $b->setRequires(array(new Link('b/bar', 'c/lorem'), new Link('b/bar', 'd/d')));
  365. $c->setAutoload(array('files' => array('testC.php')));
  366. $d->setAutoload(array('files' => array('testD.php')));
  367. $d->setRequires(array(new Link('d/d', 'c/lorem')));
  368. $e->setAutoload(array('files' => array('testE.php')));
  369. $e->setRequires(array(new Link('e/e', 'c/lorem')));
  370. $this->repository->expects($this->once())
  371. ->method('getCanonicalPackages')
  372. ->will($this->returnValue($packages));
  373. $this->fs->ensureDirectoryExists($this->vendorDir . '/z/foo');
  374. $this->fs->ensureDirectoryExists($this->vendorDir . '/b/bar');
  375. $this->fs->ensureDirectoryExists($this->vendorDir . '/c/lorem');
  376. $this->fs->ensureDirectoryExists($this->vendorDir . '/d/d');
  377. $this->fs->ensureDirectoryExists($this->vendorDir . '/e/e');
  378. file_put_contents($this->vendorDir . '/z/foo/testA.php', '<?php function testFilesAutoloadOrderByDependency1() {}');
  379. file_put_contents($this->vendorDir . '/b/bar/testB.php', '<?php function testFilesAutoloadOrderByDependency2() {}');
  380. file_put_contents($this->vendorDir . '/c/lorem/testC.php', '<?php function testFilesAutoloadOrderByDependency3() {}');
  381. file_put_contents($this->vendorDir . '/d/d/testD.php', '<?php function testFilesAutoloadOrderByDependency4() {}');
  382. file_put_contents($this->vendorDir . '/e/e/testE.php', '<?php function testFilesAutoloadOrderByDependency5() {}');
  383. file_put_contents($this->workingDir . '/root.php', '<?php function testFilesAutoloadOrderByDependencyRoot() {}');
  384. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoloadOrder');
  385. $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_functions_by_dependency.php', $this->vendorDir . '/autoload.php');
  386. $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_real_files_by_dependency.php', $this->vendorDir . '/composer/autoload_real.php');
  387. require $this->vendorDir . '/autoload.php';
  388. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency1'));
  389. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency2'));
  390. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency3'));
  391. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency4'));
  392. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency5'));
  393. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependencyRoot'));
  394. }
  395. public function testOverrideVendorsAutoloading()
  396. {
  397. $package = new Package('z', '1.0', '1.0');
  398. $package->setAutoload(array('psr-0' => array('A\\B' => $this->workingDir.'/lib'), 'classmap' => array($this->workingDir.'/src')));
  399. $package->setRequires(array(new Link('z', 'a/a')));
  400. $packages = array();
  401. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  402. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  403. $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'), 'classmap' => array('classmap')));
  404. $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
  405. $this->repository->expects($this->once())
  406. ->method('getCanonicalPackages')
  407. ->will($this->returnValue($packages));
  408. $this->fs->ensureDirectoryExists($this->workingDir.'/lib/A/B');
  409. $this->fs->ensureDirectoryExists($this->workingDir.'/src/');
  410. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  411. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/classmap');
  412. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  413. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib/A/B');
  414. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  415. file_put_contents($this->workingDir.'/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
  416. file_put_contents($this->workingDir.'/src/classes.php', '<?php namespace Foo; class Bar {}');
  417. file_put_contents($this->vendorDir.'/a/a/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
  418. file_put_contents($this->vendorDir.'/a/a/classmap/classes.php', '<?php namespace Foo; class Bar {}');
  419. $expectedNamespace = <<<EOF
  420. <?php
  421. // autoload_namespaces.php @generated by Composer
  422. \$vendorDir = dirname(dirname(__FILE__));
  423. \$baseDir = dirname(\$vendorDir);
  424. return array(
  425. 'B\\\\Sub\\\\Name' => array(\$vendorDir . '/b/b/src'),
  426. 'A\\\\B' => array(\$baseDir . '/lib', \$vendorDir . '/a/a/lib'),
  427. 'A' => array(\$vendorDir . '/a/a/src'),
  428. );
  429. EOF;
  430. // autoload_psr4.php is expected to be empty in this example.
  431. $expectedPsr4 = <<<EOF
  432. <?php
  433. // autoload_psr4.php @generated by Composer
  434. \$vendorDir = dirname(dirname(__FILE__));
  435. \$baseDir = dirname(\$vendorDir);
  436. return array(
  437. );
  438. EOF;
  439. $expectedClassmap = <<<EOF
  440. <?php
  441. // autoload_classmap.php @generated by Composer
  442. \$vendorDir = dirname(dirname(__FILE__));
  443. \$baseDir = dirname(\$vendorDir);
  444. return array(
  445. 'A\\\\B\\\\C' => \$baseDir . '/lib/A/B/C.php',
  446. 'Foo\\\\Bar' => \$baseDir . '/src/classes.php',
  447. );
  448. EOF;
  449. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_9');
  450. $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
  451. $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
  452. $this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
  453. }
  454. public function testIncludePathFileGeneration()
  455. {
  456. $package = new Package('a', '1.0', '1.0');
  457. $packages = array();
  458. $a = new Package("a/a", "1.0", "1.0");
  459. $a->setIncludePaths(array("lib/"));
  460. $b = new Package("b/b", "1.0", "1.0");
  461. $b->setIncludePaths(array("library"));
  462. $c = new Package("c", "1.0", "1.0");
  463. $c->setIncludePaths(array("library"));
  464. $packages[] = $a;
  465. $packages[] = $b;
  466. $packages[] = $c;
  467. $this->repository->expects($this->once())
  468. ->method("getCanonicalPackages")
  469. ->will($this->returnValue($packages));
  470. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  471. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_10');
  472. $this->assertFileEquals(__DIR__.'/Fixtures/include_paths.php', $this->vendorDir.'/composer/include_paths.php');
  473. $this->assertEquals(
  474. array(
  475. $this->vendorDir."/a/a/lib",
  476. $this->vendorDir."/b/b/library",
  477. $this->vendorDir."/c/library",
  478. ),
  479. require $this->vendorDir."/composer/include_paths.php"
  480. );
  481. }
  482. public function testIncludePathsArePrependedInAutoloadFile()
  483. {
  484. $package = new Package('a', '1.0', '1.0');
  485. $packages = array();
  486. $a = new Package("a/a", "1.0", "1.0");
  487. $a->setIncludePaths(array("lib/"));
  488. $packages[] = $a;
  489. $this->repository->expects($this->once())
  490. ->method("getCanonicalPackages")
  491. ->will($this->returnValue($packages));
  492. mkdir($this->vendorDir."/composer", 0777, true);
  493. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_11');
  494. $oldIncludePath = get_include_path();
  495. require $this->vendorDir."/autoload.php";
  496. $this->assertEquals(
  497. $this->vendorDir."/a/a/lib".PATH_SEPARATOR.$oldIncludePath,
  498. get_include_path()
  499. );
  500. set_include_path($oldIncludePath);
  501. }
  502. public function testIncludePathsInMainPackage()
  503. {
  504. $package = new Package('a', '1.0', '1.0');
  505. $package->setIncludePaths(array('/lib', '/src'));
  506. $packages = array($a = new Package("a/a", "1.0", "1.0"));
  507. $a->setIncludePaths(array("lib/"));
  508. $this->repository->expects($this->once())
  509. ->method("getCanonicalPackages")
  510. ->will($this->returnValue($packages));
  511. mkdir($this->vendorDir."/composer", 0777, true);
  512. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
  513. $oldIncludePath = get_include_path();
  514. require $this->vendorDir."/autoload.php";
  515. $this->assertEquals(
  516. $this->workingDir."/lib".PATH_SEPARATOR.$this->workingDir."/src".PATH_SEPARATOR.$this->vendorDir."/a/a/lib".PATH_SEPARATOR.$oldIncludePath,
  517. get_include_path()
  518. );
  519. set_include_path($oldIncludePath);
  520. }
  521. public function testIncludePathFileWithoutPathsIsSkipped()
  522. {
  523. $package = new Package('a', '1.0', '1.0');
  524. $packages = array();
  525. $a = new Package("a/a", "1.0", "1.0");
  526. $packages[] = $a;
  527. $this->repository->expects($this->once())
  528. ->method("getCanonicalPackages")
  529. ->will($this->returnValue($packages));
  530. mkdir($this->vendorDir."/composer", 0777, true);
  531. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
  532. $this->assertFalse(file_exists($this->vendorDir."/composer/include_paths.php"));
  533. }
  534. public function testPreAndPostEventsAreDispatchedDuringAutoloadDump()
  535. {
  536. $this->eventDispatcher
  537. ->expects($this->at(0))
  538. ->method('dispatchScript')
  539. ->with(ScriptEvents::PRE_AUTOLOAD_DUMP, false);
  540. $this->eventDispatcher
  541. ->expects($this->at(1))
  542. ->method('dispatchScript')
  543. ->with(ScriptEvents::POST_AUTOLOAD_DUMP, false);
  544. $package = new Package('a', '1.0', '1.0');
  545. $package->setAutoload(array('psr-0' => array('foo/bar/non/existing/')));
  546. $this->repository->expects($this->once())
  547. ->method('getCanonicalPackages')
  548. ->will($this->returnValue(array()));
  549. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
  550. }
  551. public function testUseGlobalIncludePath()
  552. {
  553. $package = new Package('a', '1.0', '1.0');
  554. $package->setAutoload(array(
  555. 'psr-0' => array('Main\\Foo' => '', 'Main\\Bar' => ''),
  556. ));
  557. $package->setTargetDir('Main/Foo/');
  558. $this->repository->expects($this->once())
  559. ->method('getCanonicalPackages')
  560. ->will($this->returnValue(array()));
  561. $this->config->expects($this->at(2))
  562. ->method('get')
  563. ->with($this->equalTo('use-include-path'))
  564. ->will($this->returnValue(true));
  565. $this->fs->ensureDirectoryExists($this->vendorDir.'/a');
  566. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'IncludePath');
  567. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_include_path.php', $this->vendorDir.'/composer/autoload_real.php');
  568. }
  569. public function testVendorDirExcludedFromWorkingDir()
  570. {
  571. $workingDir = $this->vendorDir.'/working-dir';
  572. $vendorDir = $workingDir.'/../vendor';
  573. $this->fs->ensureDirectoryExists($workingDir);
  574. chdir($workingDir);
  575. $package = new Package('a', '1.0', '1.0');
  576. $package->setAutoload(array(
  577. 'psr-0' => array('Foo' => 'src'),
  578. 'psr-4' => array('Acme\Foo\\' => 'src-psr4'),
  579. 'classmap' => array('classmap'),
  580. 'files' => array('test.php'),
  581. ));
  582. $vendorPackage = new Package('b/b', '1.0', '1.0');
  583. $vendorPackage->setAutoload(array(
  584. 'psr-0' => array('Bar' => 'lib'),
  585. 'psr-4' => array('Acme\Bar\\' => 'lib-psr4'),
  586. 'classmap' => array('classmaps'),
  587. 'files' => array('bootstrap.php'),
  588. ));
  589. $this->repository->expects($this->once())
  590. ->method('getCanonicalPackages')
  591. ->will($this->returnValue(array($vendorPackage)));
  592. $im = $this->getMockBuilder('Composer\Installer\InstallationManager')
  593. ->disableOriginalConstructor()
  594. ->getMock();
  595. $im->expects($this->any())
  596. ->method('getInstallPath')
  597. ->will($this->returnCallback(function ($package) use ($vendorDir) {
  598. $targetDir = $package->getTargetDir();
  599. return $vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : '');
  600. }));
  601. $this->fs->ensureDirectoryExists($workingDir.'/src/Foo');
  602. $this->fs->ensureDirectoryExists($workingDir.'/classmap');
  603. $this->fs->ensureDirectoryExists($vendorDir.'/composer');
  604. $this->fs->ensureDirectoryExists($vendorDir.'/b/b/lib/Bar');
  605. $this->fs->ensureDirectoryExists($vendorDir.'/b/b/classmaps');
  606. file_put_contents($workingDir.'/src/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
  607. file_put_contents($workingDir.'/classmap/classes.php', '<?php namespace Foo; class Foo {}');
  608. file_put_contents($workingDir.'/test.php', '<?php class Foo {}');
  609. file_put_contents($vendorDir.'/b/b/lib/Bar/Foo.php', '<?php namespace Bar; class Foo {}');
  610. file_put_contents($vendorDir.'/b/b/classmaps/classes.php', '<?php namespace Bar; class Bar {}');
  611. file_put_contents($vendorDir.'/b/b/bootstrap.php', '<?php class Bar {}');
  612. $oldVendorDir = $this->vendorDir;
  613. $this->vendorDir = $vendorDir;
  614. $this->generator->dump($this->config, $this->repository, $package, $im, 'composer', true, '_13');
  615. $this->vendorDir = $oldVendorDir;
  616. $expectedNamespace = <<<'EOF'
  617. <?php
  618. // autoload_namespaces.php @generated by Composer
  619. $vendorDir = dirname(dirname(__FILE__));
  620. $baseDir = dirname($vendorDir).'/working-dir';
  621. return array(
  622. 'Foo' => array($baseDir . '/src'),
  623. 'Bar' => array($vendorDir . '/b/b/lib'),
  624. );
  625. EOF;
  626. $expectedPsr4 = <<<'EOF'
  627. <?php
  628. // autoload_psr4.php @generated by Composer
  629. $vendorDir = dirname(dirname(__FILE__));
  630. $baseDir = dirname($vendorDir).'/working-dir';
  631. return array(
  632. 'Acme\\Foo\\' => array($baseDir . '/src-psr4'),
  633. 'Acme\\Bar\\' => array($vendorDir . '/b/b/lib-psr4'),
  634. );
  635. EOF;
  636. $expectedClassmap = <<<'EOF'
  637. <?php
  638. // autoload_classmap.php @generated by Composer
  639. $vendorDir = dirname(dirname(__FILE__));
  640. $baseDir = dirname($vendorDir).'/working-dir';
  641. return array(
  642. 'Bar\\Bar' => $vendorDir . '/b/b/classmaps/classes.php',
  643. 'Bar\\Foo' => $vendorDir . '/b/b/lib/Bar/Foo.php',
  644. 'Foo\\Bar' => $baseDir . '/src/Foo/Bar.php',
  645. 'Foo\\Foo' => $baseDir . '/classmap/classes.php',
  646. );
  647. EOF;
  648. $this->assertEquals($expectedNamespace, file_get_contents($vendorDir.'/composer/autoload_namespaces.php'));
  649. $this->assertEquals($expectedPsr4, file_get_contents($vendorDir.'/composer/autoload_psr4.php'));
  650. $this->assertEquals($expectedClassmap, file_get_contents($vendorDir.'/composer/autoload_classmap.php'));
  651. $this->assertContains("\n \$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
  652. $this->assertContains("\n \$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
  653. }
  654. public function testUpLevelRelativePaths()
  655. {
  656. $workingDir = $this->workingDir.'/working-dir';
  657. mkdir($workingDir, 0777, true);
  658. chdir($workingDir);
  659. $package = new Package('a', '1.0', '1.0');
  660. $package->setAutoload(array(
  661. 'psr-0' => array('Foo' => '../path/../src'),
  662. 'psr-4' => array('Acme\Foo\\' => '../path/../src-psr4'),
  663. 'classmap' => array('../classmap'),
  664. 'files' => array('../test.php'),
  665. ));
  666. $this->repository->expects($this->once())
  667. ->method('getCanonicalPackages')
  668. ->will($this->returnValue(array()));
  669. $this->fs->ensureDirectoryExists($this->workingDir.'/src/Foo');
  670. $this->fs->ensureDirectoryExists($this->workingDir.'/classmap');
  671. file_put_contents($this->workingDir.'/src/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
  672. file_put_contents($this->workingDir.'/classmap/classes.php', '<?php namespace Foo; class Foo {}');
  673. file_put_contents($this->workingDir.'/test.php', '<?php class Foo {}');
  674. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_14');
  675. $expectedNamespace = <<<'EOF'
  676. <?php
  677. // autoload_namespaces.php @generated by Composer
  678. $vendorDir = dirname(dirname(__FILE__));
  679. $baseDir = dirname($vendorDir).'/working-dir';
  680. return array(
  681. 'Foo' => array($baseDir . '/../src'),
  682. );
  683. EOF;
  684. $expectedPsr4 = <<<'EOF'
  685. <?php
  686. // autoload_psr4.php @generated by Composer
  687. $vendorDir = dirname(dirname(__FILE__));
  688. $baseDir = dirname($vendorDir).'/working-dir';
  689. return array(
  690. 'Acme\\Foo\\' => array($baseDir . '/../src-psr4'),
  691. );
  692. EOF;
  693. $expectedClassmap = <<<'EOF'
  694. <?php
  695. // autoload_classmap.php @generated by Composer
  696. $vendorDir = dirname(dirname(__FILE__));
  697. $baseDir = dirname($vendorDir).'/working-dir';
  698. return array(
  699. 'Foo\\Bar' => $baseDir . '/../src/Foo/Bar.php',
  700. 'Foo\\Foo' => $baseDir . '/../classmap/classes.php',
  701. );
  702. EOF;
  703. $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
  704. $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
  705. $this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
  706. $this->assertContains("\n \$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php'));
  707. }
  708. public function testEmptyPaths()
  709. {
  710. $package = new Package('a', '1.0', '1.0');
  711. $package->setAutoload(array(
  712. 'psr-0' => array('Foo' => ''),
  713. 'psr-4' => array('Acme\Foo\\' => ''),
  714. 'classmap' => array(''),
  715. ));
  716. $this->repository->expects($this->once())
  717. ->method('getCanonicalPackages')
  718. ->will($this->returnValue(array()));
  719. $this->fs->ensureDirectoryExists($this->workingDir.'/Foo');
  720. file_put_contents($this->workingDir.'/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
  721. file_put_contents($this->workingDir.'/class.php', '<?php namespace Classmap; class Foo {}');
  722. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_15');
  723. $expectedNamespace = <<<'EOF'
  724. <?php
  725. // autoload_namespaces.php @generated by Composer
  726. $vendorDir = dirname(dirname(__FILE__));
  727. $baseDir = dirname($vendorDir);
  728. return array(
  729. 'Foo' => array($baseDir . '/'),
  730. );
  731. EOF;
  732. $expectedPsr4 = <<<'EOF'
  733. <?php
  734. // autoload_psr4.php @generated by Composer
  735. $vendorDir = dirname(dirname(__FILE__));
  736. $baseDir = dirname($vendorDir);
  737. return array(
  738. 'Acme\\Foo\\' => array($baseDir . '/'),
  739. );
  740. EOF;
  741. $expectedClassmap = <<<'EOF'
  742. <?php
  743. // autoload_classmap.php @generated by Composer
  744. $vendorDir = dirname(dirname(__FILE__));
  745. $baseDir = dirname($vendorDir);
  746. return array(
  747. 'Classmap\\Foo' => $baseDir . '/class.php',
  748. 'Foo\\Bar' => $baseDir . '/Foo/Bar.php',
  749. );
  750. EOF;
  751. $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
  752. $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
  753. $this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
  754. }
  755. public function testVendorSubstringPath()
  756. {
  757. $package = new Package('a', '1.0', '1.0');
  758. $package->setAutoload(array(
  759. 'psr-0' => array('Foo' => 'composer-test-autoload-src/src'),
  760. 'psr-4' => array('Acme\Foo\\' => 'composer-test-autoload-src/src-psr4'),
  761. ));
  762. $this->repository->expects($this->once())
  763. ->method('getCanonicalPackages')
  764. ->will($this->returnValue(array()));
  765. $this->fs->ensureDirectoryExists($this->vendorDir.'/a');
  766. $expectedNamespace = <<<'EOF'
  767. <?php
  768. // autoload_namespaces.php @generated by Composer
  769. $vendorDir = dirname(dirname(__FILE__));
  770. $baseDir = dirname($vendorDir);
  771. return array(
  772. 'Foo' => array($baseDir . '/composer-test-autoload-src/src'),
  773. );
  774. EOF;
  775. $expectedPsr4 = <<<'EOF'
  776. <?php
  777. // autoload_psr4.php @generated by Composer
  778. $vendorDir = dirname(dirname(__FILE__));
  779. $baseDir = dirname($vendorDir);
  780. return array(
  781. 'Acme\\Foo\\' => array($baseDir . '/composer-test-autoload-src/src-psr4'),
  782. );
  783. EOF;
  784. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'VendorSubstring');
  785. $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
  786. $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
  787. }
  788. private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
  789. {
  790. $a = __DIR__.'/Fixtures/autoload_'.$name.'.php';
  791. $b = $dir.'/autoload_'.$type.'.php';
  792. $this->assertFileEquals($a, $b);
  793. }
  794. }