AutoloadGeneratorTest.php 41 KB

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