AutoloadGeneratorTest.php 41 KB

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