AutoloadGeneratorTest.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  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. 'classmap' => array('Main/Foo/src', 'lib'),
  165. 'files' => array('foo.php', 'Main/Foo/bar.php'),
  166. ));
  167. $package->setTargetDir('Main/Foo/');
  168. $this->repository->expects($this->once())
  169. ->method('getCanonicalPackages')
  170. ->will($this->returnValue(array()));
  171. $this->fs->ensureDirectoryExists($this->vendorDir.'/a');
  172. $this->fs->ensureDirectoryExists($this->workingDir.'/src');
  173. $this->fs->ensureDirectoryExists($this->workingDir.'/lib');
  174. file_put_contents($this->workingDir.'/src/rootfoo.php', '<?php class ClassMapFoo {}');
  175. file_put_contents($this->workingDir.'/lib/rootbar.php', '<?php class ClassMapBar {}');
  176. file_put_contents($this->workingDir.'/foo.php', '<?php class FilesFoo {}');
  177. file_put_contents($this->workingDir.'/bar.php', '<?php class FilesBar {}');
  178. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'TargetDir');
  179. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_target_dir.php', $this->vendorDir.'/autoload.php');
  180. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_target_dir.php', $this->vendorDir.'/composer/autoload_real.php');
  181. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_target_dir.php', $this->vendorDir.'/composer/autoload_files.php');
  182. $this->assertAutoloadFiles('classmap6', $this->vendorDir.'/composer', 'classmap');
  183. }
  184. public function testVendorsAutoloading()
  185. {
  186. $package = new Package('a', '1.0', '1.0');
  187. $packages = array();
  188. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  189. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  190. $packages[] = $c = new AliasPackage($b, '1.2', '1.2');
  191. $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
  192. $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
  193. $this->repository->expects($this->once())
  194. ->method('getCanonicalPackages')
  195. ->will($this->returnValue($packages));
  196. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  197. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  198. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib');
  199. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  200. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_5');
  201. $this->assertAutoloadFiles('vendors', $this->vendorDir.'/composer');
  202. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated, even if empty.");
  203. }
  204. public function testPSRToClassMapIgnoresNonExistingDir()
  205. {
  206. $package = new Package('a', '1.0', '1.0');
  207. $package->setAutoload(array(
  208. 'psr-0' => array('Prefix' => 'foo/bar/non/existing/'),
  209. 'psr-4' => array('Prefix\\' => 'foo/bar/non/existing2/')
  210. ));
  211. $this->repository->expects($this->once())
  212. ->method('getCanonicalPackages')
  213. ->will($this->returnValue(array()));
  214. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
  215. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
  216. $this->assertEquals(
  217. array(),
  218. include $this->vendorDir.'/composer/autoload_classmap.php'
  219. );
  220. }
  221. public function testVendorsClassMapAutoloading()
  222. {
  223. $package = new Package('a', '1.0', '1.0');
  224. $packages = array();
  225. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  226. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  227. $a->setAutoload(array('classmap' => array('src/')));
  228. $b->setAutoload(array('classmap' => array('src/', 'lib/')));
  229. $this->repository->expects($this->once())
  230. ->method('getCanonicalPackages')
  231. ->will($this->returnValue($packages));
  232. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  233. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  234. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  235. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/lib');
  236. file_put_contents($this->vendorDir.'/a/a/src/a.php', '<?php class ClassMapFoo {}');
  237. file_put_contents($this->vendorDir.'/b/b/src/b.php', '<?php class ClassMapBar {}');
  238. file_put_contents($this->vendorDir.'/b/b/lib/c.php', '<?php class ClassMapBaz {}');
  239. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
  240. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
  241. $this->assertEquals(
  242. array(
  243. 'ClassMapBar' => $this->vendorDir.'/b/b/src/b.php',
  244. 'ClassMapBaz' => $this->vendorDir.'/b/b/lib/c.php',
  245. 'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
  246. ),
  247. include $this->vendorDir.'/composer/autoload_classmap.php'
  248. );
  249. $this->assertAutoloadFiles('classmap4', $this->vendorDir.'/composer', 'classmap');
  250. }
  251. public function testVendorsClassMapAutoloadingWithTargetDir()
  252. {
  253. $package = new Package('a', '1.0', '1.0');
  254. $packages = array();
  255. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  256. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  257. $a->setAutoload(array('classmap' => array('target/src/', 'lib/')));
  258. $a->setTargetDir('target');
  259. $b->setAutoload(array('classmap' => array('src/')));
  260. $this->repository->expects($this->once())
  261. ->method('getCanonicalPackages')
  262. ->will($this->returnValue($packages));
  263. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  264. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/target/src');
  265. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/target/lib');
  266. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  267. file_put_contents($this->vendorDir.'/a/a/target/src/a.php', '<?php class ClassMapFoo {}');
  268. file_put_contents($this->vendorDir.'/a/a/target/lib/b.php', '<?php class ClassMapBar {}');
  269. file_put_contents($this->vendorDir.'/b/b/src/c.php', '<?php class ClassMapBaz {}');
  270. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
  271. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
  272. $this->assertEquals(
  273. array(
  274. 'ClassMapBar' => $this->vendorDir.'/a/a/target/lib/b.php',
  275. 'ClassMapBaz' => $this->vendorDir.'/b/b/src/c.php',
  276. 'ClassMapFoo' => $this->vendorDir.'/a/a/target/src/a.php',
  277. ),
  278. include $this->vendorDir.'/composer/autoload_classmap.php'
  279. );
  280. }
  281. public function testClassMapAutoloadingEmptyDirAndExactFile()
  282. {
  283. $package = new Package('a', '1.0', '1.0');
  284. $packages = array();
  285. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  286. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  287. $packages[] = $c = new Package('c/c', '1.0', '1.0');
  288. $a->setAutoload(array('classmap' => array('')));
  289. $b->setAutoload(array('classmap' => array('test.php')));
  290. $c->setAutoload(array('classmap' => array('./')));
  291. $this->repository->expects($this->once())
  292. ->method('getCanonicalPackages')
  293. ->will($this->returnValue($packages));
  294. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  295. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  296. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
  297. $this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo');
  298. file_put_contents($this->vendorDir.'/a/a/src/a.php', '<?php class ClassMapFoo {}');
  299. file_put_contents($this->vendorDir.'/b/b/test.php', '<?php class ClassMapBar {}');
  300. file_put_contents($this->vendorDir.'/c/c/foo/test.php', '<?php class ClassMapBaz {}');
  301. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
  302. $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
  303. $this->assertEquals(
  304. array(
  305. 'ClassMapBar' => $this->vendorDir.'/b/b/test.php',
  306. 'ClassMapBaz' => $this->vendorDir.'/c/c/foo/test.php',
  307. 'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
  308. ),
  309. include $this->vendorDir.'/composer/autoload_classmap.php'
  310. );
  311. $this->assertAutoloadFiles('classmap5', $this->vendorDir.'/composer', 'classmap');
  312. }
  313. public function testFilesAutoloadGeneration()
  314. {
  315. $package = new Package('a', '1.0', '1.0');
  316. $package->setAutoload(array('files' => array('root.php')));
  317. $packages = array();
  318. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  319. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  320. $packages[] = $c = new Package('c/c', '1.0', '1.0');
  321. $a->setAutoload(array('files' => array('test.php')));
  322. $b->setAutoload(array('files' => array('test2.php')));
  323. $c->setAutoload(array('files' => array('test3.php', 'foo/bar/test4.php')));
  324. $c->setTargetDir('foo/bar');
  325. $this->repository->expects($this->once())
  326. ->method('getCanonicalPackages')
  327. ->will($this->returnValue($packages));
  328. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a');
  329. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
  330. $this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo/bar');
  331. file_put_contents($this->vendorDir.'/a/a/test.php', '<?php function testFilesAutoloadGeneration1() {}');
  332. file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
  333. file_put_contents($this->vendorDir.'/c/c/foo/bar/test3.php', '<?php function testFilesAutoloadGeneration3() {}');
  334. file_put_contents($this->vendorDir.'/c/c/foo/bar/test4.php', '<?php function testFilesAutoloadGeneration4() {}');
  335. file_put_contents($this->workingDir.'/root.php', '<?php function testFilesAutoloadGenerationRoot() {}');
  336. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoload');
  337. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
  338. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php');
  339. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php');
  340. include $this->vendorDir . '/autoload.php';
  341. $this->assertTrue(function_exists('testFilesAutoloadGeneration1'));
  342. $this->assertTrue(function_exists('testFilesAutoloadGeneration2'));
  343. $this->assertTrue(function_exists('testFilesAutoloadGeneration3'));
  344. $this->assertTrue(function_exists('testFilesAutoloadGeneration4'));
  345. $this->assertTrue(function_exists('testFilesAutoloadGenerationRoot'));
  346. }
  347. public function testFilesAutoloadOrderByDependencies()
  348. {
  349. $package = new Package('a', '1.0', '1.0');
  350. $package->setAutoload(array('files' => array('root.php')));
  351. $package->setRequires(array(new Link('a', 'z/foo')));
  352. $package->setRequires(array(new Link('a', 'd/d')));
  353. $package->setRequires(array(new Link('a', 'e/e')));
  354. $packages = array();
  355. $packages[] = $z = new Package('z/foo', '1.0', '1.0');
  356. $packages[] = $b = new Package('b/bar', '1.0', '1.0');
  357. $packages[] = $d = new Package('d/d', '1.0', '1.0');
  358. $packages[] = $c = new Package('c/lorem', '1.0', '1.0');
  359. $packages[] = $e = new Package('e/e', '1.0', '1.0');
  360. $z->setAutoload(array('files' => array('testA.php')));
  361. $z->setRequires(array(new Link('z/foo', 'c/lorem')));
  362. $b->setAutoload(array('files' => array('testB.php')));
  363. $b->setRequires(array(new Link('b/bar', 'c/lorem'), new Link('b/bar', 'd/d')));
  364. $c->setAutoload(array('files' => array('testC.php')));
  365. $d->setAutoload(array('files' => array('testD.php')));
  366. $d->setRequires(array(new Link('d/d', 'c/lorem')));
  367. $e->setAutoload(array('files' => array('testE.php')));
  368. $e->setRequires(array(new Link('e/e', 'c/lorem')));
  369. $this->repository->expects($this->once())
  370. ->method('getCanonicalPackages')
  371. ->will($this->returnValue($packages));
  372. $this->fs->ensureDirectoryExists($this->vendorDir . '/z/foo');
  373. $this->fs->ensureDirectoryExists($this->vendorDir . '/b/bar');
  374. $this->fs->ensureDirectoryExists($this->vendorDir . '/c/lorem');
  375. $this->fs->ensureDirectoryExists($this->vendorDir . '/d/d');
  376. $this->fs->ensureDirectoryExists($this->vendorDir . '/e/e');
  377. file_put_contents($this->vendorDir . '/z/foo/testA.php', '<?php function testFilesAutoloadOrderByDependency1() {}');
  378. file_put_contents($this->vendorDir . '/b/bar/testB.php', '<?php function testFilesAutoloadOrderByDependency2() {}');
  379. file_put_contents($this->vendorDir . '/c/lorem/testC.php', '<?php function testFilesAutoloadOrderByDependency3() {}');
  380. file_put_contents($this->vendorDir . '/d/d/testD.php', '<?php function testFilesAutoloadOrderByDependency4() {}');
  381. file_put_contents($this->vendorDir . '/e/e/testE.php', '<?php function testFilesAutoloadOrderByDependency5() {}');
  382. file_put_contents($this->workingDir . '/root.php', '<?php function testFilesAutoloadOrderByDependencyRoot() {}');
  383. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoloadOrder');
  384. $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_functions_by_dependency.php', $this->vendorDir . '/autoload.php');
  385. $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_real_files_by_dependency.php', $this->vendorDir . '/composer/autoload_real.php');
  386. require $this->vendorDir . '/autoload.php';
  387. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency1'));
  388. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency2'));
  389. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency3'));
  390. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency4'));
  391. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency5'));
  392. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependencyRoot'));
  393. }
  394. public function testOverrideVendorsAutoloading()
  395. {
  396. $package = new Package('z', '1.0', '1.0');
  397. $package->setAutoload(array(
  398. 'psr-0' => array('A\\B' => $this->workingDir.'/lib'),
  399. 'classmap' => array($this->workingDir.'/src')
  400. ));
  401. $package->setRequires(array(new Link('z', 'a/a')));
  402. $packages = array();
  403. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  404. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  405. $a->setAutoload(array(
  406. 'psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'),
  407. 'classmap' => array('classmap'),
  408. ));
  409. $b->setAutoload(array(
  410. 'psr-0' => array('B\\Sub\\Name' => 'src/'),
  411. ));
  412. $this->repository->expects($this->once())
  413. ->method('getCanonicalPackages')
  414. ->will($this->returnValue($packages));
  415. $this->fs->ensureDirectoryExists($this->workingDir.'/lib/A/B');
  416. $this->fs->ensureDirectoryExists($this->workingDir.'/src/');
  417. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  418. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/classmap');
  419. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  420. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib/A/B');
  421. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  422. file_put_contents($this->workingDir.'/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
  423. file_put_contents($this->workingDir.'/src/classes.php', '<?php namespace Foo; class Bar {}');
  424. file_put_contents($this->vendorDir.'/a/a/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
  425. file_put_contents($this->vendorDir.'/a/a/classmap/classes.php', '<?php namespace Foo; class Bar {}');
  426. $expectedNamespace = <<<EOF
  427. <?php
  428. // autoload_namespaces.php @generated by Composer
  429. \$vendorDir = dirname(dirname(__FILE__));
  430. \$baseDir = dirname(\$vendorDir);
  431. return array(
  432. 'B\\\\Sub\\\\Name' => array(\$vendorDir . '/b/b/src'),
  433. 'A\\\\B' => array(\$baseDir . '/lib', \$vendorDir . '/a/a/lib'),
  434. 'A' => array(\$vendorDir . '/a/a/src'),
  435. );
  436. EOF;
  437. // autoload_psr4.php is expected to be empty in this example.
  438. $expectedPsr4 = <<<EOF
  439. <?php
  440. // autoload_psr4.php @generated by Composer
  441. \$vendorDir = dirname(dirname(__FILE__));
  442. \$baseDir = dirname(\$vendorDir);
  443. return array(
  444. );
  445. EOF;
  446. $expectedClassmap = <<<EOF
  447. <?php
  448. // autoload_classmap.php @generated by Composer
  449. \$vendorDir = dirname(dirname(__FILE__));
  450. \$baseDir = dirname(\$vendorDir);
  451. return array(
  452. 'A\\\\B\\\\C' => \$baseDir . '/lib/A/B/C.php',
  453. 'Foo\\\\Bar' => \$baseDir . '/src/classes.php',
  454. );
  455. EOF;
  456. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_9');
  457. $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
  458. $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
  459. $this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
  460. }
  461. public function testIncludePathFileGeneration()
  462. {
  463. $package = new Package('a', '1.0', '1.0');
  464. $packages = array();
  465. $a = new Package("a/a", "1.0", "1.0");
  466. $a->setIncludePaths(array("lib/"));
  467. $b = new Package("b/b", "1.0", "1.0");
  468. $b->setIncludePaths(array("library"));
  469. $c = new Package("c", "1.0", "1.0");
  470. $c->setIncludePaths(array("library"));
  471. $packages[] = $a;
  472. $packages[] = $b;
  473. $packages[] = $c;
  474. $this->repository->expects($this->once())
  475. ->method("getCanonicalPackages")
  476. ->will($this->returnValue($packages));
  477. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  478. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_10');
  479. $this->assertFileEquals(__DIR__.'/Fixtures/include_paths.php', $this->vendorDir.'/composer/include_paths.php');
  480. $this->assertEquals(
  481. array(
  482. $this->vendorDir."/a/a/lib",
  483. $this->vendorDir."/b/b/library",
  484. $this->vendorDir."/c/library",
  485. ),
  486. require $this->vendorDir."/composer/include_paths.php"
  487. );
  488. }
  489. public function testIncludePathsArePrependedInAutoloadFile()
  490. {
  491. $package = new Package('a', '1.0', '1.0');
  492. $packages = array();
  493. $a = new Package("a/a", "1.0", "1.0");
  494. $a->setIncludePaths(array("lib/"));
  495. $packages[] = $a;
  496. $this->repository->expects($this->once())
  497. ->method("getCanonicalPackages")
  498. ->will($this->returnValue($packages));
  499. mkdir($this->vendorDir."/composer", 0777, true);
  500. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_11');
  501. $oldIncludePath = get_include_path();
  502. require $this->vendorDir."/autoload.php";
  503. $this->assertEquals(
  504. $this->vendorDir."/a/a/lib".PATH_SEPARATOR.$oldIncludePath,
  505. get_include_path()
  506. );
  507. set_include_path($oldIncludePath);
  508. }
  509. public function testIncludePathsInMainPackage()
  510. {
  511. $package = new Package('a', '1.0', '1.0');
  512. $package->setIncludePaths(array('/lib', '/src'));
  513. $packages = array($a = new Package("a/a", "1.0", "1.0"));
  514. $a->setIncludePaths(array("lib/"));
  515. $this->repository->expects($this->once())
  516. ->method("getCanonicalPackages")
  517. ->will($this->returnValue($packages));
  518. mkdir($this->vendorDir."/composer", 0777, true);
  519. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
  520. $oldIncludePath = get_include_path();
  521. require $this->vendorDir."/autoload.php";
  522. $this->assertEquals(
  523. $this->workingDir."/lib".PATH_SEPARATOR.$this->workingDir."/src".PATH_SEPARATOR.$this->vendorDir."/a/a/lib".PATH_SEPARATOR.$oldIncludePath,
  524. get_include_path()
  525. );
  526. set_include_path($oldIncludePath);
  527. }
  528. public function testIncludePathFileWithoutPathsIsSkipped()
  529. {
  530. $package = new Package('a', '1.0', '1.0');
  531. $packages = array();
  532. $a = new Package("a/a", "1.0", "1.0");
  533. $packages[] = $a;
  534. $this->repository->expects($this->once())
  535. ->method("getCanonicalPackages")
  536. ->will($this->returnValue($packages));
  537. mkdir($this->vendorDir."/composer", 0777, true);
  538. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
  539. $this->assertFalse(file_exists($this->vendorDir."/composer/include_paths.php"));
  540. }
  541. public function testPreAndPostEventsAreDispatchedDuringAutoloadDump()
  542. {
  543. $this->eventDispatcher
  544. ->expects($this->at(0))
  545. ->method('dispatchScript')
  546. ->with(ScriptEvents::PRE_AUTOLOAD_DUMP, false);
  547. $this->eventDispatcher
  548. ->expects($this->at(1))
  549. ->method('dispatchScript')
  550. ->with(ScriptEvents::POST_AUTOLOAD_DUMP, false);
  551. $package = new Package('a', '1.0', '1.0');
  552. $package->setAutoload(array('psr-0' => array('foo/bar/non/existing/')));
  553. $this->repository->expects($this->once())
  554. ->method('getCanonicalPackages')
  555. ->will($this->returnValue(array()));
  556. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
  557. }
  558. public function testUseGlobalIncludePath()
  559. {
  560. $package = new Package('a', '1.0', '1.0');
  561. $package->setAutoload(array(
  562. 'psr-0' => array('Main\\Foo' => '', 'Main\\Bar' => ''),
  563. ));
  564. $package->setTargetDir('Main/Foo/');
  565. $this->repository->expects($this->once())
  566. ->method('getCanonicalPackages')
  567. ->will($this->returnValue(array()));
  568. $this->config->expects($this->at(2))
  569. ->method('get')
  570. ->with($this->equalTo('use-include-path'))
  571. ->will($this->returnValue(true));
  572. $this->fs->ensureDirectoryExists($this->vendorDir.'/a');
  573. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'IncludePath');
  574. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_include_path.php', $this->vendorDir.'/composer/autoload_real.php');
  575. }
  576. public function testVendorDirExcludedFromWorkingDir()
  577. {
  578. $workingDir = $this->vendorDir.'/working-dir';
  579. $vendorDir = $workingDir.'/../vendor';
  580. $this->fs->ensureDirectoryExists($workingDir);
  581. chdir($workingDir);
  582. $package = new Package('a', '1.0', '1.0');
  583. $package->setAutoload(array(
  584. 'psr-0' => array('Foo' => 'src'),
  585. 'psr-4' => array('Acme\Foo\\' => 'src-psr4'),
  586. 'classmap' => array('classmap'),
  587. 'files' => array('test.php'),
  588. ));
  589. $vendorPackage = new Package('b/b', '1.0', '1.0');
  590. $vendorPackage->setAutoload(array(
  591. 'psr-0' => array('Bar' => 'lib'),
  592. 'psr-4' => array('Acme\Bar\\' => 'lib-psr4'),
  593. 'classmap' => array('classmaps'),
  594. 'files' => array('bootstrap.php'),
  595. ));
  596. $this->repository->expects($this->once())
  597. ->method('getCanonicalPackages')
  598. ->will($this->returnValue(array($vendorPackage)));
  599. $im = $this->getMockBuilder('Composer\Installer\InstallationManager')
  600. ->disableOriginalConstructor()
  601. ->getMock();
  602. $im->expects($this->any())
  603. ->method('getInstallPath')
  604. ->will($this->returnCallback(function ($package) use ($vendorDir) {
  605. $targetDir = $package->getTargetDir();
  606. return $vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : '');
  607. }));
  608. $this->fs->ensureDirectoryExists($workingDir.'/src/Foo');
  609. $this->fs->ensureDirectoryExists($workingDir.'/classmap');
  610. $this->fs->ensureDirectoryExists($vendorDir.'/composer');
  611. $this->fs->ensureDirectoryExists($vendorDir.'/b/b/lib/Bar');
  612. $this->fs->ensureDirectoryExists($vendorDir.'/b/b/classmaps');
  613. file_put_contents($workingDir.'/src/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
  614. file_put_contents($workingDir.'/classmap/classes.php', '<?php namespace Foo; class Foo {}');
  615. file_put_contents($workingDir.'/test.php', '<?php class Foo {}');
  616. file_put_contents($vendorDir.'/b/b/lib/Bar/Foo.php', '<?php namespace Bar; class Foo {}');
  617. file_put_contents($vendorDir.'/b/b/classmaps/classes.php', '<?php namespace Bar; class Bar {}');
  618. file_put_contents($vendorDir.'/b/b/bootstrap.php', '<?php class Bar {}');
  619. $oldVendorDir = $this->vendorDir;
  620. $this->vendorDir = $vendorDir;
  621. $this->generator->dump($this->config, $this->repository, $package, $im, 'composer', true, '_13');
  622. $this->vendorDir = $oldVendorDir;
  623. $expectedNamespace = <<<'EOF'
  624. <?php
  625. // autoload_namespaces.php @generated by Composer
  626. $vendorDir = dirname(dirname(__FILE__));
  627. $baseDir = dirname($vendorDir).'/working-dir';
  628. return array(
  629. 'Foo' => array($baseDir . '/src'),
  630. 'Bar' => array($vendorDir . '/b/b/lib'),
  631. );
  632. EOF;
  633. $expectedPsr4 = <<<'EOF'
  634. <?php
  635. // autoload_psr4.php @generated by Composer
  636. $vendorDir = dirname(dirname(__FILE__));
  637. $baseDir = dirname($vendorDir).'/working-dir';
  638. return array(
  639. 'Acme\\Foo\\' => array($baseDir . '/src-psr4'),
  640. 'Acme\\Bar\\' => array($vendorDir . '/b/b/lib-psr4'),
  641. );
  642. EOF;
  643. $expectedClassmap = <<<'EOF'
  644. <?php
  645. // autoload_classmap.php @generated by Composer
  646. $vendorDir = dirname(dirname(__FILE__));
  647. $baseDir = dirname($vendorDir).'/working-dir';
  648. return array(
  649. 'Bar\\Bar' => $vendorDir . '/b/b/classmaps/classes.php',
  650. 'Bar\\Foo' => $vendorDir . '/b/b/lib/Bar/Foo.php',
  651. 'Foo\\Bar' => $baseDir . '/src/Foo/Bar.php',
  652. 'Foo\\Foo' => $baseDir . '/classmap/classes.php',
  653. );
  654. EOF;
  655. $this->assertEquals($expectedNamespace, file_get_contents($vendorDir.'/composer/autoload_namespaces.php'));
  656. $this->assertEquals($expectedPsr4, file_get_contents($vendorDir.'/composer/autoload_psr4.php'));
  657. $this->assertEquals($expectedClassmap, file_get_contents($vendorDir.'/composer/autoload_classmap.php'));
  658. $this->assertContains("\n \$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
  659. $this->assertContains("\n \$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
  660. }
  661. public function testUpLevelRelativePaths()
  662. {
  663. $workingDir = $this->workingDir.'/working-dir';
  664. mkdir($workingDir, 0777, true);
  665. chdir($workingDir);
  666. $package = new Package('a', '1.0', '1.0');
  667. $package->setAutoload(array(
  668. 'psr-0' => array('Foo' => '../path/../src'),
  669. 'psr-4' => array('Acme\Foo\\' => '../path/../src-psr4'),
  670. 'classmap' => array('../classmap'),
  671. 'files' => array('../test.php'),
  672. ));
  673. $this->repository->expects($this->once())
  674. ->method('getCanonicalPackages')
  675. ->will($this->returnValue(array()));
  676. $this->fs->ensureDirectoryExists($this->workingDir.'/src/Foo');
  677. $this->fs->ensureDirectoryExists($this->workingDir.'/classmap');
  678. file_put_contents($this->workingDir.'/src/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
  679. file_put_contents($this->workingDir.'/classmap/classes.php', '<?php namespace Foo; class Foo {}');
  680. file_put_contents($this->workingDir.'/test.php', '<?php class Foo {}');
  681. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_14');
  682. $expectedNamespace = <<<'EOF'
  683. <?php
  684. // autoload_namespaces.php @generated by Composer
  685. $vendorDir = dirname(dirname(__FILE__));
  686. $baseDir = dirname($vendorDir).'/working-dir';
  687. return array(
  688. 'Foo' => array($baseDir . '/../src'),
  689. );
  690. EOF;
  691. $expectedPsr4 = <<<'EOF'
  692. <?php
  693. // autoload_psr4.php @generated by Composer
  694. $vendorDir = dirname(dirname(__FILE__));
  695. $baseDir = dirname($vendorDir).'/working-dir';
  696. return array(
  697. 'Acme\\Foo\\' => array($baseDir . '/../src-psr4'),
  698. );
  699. EOF;
  700. $expectedClassmap = <<<'EOF'
  701. <?php
  702. // autoload_classmap.php @generated by Composer
  703. $vendorDir = dirname(dirname(__FILE__));
  704. $baseDir = dirname($vendorDir).'/working-dir';
  705. return array(
  706. 'Foo\\Bar' => $baseDir . '/../src/Foo/Bar.php',
  707. 'Foo\\Foo' => $baseDir . '/../classmap/classes.php',
  708. );
  709. EOF;
  710. $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
  711. $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
  712. $this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
  713. $this->assertContains("\n \$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php'));
  714. }
  715. public function testEmptyPaths()
  716. {
  717. $package = new Package('a', '1.0', '1.0');
  718. $package->setAutoload(array(
  719. 'psr-0' => array('Foo' => ''),
  720. 'psr-4' => array('Acme\Foo\\' => ''),
  721. 'classmap' => array(''),
  722. ));
  723. $this->repository->expects($this->once())
  724. ->method('getCanonicalPackages')
  725. ->will($this->returnValue(array()));
  726. $this->fs->ensureDirectoryExists($this->workingDir.'/Foo');
  727. file_put_contents($this->workingDir.'/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
  728. file_put_contents($this->workingDir.'/class.php', '<?php namespace Classmap; class Foo {}');
  729. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_15');
  730. $expectedNamespace = <<<'EOF'
  731. <?php
  732. // autoload_namespaces.php @generated by Composer
  733. $vendorDir = dirname(dirname(__FILE__));
  734. $baseDir = dirname($vendorDir);
  735. return array(
  736. 'Foo' => array($baseDir . '/'),
  737. );
  738. EOF;
  739. $expectedPsr4 = <<<'EOF'
  740. <?php
  741. // autoload_psr4.php @generated by Composer
  742. $vendorDir = dirname(dirname(__FILE__));
  743. $baseDir = dirname($vendorDir);
  744. return array(
  745. 'Acme\\Foo\\' => array($baseDir . '/'),
  746. );
  747. EOF;
  748. $expectedClassmap = <<<'EOF'
  749. <?php
  750. // autoload_classmap.php @generated by Composer
  751. $vendorDir = dirname(dirname(__FILE__));
  752. $baseDir = dirname($vendorDir);
  753. return array(
  754. 'Classmap\\Foo' => $baseDir . '/class.php',
  755. 'Foo\\Bar' => $baseDir . '/Foo/Bar.php',
  756. );
  757. EOF;
  758. $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
  759. $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
  760. $this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
  761. }
  762. public function testVendorSubstringPath()
  763. {
  764. $package = new Package('a', '1.0', '1.0');
  765. $package->setAutoload(array(
  766. 'psr-0' => array('Foo' => 'composer-test-autoload-src/src'),
  767. 'psr-4' => array('Acme\Foo\\' => 'composer-test-autoload-src/src-psr4'),
  768. ));
  769. $this->repository->expects($this->once())
  770. ->method('getCanonicalPackages')
  771. ->will($this->returnValue(array()));
  772. $this->fs->ensureDirectoryExists($this->vendorDir.'/a');
  773. $expectedNamespace = <<<'EOF'
  774. <?php
  775. // autoload_namespaces.php @generated by Composer
  776. $vendorDir = dirname(dirname(__FILE__));
  777. $baseDir = dirname($vendorDir);
  778. return array(
  779. 'Foo' => array($baseDir . '/composer-test-autoload-src/src'),
  780. );
  781. EOF;
  782. $expectedPsr4 = <<<'EOF'
  783. <?php
  784. // autoload_psr4.php @generated by Composer
  785. $vendorDir = dirname(dirname(__FILE__));
  786. $baseDir = dirname($vendorDir);
  787. return array(
  788. 'Acme\\Foo\\' => array($baseDir . '/composer-test-autoload-src/src-psr4'),
  789. );
  790. EOF;
  791. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'VendorSubstring');
  792. $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
  793. $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
  794. }
  795. private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
  796. {
  797. $a = __DIR__.'/Fixtures/autoload_'.$name.'.php';
  798. $b = $dir.'/autoload_'.$type.'.php';
  799. $this->assertFileEquals($a, $b);
  800. }
  801. }