AutoloadGeneratorTest.php 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  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\Semver\Constraint\Constraint;
  15. use Composer\Util\Filesystem;
  16. use Composer\Package\AliasPackage;
  17. use Composer\Package\Package;
  18. use Composer\Test\TestCase;
  19. use Composer\Script\ScriptEvents;
  20. use Composer\Repository\InstalledRepositoryInterface;
  21. use Composer\Installer\InstallationManager;
  22. use Composer\Config;
  23. use Composer\EventDispatcher\EventDispatcher;
  24. use Composer\Util\Platform;
  25. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  26. class AutoloadGeneratorTest extends TestCase
  27. {
  28. /**
  29. * @var string
  30. */
  31. public $vendorDir;
  32. /**
  33. * @var Config|MockObject
  34. */
  35. private $config;
  36. /**
  37. * @var string
  38. */
  39. private $workingDir;
  40. /**
  41. * @var string
  42. */
  43. private $origDir;
  44. /**
  45. * @var InstallationManager|MockObject
  46. */
  47. private $im;
  48. /**
  49. * @var InstalledRepositoryInterface|MockObject
  50. */
  51. private $repository;
  52. /**
  53. * @var AutoloadGenerator
  54. */
  55. private $generator;
  56. /**
  57. * @var Filesystem
  58. */
  59. private $fs;
  60. /**
  61. * @var EventDispatcher|MockObject
  62. */
  63. private $eventDispatcher;
  64. /**
  65. * Map of setting name => return value configuration for the stub Config
  66. * object.
  67. *
  68. * Note: must be public for compatibility with PHP 5.3 runtimes where
  69. * closures cannot access private members of the classes they are created
  70. * in.
  71. * @var array
  72. */
  73. public $configValueMap;
  74. protected function setUp()
  75. {
  76. $this->fs = new Filesystem;
  77. $that = $this;
  78. $this->workingDir = $this->getUniqueTmpDirectory();
  79. $this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload';
  80. $this->ensureDirectoryExistsAndClear($this->vendorDir);
  81. $this->config = $this->getMockBuilder('Composer\Config')->getMock();
  82. $this->configValueMap = array(
  83. 'vendor-dir' => function () use ($that) {
  84. return $that->vendorDir;
  85. },
  86. );
  87. $this->config->expects($this->atLeastOnce())
  88. ->method('get')
  89. ->will($this->returnCallback(function ($arg) use ($that) {
  90. $ret = null;
  91. if (isset($that->configValueMap[$arg])) {
  92. $ret = $that->configValueMap[$arg];
  93. if (is_callable($ret)) {
  94. $ret = $ret();
  95. }
  96. }
  97. return $ret;
  98. }));
  99. $this->origDir = getcwd();
  100. chdir($this->workingDir);
  101. $this->im = $this->getMockBuilder('Composer\Installer\InstallationManager')
  102. ->disableOriginalConstructor()
  103. ->getMock();
  104. $this->im->expects($this->any())
  105. ->method('getInstallPath')
  106. ->will($this->returnCallback(function ($package) use ($that) {
  107. $targetDir = $package->getTargetDir();
  108. return $that->vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : '');
  109. }));
  110. $this->repository = $this->getMockBuilder('Composer\Repository\InstalledRepositoryInterface')->getMock();
  111. $this->eventDispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
  112. ->disableOriginalConstructor()
  113. ->getMock();
  114. $this->generator = new AutoloadGenerator($this->eventDispatcher);
  115. }
  116. protected function tearDown()
  117. {
  118. chdir($this->origDir);
  119. if (is_dir($this->workingDir)) {
  120. $this->fs->removeDirectory($this->workingDir);
  121. }
  122. if (is_dir($this->vendorDir)) {
  123. $this->fs->removeDirectory($this->vendorDir);
  124. }
  125. }
  126. public function testMainPackageAutoloading()
  127. {
  128. $package = new Package('a', '1.0', '1.0');
  129. $package->setAutoload(array(
  130. 'psr-0' => array(
  131. 'Main' => 'src/',
  132. 'Lala' => array('src/', 'lib/'),
  133. ),
  134. 'psr-4' => array(
  135. 'Acme\Fruit\\' => 'src-fruit/',
  136. 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
  137. ),
  138. 'classmap' => array('composersrc/'),
  139. ));
  140. $this->repository->expects($this->once())
  141. ->method('getCanonicalPackages')
  142. ->will($this->returnValue(array()));
  143. $this->fs->ensureDirectoryExists($this->workingDir.'/composer');
  144. $this->fs->ensureDirectoryExists($this->workingDir.'/src/Lala/Test');
  145. $this->fs->ensureDirectoryExists($this->workingDir.'/lib');
  146. file_put_contents($this->workingDir.'/src/Lala/ClassMapMain.php', '<?php namespace Lala; class ClassMapMain {}');
  147. file_put_contents($this->workingDir.'/src/Lala/Test/ClassMapMainTest.php', '<?php namespace Lala\Test; class ClassMapMainTest {}');
  148. $this->fs->ensureDirectoryExists($this->workingDir.'/src-fruit');
  149. $this->fs->ensureDirectoryExists($this->workingDir.'/src-cake');
  150. $this->fs->ensureDirectoryExists($this->workingDir.'/lib-cake');
  151. file_put_contents($this->workingDir.'/src-cake/ClassMapBar.php', '<?php namespace Acme\Cake; class ClassMapBar {}');
  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', true, '_1');
  155. // Assert that autoload_namespaces.php was correctly generated.
  156. $this->assertAutoloadFiles('main', $this->vendorDir.'/composer');
  157. // Assert that autoload_psr4.php was correctly generated.
  158. $this->assertAutoloadFiles('psr4', $this->vendorDir.'/composer', 'psr4');
  159. // Assert that autoload_classmap.php was correctly generated.
  160. $this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
  161. }
  162. public function testMainPackageDevAutoloading()
  163. {
  164. $package = new Package('a', '1.0', '1.0');
  165. $package->setAutoload(array(
  166. 'psr-0' => array(
  167. 'Main' => 'src/',
  168. ),
  169. ));
  170. $package->setDevAutoload(array(
  171. 'files' => array('devfiles/foo.php'),
  172. 'psr-0' => array(
  173. 'Main' => 'tests/',
  174. ),
  175. ));
  176. $this->repository->expects($this->once())
  177. ->method('getCanonicalPackages')
  178. ->will($this->returnValue(array()));
  179. $this->fs->ensureDirectoryExists($this->workingDir.'/composer');
  180. $this->fs->ensureDirectoryExists($this->workingDir.'/src/Main');
  181. file_put_contents($this->workingDir.'/src/Main/ClassMain.php', '<?php namespace Main; class ClassMain {}');
  182. $this->fs->ensureDirectoryExists($this->workingDir.'/devfiles');
  183. file_put_contents($this->workingDir.'/devfiles/foo.php', '<?php function foo() { echo "foo"; }');
  184. // generate autoload files with the dev mode set to true
  185. $this->generator->setDevMode(true);
  186. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
  187. // check standard autoload
  188. $this->assertAutoloadFiles('main5', $this->vendorDir.'/composer');
  189. $this->assertAutoloadFiles('classmap7', $this->vendorDir.'/composer', 'classmap');
  190. // make sure dev autoload is correctly dumped
  191. $this->assertAutoloadFiles('files2', $this->vendorDir.'/composer', 'files');
  192. }
  193. public function testMainPackageDevAutoloadingDisabledByDefault()
  194. {
  195. $package = new Package('a', '1.0', '1.0');
  196. $package->setAutoload(array(
  197. 'psr-0' => array(
  198. 'Main' => 'src/',
  199. ),
  200. ));
  201. $package->setDevAutoload(array(
  202. 'files' => array('devfiles/foo.php'),
  203. ));
  204. $this->repository->expects($this->once())
  205. ->method('getCanonicalPackages')
  206. ->will($this->returnValue(array()));
  207. $this->fs->ensureDirectoryExists($this->workingDir.'/composer');
  208. $this->fs->ensureDirectoryExists($this->workingDir.'/src/Main');
  209. file_put_contents($this->workingDir.'/src/Main/ClassMain.php', '<?php namespace Main; class ClassMain {}');
  210. $this->fs->ensureDirectoryExists($this->workingDir.'/devfiles');
  211. file_put_contents($this->workingDir.'/devfiles/foo.php', '<?php function foo() { echo "foo"; }');
  212. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
  213. // check standard autoload
  214. $this->assertAutoloadFiles('main4', $this->vendorDir.'/composer');
  215. $this->assertAutoloadFiles('classmap7', $this->vendorDir.'/composer', 'classmap');
  216. // make sure dev autoload is disabled when dev mode is set to false
  217. $this->assertFalse(is_file($this->vendorDir.'/composer/autoload_files.php'));
  218. }
  219. public function testVendorDirSameAsWorkingDir()
  220. {
  221. $this->vendorDir = $this->workingDir;
  222. $package = new Package('a', '1.0', '1.0');
  223. $package->setAutoload(array(
  224. 'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
  225. 'psr-4' => array(
  226. 'Acme\Fruit\\' => 'src-fruit/',
  227. 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
  228. ),
  229. 'classmap' => array('composersrc/'),
  230. ));
  231. $this->repository->expects($this->once())
  232. ->method('getCanonicalPackages')
  233. ->will($this->returnValue(array()));
  234. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  235. $this->fs->ensureDirectoryExists($this->vendorDir.'/src/Main');
  236. file_put_contents($this->vendorDir.'/src/Main/Foo.php', '<?php namespace Main; class Foo {}');
  237. $this->fs->ensureDirectoryExists($this->vendorDir.'/composersrc');
  238. file_put_contents($this->vendorDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
  239. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_2');
  240. $this->assertAutoloadFiles('main3', $this->vendorDir.'/composer');
  241. $this->assertAutoloadFiles('psr4_3', $this->vendorDir.'/composer', 'psr4');
  242. $this->assertAutoloadFiles('classmap3', $this->vendorDir.'/composer', 'classmap');
  243. }
  244. public function testMainPackageAutoloadingAlternativeVendorDir()
  245. {
  246. $package = new Package('a', '1.0', '1.0');
  247. $package->setAutoload(array(
  248. 'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
  249. 'psr-4' => array(
  250. 'Acme\Fruit\\' => 'src-fruit/',
  251. 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
  252. ),
  253. 'classmap' => array('composersrc/'),
  254. ));
  255. $this->repository->expects($this->once())
  256. ->method('getCanonicalPackages')
  257. ->will($this->returnValue(array()));
  258. $this->vendorDir .= '/subdir';
  259. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  260. $this->fs->ensureDirectoryExists($this->workingDir.'/src');
  261. $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc');
  262. file_put_contents($this->workingDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
  263. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_3');
  264. $this->assertAutoloadFiles('main2', $this->vendorDir.'/composer');
  265. $this->assertAutoloadFiles('psr4_2', $this->vendorDir.'/composer', 'psr4');
  266. $this->assertAutoloadFiles('classmap2', $this->vendorDir.'/composer', 'classmap');
  267. }
  268. public function testMainPackageAutoloadingWithTargetDir()
  269. {
  270. $package = new Package('a', '1.0', '1.0');
  271. $package->setAutoload(array(
  272. 'psr-0' => array('Main\\Foo' => '', 'Main\\Bar' => ''),
  273. 'classmap' => array('Main/Foo/src', 'lib'),
  274. 'files' => array('foo.php', 'Main/Foo/bar.php'),
  275. ));
  276. $package->setTargetDir('Main/Foo/');
  277. $this->repository->expects($this->once())
  278. ->method('getCanonicalPackages')
  279. ->will($this->returnValue(array()));
  280. $this->fs->ensureDirectoryExists($this->vendorDir.'/a');
  281. $this->fs->ensureDirectoryExists($this->workingDir.'/src');
  282. $this->fs->ensureDirectoryExists($this->workingDir.'/lib');
  283. file_put_contents($this->workingDir.'/src/rootfoo.php', '<?php class ClassMapFoo {}');
  284. file_put_contents($this->workingDir.'/lib/rootbar.php', '<?php class ClassMapBar {}');
  285. file_put_contents($this->workingDir.'/foo.php', '<?php class FilesFoo {}');
  286. file_put_contents($this->workingDir.'/bar.php', '<?php class FilesBar {}');
  287. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'TargetDir');
  288. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_target_dir.php', $this->vendorDir.'/autoload.php');
  289. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_target_dir.php', $this->vendorDir.'/composer/autoload_real.php');
  290. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_target_dir.php', $this->vendorDir.'/composer/autoload_static.php');
  291. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_target_dir.php', $this->vendorDir.'/composer/autoload_files.php');
  292. $this->assertAutoloadFiles('classmap6', $this->vendorDir.'/composer', 'classmap');
  293. }
  294. public function testVendorsAutoloading()
  295. {
  296. $package = new Package('a', '1.0', '1.0');
  297. $package->setRequires(array(
  298. new Link('a', 'a/a'),
  299. new Link('a', 'b/b'),
  300. ));
  301. $packages = array();
  302. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  303. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  304. $packages[] = $c = new AliasPackage($b, '1.2', '1.2');
  305. $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
  306. $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
  307. $this->repository->expects($this->once())
  308. ->method('getCanonicalPackages')
  309. ->will($this->returnValue($packages));
  310. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  311. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  312. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib');
  313. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  314. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_5');
  315. $this->assertAutoloadFiles('vendors', $this->vendorDir.'/composer');
  316. $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated, even if empty.");
  317. }
  318. public function testNonDevAutoloadExclusionWithRecursion()
  319. {
  320. $package = new Package('a', '1.0', '1.0');
  321. $package->setRequires(array(
  322. new Link('a', 'a/a'),
  323. ));
  324. $packages = array();
  325. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  326. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  327. $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
  328. $a->setRequires(array(
  329. new Link('a/a', 'b/b'),
  330. ));
  331. $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
  332. $b->setRequires(array(
  333. new Link('b/b', 'a/a'),
  334. ));
  335. $this->repository->expects($this->once())
  336. ->method('getCanonicalPackages')
  337. ->will($this->returnValue($packages));
  338. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  339. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  340. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib');
  341. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  342. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_5');
  343. $this->assertAutoloadFiles('vendors', $this->vendorDir.'/composer');
  344. $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated, even if empty.");
  345. }
  346. public function testNonDevAutoloadShouldIncludeReplacedPackages()
  347. {
  348. $package = new Package('a', '1.0', '1.0');
  349. $package->setRequires(array(new Link('a', 'a/a')));
  350. $packages = array();
  351. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  352. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  353. $a->setRequires(array(new Link('a/a', 'b/c')));
  354. $b->setAutoload(array('psr-4' => array('B\\' => 'src/')));
  355. $b->setReplaces(
  356. array(new Link('b/b', 'b/c', new Constraint('==', '1.0'), 'replaces'))
  357. );
  358. $this->repository->expects($this->once())
  359. ->method('getCanonicalPackages')
  360. ->will($this->returnValue($packages));
  361. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src/C');
  362. file_put_contents($this->vendorDir.'/b/b/src/C/C.php', '<?php namespace B\\C; class C {}');
  363. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_5');
  364. $this->assertEquals(
  365. array(
  366. 'B\\C\\C' => $this->vendorDir.'/b/b/src/C/C.php',
  367. ),
  368. include $this->vendorDir.'/composer/autoload_classmap.php'
  369. );
  370. }
  371. public function testPSRToClassMapIgnoresNonExistingDir()
  372. {
  373. $package = new Package('a', '1.0', '1.0');
  374. $package->setAutoload(array(
  375. 'psr-0' => array('Prefix' => 'foo/bar/non/existing/'),
  376. 'psr-4' => array('Prefix\\' => 'foo/bar/non/existing2/'),
  377. ));
  378. $this->repository->expects($this->once())
  379. ->method('getCanonicalPackages')
  380. ->will($this->returnValue(array()));
  381. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
  382. $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
  383. $this->assertEquals(
  384. array(),
  385. include $this->vendorDir.'/composer/autoload_classmap.php'
  386. );
  387. }
  388. public function testVendorsClassMapAutoloading()
  389. {
  390. $package = new Package('a', '1.0', '1.0');
  391. $package->setRequires(array(
  392. new Link('a', 'a/a'),
  393. new Link('a', 'b/b'),
  394. ));
  395. $packages = array();
  396. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  397. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  398. $a->setAutoload(array('classmap' => array('src/')));
  399. $b->setAutoload(array('classmap' => array('src/', 'lib/')));
  400. $this->repository->expects($this->once())
  401. ->method('getCanonicalPackages')
  402. ->will($this->returnValue($packages));
  403. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  404. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  405. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  406. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/lib');
  407. file_put_contents($this->vendorDir.'/a/a/src/a.php', '<?php class ClassMapFoo {}');
  408. file_put_contents($this->vendorDir.'/b/b/src/b.php', '<?php class ClassMapBar {}');
  409. file_put_contents($this->vendorDir.'/b/b/lib/c.php', '<?php class ClassMapBaz {}');
  410. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
  411. $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
  412. $this->assertEquals(
  413. array(
  414. 'ClassMapBar' => $this->vendorDir.'/b/b/src/b.php',
  415. 'ClassMapBaz' => $this->vendorDir.'/b/b/lib/c.php',
  416. 'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
  417. ),
  418. include $this->vendorDir.'/composer/autoload_classmap.php'
  419. );
  420. $this->assertAutoloadFiles('classmap4', $this->vendorDir.'/composer', 'classmap');
  421. }
  422. public function testVendorsClassMapAutoloadingWithTargetDir()
  423. {
  424. $package = new Package('a', '1.0', '1.0');
  425. $package->setRequires(array(
  426. new Link('a', 'a/a'),
  427. new Link('a', 'b/b'),
  428. ));
  429. $packages = array();
  430. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  431. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  432. $a->setAutoload(array('classmap' => array('target/src/', 'lib/')));
  433. $a->setTargetDir('target');
  434. $b->setAutoload(array('classmap' => array('src/')));
  435. $this->repository->expects($this->once())
  436. ->method('getCanonicalPackages')
  437. ->will($this->returnValue($packages));
  438. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  439. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/target/src');
  440. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/target/lib');
  441. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  442. file_put_contents($this->vendorDir.'/a/a/target/src/a.php', '<?php class ClassMapFoo {}');
  443. file_put_contents($this->vendorDir.'/a/a/target/lib/b.php', '<?php class ClassMapBar {}');
  444. file_put_contents($this->vendorDir.'/b/b/src/c.php', '<?php class ClassMapBaz {}');
  445. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
  446. $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
  447. $this->assertEquals(
  448. array(
  449. 'ClassMapBar' => $this->vendorDir.'/a/a/target/lib/b.php',
  450. 'ClassMapBaz' => $this->vendorDir.'/b/b/src/c.php',
  451. 'ClassMapFoo' => $this->vendorDir.'/a/a/target/src/a.php',
  452. ),
  453. include $this->vendorDir.'/composer/autoload_classmap.php'
  454. );
  455. }
  456. public function testClassMapAutoloadingEmptyDirAndExactFile()
  457. {
  458. $package = new Package('a', '1.0', '1.0');
  459. $package->setRequires(array(
  460. new Link('a', 'a/a'),
  461. new Link('a', 'b/b'),
  462. new Link('a', 'c/c'),
  463. ));
  464. $packages = array();
  465. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  466. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  467. $packages[] = $c = new Package('c/c', '1.0', '1.0');
  468. $a->setAutoload(array('classmap' => array('')));
  469. $b->setAutoload(array('classmap' => array('test.php')));
  470. $c->setAutoload(array('classmap' => array('./')));
  471. $this->repository->expects($this->once())
  472. ->method('getCanonicalPackages')
  473. ->will($this->returnValue($packages));
  474. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  475. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  476. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
  477. $this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo');
  478. file_put_contents($this->vendorDir.'/a/a/src/a.php', '<?php class ClassMapFoo {}');
  479. file_put_contents($this->vendorDir.'/b/b/test.php', '<?php class ClassMapBar {}');
  480. file_put_contents($this->vendorDir.'/c/c/foo/test.php', '<?php class ClassMapBaz {}');
  481. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
  482. $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
  483. $this->assertEquals(
  484. array(
  485. 'ClassMapBar' => $this->vendorDir.'/b/b/test.php',
  486. 'ClassMapBaz' => $this->vendorDir.'/c/c/foo/test.php',
  487. 'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
  488. ),
  489. include $this->vendorDir.'/composer/autoload_classmap.php'
  490. );
  491. $this->assertAutoloadFiles('classmap5', $this->vendorDir.'/composer', 'classmap');
  492. $this->assertNotContains('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
  493. $this->assertNotContains('$loader->setApcuPrefix(', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
  494. }
  495. public function testClassMapAutoloadingAuthoritativeAndApcu()
  496. {
  497. $package = new Package('a', '1.0', '1.0');
  498. $package->setRequires(array(
  499. new Link('a', 'a/a'),
  500. new Link('a', 'b/b'),
  501. new Link('a', 'c/c'),
  502. ));
  503. $packages = array();
  504. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  505. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  506. $packages[] = $c = new Package('c/c', '1.0', '1.0');
  507. $a->setAutoload(array('psr-4' => array('' => 'src/')));
  508. $b->setAutoload(array('psr-4' => array('' => './')));
  509. $c->setAutoload(array('psr-4' => array('' => 'foo/')));
  510. $this->repository->expects($this->once())
  511. ->method('getCanonicalPackages')
  512. ->will($this->returnValue($packages));
  513. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  514. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  515. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
  516. $this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo');
  517. file_put_contents($this->vendorDir.'/a/a/src/ClassMapFoo.php', '<?php class ClassMapFoo {}');
  518. file_put_contents($this->vendorDir.'/b/b/ClassMapBar.php', '<?php class ClassMapBar {}');
  519. file_put_contents($this->vendorDir.'/c/c/foo/ClassMapBaz.php', '<?php class ClassMapBaz {}');
  520. $this->generator->setClassMapAuthoritative(true);
  521. $this->generator->setApcu(true);
  522. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
  523. $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated.");
  524. $this->assertEquals(
  525. array(
  526. 'ClassMapBar' => $this->vendorDir.'/b/b/ClassMapBar.php',
  527. 'ClassMapBaz' => $this->vendorDir.'/c/c/foo/ClassMapBaz.php',
  528. 'ClassMapFoo' => $this->vendorDir.'/a/a/src/ClassMapFoo.php',
  529. ),
  530. include $this->vendorDir.'/composer/autoload_classmap.php'
  531. );
  532. $this->assertAutoloadFiles('classmap8', $this->vendorDir.'/composer', 'classmap');
  533. $this->assertContains('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
  534. $this->assertContains('$loader->setApcuPrefix(', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
  535. }
  536. public function testFilesAutoloadGeneration()
  537. {
  538. $package = new Package('a', '1.0', '1.0');
  539. $package->setAutoload(array('files' => array('root.php')));
  540. $package->setRequires(array(
  541. new Link('a', 'a/a'),
  542. new Link('a', 'b/b'),
  543. new Link('a', 'c/c'),
  544. ));
  545. $packages = array();
  546. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  547. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  548. $packages[] = $c = new Package('c/c', '1.0', '1.0');
  549. $a->setAutoload(array('files' => array('test.php')));
  550. $b->setAutoload(array('files' => array('test2.php')));
  551. $c->setAutoload(array('files' => array('test3.php', 'foo/bar/test4.php')));
  552. $c->setTargetDir('foo/bar');
  553. $this->repository->expects($this->once())
  554. ->method('getCanonicalPackages')
  555. ->will($this->returnValue($packages));
  556. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a');
  557. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
  558. $this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo/bar');
  559. file_put_contents($this->vendorDir.'/a/a/test.php', '<?php function testFilesAutoloadGeneration1() {}');
  560. file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
  561. file_put_contents($this->vendorDir.'/c/c/foo/bar/test3.php', '<?php function testFilesAutoloadGeneration3() {}');
  562. file_put_contents($this->vendorDir.'/c/c/foo/bar/test4.php', '<?php function testFilesAutoloadGeneration4() {}');
  563. file_put_contents($this->workingDir.'/root.php', '<?php function testFilesAutoloadGenerationRoot() {}');
  564. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoload');
  565. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
  566. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php');
  567. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_functions.php', $this->vendorDir.'/composer/autoload_static.php');
  568. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php');
  569. include $this->vendorDir . '/autoload.php';
  570. $this->assertTrue(function_exists('testFilesAutoloadGeneration1'));
  571. $this->assertTrue(function_exists('testFilesAutoloadGeneration2'));
  572. $this->assertTrue(function_exists('testFilesAutoloadGeneration3'));
  573. $this->assertTrue(function_exists('testFilesAutoloadGeneration4'));
  574. $this->assertTrue(function_exists('testFilesAutoloadGenerationRoot'));
  575. }
  576. public function testFilesAutoloadGenerationRemoveExtraEntitiesFromAutoloadFiles()
  577. {
  578. $autoloadPackage = new Package('a', '1.0', '1.0');
  579. $autoloadPackage->setAutoload(array('files' => array('root.php')));
  580. $autoloadPackage->setIncludePaths(array('/lib', '/src'));
  581. $notAutoloadPackage = new Package('a', '1.0', '1.0');
  582. $requires = array(
  583. new Link('a', 'a/a'),
  584. new Link('a', 'b/b'),
  585. new Link('a', 'c/c'),
  586. );
  587. $autoloadPackage->setRequires($requires);
  588. $notAutoloadPackage->setRequires($requires);
  589. $autoloadPackages = array();
  590. $autoloadPackages[] = $a = new Package('a/a', '1.0', '1.0');
  591. $autoloadPackages[] = $b = new Package('b/b', '1.0', '1.0');
  592. $autoloadPackages[] = $c = new Package('c/c', '1.0', '1.0');
  593. $a->setAutoload(array('files' => array('test.php')));
  594. $a->setIncludePaths(array('lib1', 'src1'));
  595. $b->setAutoload(array('files' => array('test2.php')));
  596. $b->setIncludePaths(array('lib2'));
  597. $c->setAutoload(array('files' => array('test3.php', 'foo/bar/test4.php')));
  598. $c->setIncludePaths(array('lib3'));
  599. $c->setTargetDir('foo/bar');
  600. $notAutoloadPackages = array();
  601. $notAutoloadPackages[] = $a = new Package('a/a', '1.0', '1.0');
  602. $notAutoloadPackages[] = $b = new Package('b/b', '1.0', '1.0');
  603. $notAutoloadPackages[] = $c = new Package('c/c', '1.0', '1.0');
  604. $this->repository->expects($this->at(0))
  605. ->method('getCanonicalPackages')
  606. ->will($this->returnValue($autoloadPackages));
  607. $this->repository->expects($this->at(1))
  608. ->method('getCanonicalPackages')
  609. ->will($this->returnValue($notAutoloadPackages));
  610. $this->repository->expects($this->at(2))
  611. ->method('getCanonicalPackages')
  612. ->will($this->returnValue($notAutoloadPackages));
  613. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a');
  614. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
  615. $this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo/bar');
  616. file_put_contents($this->vendorDir.'/a/a/test.php', '<?php function testFilesAutoloadGeneration1() {}');
  617. file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
  618. file_put_contents($this->vendorDir.'/c/c/foo/bar/test3.php', '<?php function testFilesAutoloadGeneration3() {}');
  619. file_put_contents($this->vendorDir.'/c/c/foo/bar/test4.php', '<?php function testFilesAutoloadGeneration4() {}');
  620. file_put_contents($this->workingDir.'/root.php', '<?php function testFilesAutoloadGenerationRoot() {}');
  621. $this->generator->dump($this->config, $this->repository, $autoloadPackage, $this->im, 'composer', false, 'FilesAutoload');
  622. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
  623. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_include_paths.php', $this->vendorDir.'/composer/autoload_real.php');
  624. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_functions_with_include_paths.php', $this->vendorDir.'/composer/autoload_static.php');
  625. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php');
  626. $this->assertFileEquals(__DIR__.'/Fixtures/include_paths_functions.php', $this->vendorDir.'/composer/include_paths.php');
  627. $this->generator->dump($this->config, $this->repository, $autoloadPackage, $this->im, 'composer', false, 'FilesAutoload');
  628. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
  629. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_include_paths.php', $this->vendorDir.'/composer/autoload_real.php');
  630. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions_with_removed_extra.php', $this->vendorDir.'/composer/autoload_files.php');
  631. $this->assertFileEquals(__DIR__.'/Fixtures/include_paths_functions_with_removed_extra.php', $this->vendorDir.'/composer/include_paths.php');
  632. $this->generator->dump($this->config, $this->repository, $notAutoloadPackage, $this->im, 'composer', false, 'FilesAutoload');
  633. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
  634. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php', $this->vendorDir.'/composer/autoload_real.php');
  635. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_functions_with_removed_include_paths_and_autolad_files.php', $this->vendorDir.'/composer/autoload_static.php');
  636. $this->assertFileNotExists($this->vendorDir.'/composer/autoload_files.php');
  637. $this->assertFileNotExists($this->vendorDir.'/composer/include_paths.php');
  638. }
  639. public function testFilesAutoloadOrderByDependencies()
  640. {
  641. $package = new Package('a', '1.0', '1.0');
  642. $package->setAutoload(array('files' => array('root2.php')));
  643. $package->setRequires(array(
  644. new Link('a', 'z/foo'),
  645. new Link('a', 'b/bar'),
  646. new Link('a', 'd/d'),
  647. new Link('a', 'e/e'),
  648. ));
  649. $packages = array();
  650. $packages[] = $z = new Package('z/foo', '1.0', '1.0');
  651. $packages[] = $b = new Package('b/bar', '1.0', '1.0');
  652. $packages[] = $d = new Package('d/d', '1.0', '1.0');
  653. $packages[] = $c = new Package('c/lorem', '1.0', '1.0');
  654. $packages[] = $e = new Package('e/e', '1.0', '1.0');
  655. $z->setAutoload(array('files' => array('testA.php')));
  656. $z->setRequires(array(new Link('z/foo', 'c/lorem')));
  657. $b->setAutoload(array('files' => array('testB.php')));
  658. $b->setRequires(array(new Link('b/bar', 'c/lorem'), new Link('b/bar', 'd/d')));
  659. $c->setAutoload(array('files' => array('testC.php')));
  660. $d->setAutoload(array('files' => array('testD.php')));
  661. $d->setRequires(array(new Link('d/d', 'c/lorem')));
  662. $e->setAutoload(array('files' => array('testE.php')));
  663. $e->setRequires(array(new Link('e/e', 'c/lorem')));
  664. $this->repository->expects($this->once())
  665. ->method('getCanonicalPackages')
  666. ->will($this->returnValue($packages));
  667. $this->fs->ensureDirectoryExists($this->vendorDir . '/z/foo');
  668. $this->fs->ensureDirectoryExists($this->vendorDir . '/b/bar');
  669. $this->fs->ensureDirectoryExists($this->vendorDir . '/c/lorem');
  670. $this->fs->ensureDirectoryExists($this->vendorDir . '/d/d');
  671. $this->fs->ensureDirectoryExists($this->vendorDir . '/e/e');
  672. file_put_contents($this->vendorDir . '/z/foo/testA.php', '<?php function testFilesAutoloadOrderByDependency1() {}');
  673. file_put_contents($this->vendorDir . '/b/bar/testB.php', '<?php function testFilesAutoloadOrderByDependency2() {}');
  674. file_put_contents($this->vendorDir . '/c/lorem/testC.php', '<?php function testFilesAutoloadOrderByDependency3() {}');
  675. file_put_contents($this->vendorDir . '/d/d/testD.php', '<?php function testFilesAutoloadOrderByDependency4() {}');
  676. file_put_contents($this->vendorDir . '/e/e/testE.php', '<?php function testFilesAutoloadOrderByDependency5() {}');
  677. file_put_contents($this->workingDir . '/root2.php', '<?php function testFilesAutoloadOrderByDependencyRoot() {}');
  678. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoloadOrder');
  679. $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_functions_by_dependency.php', $this->vendorDir . '/autoload.php');
  680. $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_real_files_by_dependency.php', $this->vendorDir . '/composer/autoload_real.php');
  681. $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_static_files_by_dependency.php', $this->vendorDir . '/composer/autoload_static.php');
  682. require $this->vendorDir . '/autoload.php';
  683. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency1'));
  684. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency2'));
  685. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency3'));
  686. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency4'));
  687. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency5'));
  688. $this->assertTrue(function_exists('testFilesAutoloadOrderByDependencyRoot'));
  689. }
  690. /**
  691. * Test that PSR-0 and PSR-4 mappings are processed in the correct order for
  692. * autoloading and for classmap generation:
  693. * - The main package has priority over other packages.
  694. * - Longer namespaces have priority over shorter namespaces.
  695. */
  696. public function testOverrideVendorsAutoloading()
  697. {
  698. $mainPackage = new Package('z', '1.0', '1.0');
  699. $mainPackage->setAutoload(array(
  700. 'psr-0' => array('A\\B' => $this->workingDir.'/lib'),
  701. 'classmap' => array($this->workingDir.'/src'),
  702. ));
  703. $mainPackage->setRequires(array(
  704. new Link('z', 'a/a'),
  705. new Link('z', 'b/b'),
  706. ));
  707. $packages = array();
  708. $packages[] = $a = new Package('a/a', '1.0', '1.0');
  709. $packages[] = $b = new Package('b/b', '1.0', '1.0');
  710. $a->setAutoload(array(
  711. 'psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'),
  712. 'classmap' => array('classmap'),
  713. ));
  714. $b->setAutoload(array(
  715. 'psr-0' => array('B\\Sub\\Name' => 'src/'),
  716. ));
  717. $this->repository->expects($this->once())
  718. ->method('getCanonicalPackages')
  719. ->will($this->returnValue($packages));
  720. $this->fs->ensureDirectoryExists($this->workingDir.'/lib/A/B');
  721. $this->fs->ensureDirectoryExists($this->workingDir.'/src/');
  722. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  723. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/classmap');
  724. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
  725. $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib/A/B');
  726. $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
  727. // Define the classes A\B\C and Foo\Bar in the main package.
  728. file_put_contents($this->workingDir.'/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
  729. file_put_contents($this->workingDir.'/src/classes.php', '<?php namespace Foo; class Bar {}');
  730. // Define the same two classes in the package a/a.
  731. file_put_contents($this->vendorDir.'/a/a/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
  732. file_put_contents($this->vendorDir.'/a/a/classmap/classes.php', '<?php namespace Foo; class Bar {}');
  733. $expectedNamespace = <<<EOF
  734. <?php
  735. // autoload_namespaces.php @generated by Composer
  736. \$vendorDir = dirname(dirname(__FILE__));
  737. \$baseDir = dirname(\$vendorDir);
  738. return array(
  739. 'B\\\\Sub\\\\Name' => array(\$vendorDir . '/b/b/src'),
  740. 'A\\\\B' => array(\$baseDir . '/lib', \$vendorDir . '/a/a/lib'),
  741. 'A' => array(\$vendorDir . '/a/a/src'),
  742. );
  743. EOF;
  744. // autoload_psr4.php is expected to be empty in this example.
  745. $expectedPsr4 = <<<EOF
  746. <?php
  747. // autoload_psr4.php @generated by Composer
  748. \$vendorDir = dirname(dirname(__FILE__));
  749. \$baseDir = dirname(\$vendorDir);
  750. return array(
  751. );
  752. EOF;
  753. $expectedClassmap = <<<EOF
  754. <?php
  755. // autoload_classmap.php @generated by Composer
  756. \$vendorDir = dirname(dirname(__FILE__));
  757. \$baseDir = dirname(\$vendorDir);
  758. return array(
  759. 'A\\\\B\\\\C' => \$baseDir . '/lib/A/B/C.php',
  760. 'Foo\\\\Bar' => \$baseDir . '/src/classes.php',
  761. );
  762. EOF;
  763. $this->generator->dump($this->config, $this->repository, $mainPackage, $this->im, 'composer', true, '_9');
  764. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace);
  765. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_psr4.php', $expectedPsr4);
  766. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_classmap.php', $expectedClassmap);
  767. }
  768. public function testIncludePathFileGeneration()
  769. {
  770. $package = new Package('a', '1.0', '1.0');
  771. $packages = array();
  772. $a = new Package("a/a", "1.0", "1.0");
  773. $a->setIncludePaths(array("lib/"));
  774. $b = new Package("b/b", "1.0", "1.0");
  775. $b->setIncludePaths(array("library"));
  776. $c = new Package("c", "1.0", "1.0");
  777. $c->setIncludePaths(array("library"));
  778. $packages[] = $a;
  779. $packages[] = $b;
  780. $packages[] = $c;
  781. $this->repository->expects($this->once())
  782. ->method("getCanonicalPackages")
  783. ->will($this->returnValue($packages));
  784. $this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
  785. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_10');
  786. $this->assertFileEquals(__DIR__.'/Fixtures/include_paths.php', $this->vendorDir.'/composer/include_paths.php');
  787. $this->assertEquals(
  788. array(
  789. $this->vendorDir."/a/a/lib",
  790. $this->vendorDir."/b/b/library",
  791. $this->vendorDir."/c/library",
  792. ),
  793. require $this->vendorDir."/composer/include_paths.php"
  794. );
  795. }
  796. public function testIncludePathsArePrependedInAutoloadFile()
  797. {
  798. $package = new Package('a', '1.0', '1.0');
  799. $packages = array();
  800. $a = new Package("a/a", "1.0", "1.0");
  801. $a->setIncludePaths(array("lib/"));
  802. $packages[] = $a;
  803. $this->repository->expects($this->once())
  804. ->method("getCanonicalPackages")
  805. ->will($this->returnValue($packages));
  806. mkdir($this->vendorDir."/composer", 0777, true);
  807. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_11');
  808. $oldIncludePath = get_include_path();
  809. require $this->vendorDir."/autoload.php";
  810. $this->assertEquals(
  811. $this->vendorDir."/a/a/lib".PATH_SEPARATOR.$oldIncludePath,
  812. get_include_path()
  813. );
  814. set_include_path($oldIncludePath);
  815. }
  816. public function testIncludePathsInMainPackage()
  817. {
  818. $package = new Package('a', '1.0', '1.0');
  819. $package->setIncludePaths(array('/lib', '/src'));
  820. $packages = array($a = new Package("a/a", "1.0", "1.0"));
  821. $a->setIncludePaths(array("lib/"));
  822. $this->repository->expects($this->once())
  823. ->method("getCanonicalPackages")
  824. ->will($this->returnValue($packages));
  825. mkdir($this->vendorDir."/composer", 0777, true);
  826. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
  827. $oldIncludePath = get_include_path();
  828. require $this->vendorDir."/autoload.php";
  829. $this->assertEquals(
  830. $this->workingDir."/lib".PATH_SEPARATOR.$this->workingDir."/src".PATH_SEPARATOR.$this->vendorDir."/a/a/lib".PATH_SEPARATOR.$oldIncludePath,
  831. get_include_path()
  832. );
  833. set_include_path($oldIncludePath);
  834. }
  835. public function testIncludePathFileWithoutPathsIsSkipped()
  836. {
  837. $package = new Package('a', '1.0', '1.0');
  838. $packages = array();
  839. $a = new Package("a/a", "1.0", "1.0");
  840. $packages[] = $a;
  841. $this->repository->expects($this->once())
  842. ->method("getCanonicalPackages")
  843. ->will($this->returnValue($packages));
  844. mkdir($this->vendorDir."/composer", 0777, true);
  845. $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
  846. $this->assertFileNotExists($this->vendorDir."/composer/include_paths.php");
  847. }
  848. public function testPreAndPostEventsAreDispatchedDuringAutoloadDump()
  849. {
  850. $this->eventDispatcher
  851. ->expects($this->at(0))
  852. ->method('dispatchScript')
  853. ->with(ScriptEvents::PRE_AUTOLOAD_DUMP, false);
  854. $this->eventDispatcher
  855. ->expects($this->at(1))
  856. ->method('dispatchScript')
  857. ->with(ScriptEvents::POST_AUTOLOAD_DUMP, false);
  858. $package = new Package('a', '1.0', '1.0');
  859. $package->setAutoload(array('psr-0' => array('foo/bar/non/existing/')));
  860. $this->repository->expects($this->once())
  861. ->method('getCanonicalPackages')
  862. ->will($this->returnValue(array()));
  863. $this->generator->setRunScripts(true);
  864. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
  865. }
  866. public function testUseGlobalIncludePath()
  867. {
  868. $package = new Package('a', '1.0', '1.0');
  869. $package->setAutoload(array(
  870. 'psr-0' => array('Main\\Foo' => '', 'Main\\Bar' => ''),
  871. ));
  872. $package->setTargetDir('Main/Foo/');
  873. $this->repository->expects($this->once())
  874. ->method('getCanonicalPackages')
  875. ->will($this->returnValue(array()));
  876. $this->configValueMap['use-include-path'] = true;
  877. $this->fs->ensureDirectoryExists($this->vendorDir.'/a');
  878. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'IncludePath');
  879. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_include_path.php', $this->vendorDir.'/composer/autoload_real.php');
  880. $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_include_path.php', $this->vendorDir.'/composer/autoload_static.php');
  881. }
  882. public function testVendorDirExcludedFromWorkingDir()
  883. {
  884. $workingDir = $this->vendorDir.'/working-dir';
  885. $vendorDir = $workingDir.'/../vendor';
  886. $this->fs->ensureDirectoryExists($workingDir);
  887. chdir($workingDir);
  888. $package = new Package('a', '1.0', '1.0');
  889. $package->setAutoload(array(
  890. 'psr-0' => array('Foo' => 'src'),
  891. 'psr-4' => array('Acme\Foo\\' => 'src-psr4'),
  892. 'classmap' => array('classmap'),
  893. 'files' => array('test.php'),
  894. ));
  895. $package->setRequires(array(
  896. new Link('a', 'b/b'),
  897. ));
  898. $vendorPackage = new Package('b/b', '1.0', '1.0');
  899. $vendorPackage->setAutoload(array(
  900. 'psr-0' => array('Bar' => 'lib'),
  901. 'psr-4' => array('Acme\Bar\\' => 'lib-psr4'),
  902. 'classmap' => array('classmaps'),
  903. 'files' => array('bootstrap.php'),
  904. ));
  905. $this->repository->expects($this->once())
  906. ->method('getCanonicalPackages')
  907. ->will($this->returnValue(array($vendorPackage)));
  908. $im = $this->getMockBuilder('Composer\Installer\InstallationManager')
  909. ->disableOriginalConstructor()
  910. ->getMock();
  911. $im->expects($this->any())
  912. ->method('getInstallPath')
  913. ->will($this->returnCallback(function ($package) use ($vendorDir) {
  914. $targetDir = $package->getTargetDir();
  915. return $vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : '');
  916. }));
  917. $this->fs->ensureDirectoryExists($workingDir.'/src/Foo');
  918. $this->fs->ensureDirectoryExists($workingDir.'/classmap');
  919. $this->fs->ensureDirectoryExists($vendorDir.'/composer');
  920. $this->fs->ensureDirectoryExists($vendorDir.'/b/b/lib/Bar');
  921. $this->fs->ensureDirectoryExists($vendorDir.'/b/b/classmaps');
  922. file_put_contents($workingDir.'/src/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
  923. file_put_contents($workingDir.'/classmap/classes.php', '<?php namespace Foo; class Foo {}');
  924. file_put_contents($workingDir.'/test.php', '<?php class Foo {}');
  925. file_put_contents($vendorDir.'/b/b/lib/Bar/Foo.php', '<?php namespace Bar; class Foo {}');
  926. file_put_contents($vendorDir.'/b/b/classmaps/classes.php', '<?php namespace Bar; class Bar {}');
  927. file_put_contents($vendorDir.'/b/b/bootstrap.php', '<?php class Bar {}');
  928. $oldVendorDir = $this->vendorDir;
  929. $this->vendorDir = $vendorDir;
  930. $this->generator->dump($this->config, $this->repository, $package, $im, 'composer', true, '_13');
  931. $this->vendorDir = $oldVendorDir;
  932. $expectedNamespace = <<<'EOF'
  933. <?php
  934. // autoload_namespaces.php @generated by Composer
  935. $vendorDir = dirname(dirname(__FILE__));
  936. $baseDir = dirname($vendorDir).'/working-dir';
  937. return array(
  938. 'Foo' => array($baseDir . '/src'),
  939. 'Bar' => array($vendorDir . '/b/b/lib'),
  940. );
  941. EOF;
  942. $expectedPsr4 = <<<'EOF'
  943. <?php
  944. // autoload_psr4.php @generated by Composer
  945. $vendorDir = dirname(dirname(__FILE__));
  946. $baseDir = dirname($vendorDir).'/working-dir';
  947. return array(
  948. 'Acme\\Foo\\' => array($baseDir . '/src-psr4'),
  949. 'Acme\\Bar\\' => array($vendorDir . '/b/b/lib-psr4'),
  950. );
  951. EOF;
  952. $expectedClassmap = <<<'EOF'
  953. <?php
  954. // autoload_classmap.php @generated by Composer
  955. $vendorDir = dirname(dirname(__FILE__));
  956. $baseDir = dirname($vendorDir).'/working-dir';
  957. return array(
  958. 'Bar\\Bar' => $vendorDir . '/b/b/classmaps/classes.php',
  959. 'Bar\\Foo' => $vendorDir . '/b/b/lib/Bar/Foo.php',
  960. 'Foo\\Bar' => $baseDir . '/src/Foo/Bar.php',
  961. 'Foo\\Foo' => $baseDir . '/classmap/classes.php',
  962. );
  963. EOF;
  964. $this->assertStringEqualsFile($vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace);
  965. $this->assertStringEqualsFile($vendorDir.'/composer/autoload_psr4.php', $expectedPsr4);
  966. $this->assertStringEqualsFile($vendorDir.'/composer/autoload_classmap.php', $expectedClassmap);
  967. $this->assertContains("\$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
  968. $this->assertContains("\$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
  969. }
  970. public function testUpLevelRelativePaths()
  971. {
  972. $workingDir = $this->workingDir.'/working-dir';
  973. mkdir($workingDir, 0777, true);
  974. chdir($workingDir);
  975. $package = new Package('a', '1.0', '1.0');
  976. $package->setAutoload(array(
  977. 'psr-0' => array('Foo' => '../path/../src'),
  978. 'psr-4' => array('Acme\Foo\\' => '../path/../src-psr4'),
  979. 'classmap' => array('../classmap'),
  980. 'files' => array('../test.php'),
  981. 'exclude-from-classmap' => array('./../classmap/excluded'),
  982. ));
  983. $this->repository->expects($this->once())
  984. ->method('getCanonicalPackages')
  985. ->will($this->returnValue(array()));
  986. $this->fs->ensureDirectoryExists($this->workingDir.'/src/Foo');
  987. $this->fs->ensureDirectoryExists($this->workingDir.'/classmap/excluded');
  988. file_put_contents($this->workingDir.'/src/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
  989. file_put_contents($this->workingDir.'/classmap/classes.php', '<?php namespace Foo; class Foo {}');
  990. file_put_contents($this->workingDir.'/classmap/excluded/classes.php', '<?php namespace Foo; class Boo {}');
  991. file_put_contents($this->workingDir.'/test.php', '<?php class Foo {}');
  992. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_14');
  993. $expectedNamespace = <<<'EOF'
  994. <?php
  995. // autoload_namespaces.php @generated by Composer
  996. $vendorDir = dirname(dirname(__FILE__));
  997. $baseDir = dirname($vendorDir).'/working-dir';
  998. return array(
  999. 'Foo' => array($baseDir . '/../src'),
  1000. );
  1001. EOF;
  1002. $expectedPsr4 = <<<'EOF'
  1003. <?php
  1004. // autoload_psr4.php @generated by Composer
  1005. $vendorDir = dirname(dirname(__FILE__));
  1006. $baseDir = dirname($vendorDir).'/working-dir';
  1007. return array(
  1008. 'Acme\\Foo\\' => array($baseDir . '/../src-psr4'),
  1009. );
  1010. EOF;
  1011. $expectedClassmap = <<<'EOF'
  1012. <?php
  1013. // autoload_classmap.php @generated by Composer
  1014. $vendorDir = dirname(dirname(__FILE__));
  1015. $baseDir = dirname($vendorDir).'/working-dir';
  1016. return array(
  1017. 'Foo\\Bar' => $baseDir . '/../src/Foo/Bar.php',
  1018. 'Foo\\Foo' => $baseDir . '/../classmap/classes.php',
  1019. );
  1020. EOF;
  1021. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace);
  1022. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_psr4.php', $expectedPsr4);
  1023. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_classmap.php', $expectedClassmap);
  1024. $this->assertContains("\$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php'));
  1025. }
  1026. public function testEmptyPaths()
  1027. {
  1028. $package = new Package('a', '1.0', '1.0');
  1029. $package->setAutoload(array(
  1030. 'psr-0' => array('Foo' => ''),
  1031. 'psr-4' => array('Acme\Foo\\' => ''),
  1032. 'classmap' => array(''),
  1033. ));
  1034. $this->repository->expects($this->once())
  1035. ->method('getCanonicalPackages')
  1036. ->will($this->returnValue(array()));
  1037. $this->fs->ensureDirectoryExists($this->workingDir.'/Foo');
  1038. file_put_contents($this->workingDir.'/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
  1039. file_put_contents($this->workingDir.'/class.php', '<?php namespace Classmap; class Foo {}');
  1040. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_15');
  1041. $expectedNamespace = <<<'EOF'
  1042. <?php
  1043. // autoload_namespaces.php @generated by Composer
  1044. $vendorDir = dirname(dirname(__FILE__));
  1045. $baseDir = dirname($vendorDir);
  1046. return array(
  1047. 'Foo' => array($baseDir . '/'),
  1048. );
  1049. EOF;
  1050. $expectedPsr4 = <<<'EOF'
  1051. <?php
  1052. // autoload_psr4.php @generated by Composer
  1053. $vendorDir = dirname(dirname(__FILE__));
  1054. $baseDir = dirname($vendorDir);
  1055. return array(
  1056. 'Acme\\Foo\\' => array($baseDir . '/'),
  1057. );
  1058. EOF;
  1059. $expectedClassmap = <<<'EOF'
  1060. <?php
  1061. // autoload_classmap.php @generated by Composer
  1062. $vendorDir = dirname(dirname(__FILE__));
  1063. $baseDir = dirname($vendorDir);
  1064. return array(
  1065. 'Classmap\\Foo' => $baseDir . '/class.php',
  1066. 'Foo\\Bar' => $baseDir . '/Foo/Bar.php',
  1067. );
  1068. EOF;
  1069. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace);
  1070. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_psr4.php', $expectedPsr4);
  1071. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_classmap.php', $expectedClassmap);
  1072. }
  1073. public function testVendorSubstringPath()
  1074. {
  1075. $package = new Package('a', '1.0', '1.0');
  1076. $package->setAutoload(array(
  1077. 'psr-0' => array('Foo' => 'composer-test-autoload-src/src'),
  1078. 'psr-4' => array('Acme\Foo\\' => 'composer-test-autoload-src/src-psr4'),
  1079. ));
  1080. $this->repository->expects($this->once())
  1081. ->method('getCanonicalPackages')
  1082. ->will($this->returnValue(array()));
  1083. $this->fs->ensureDirectoryExists($this->vendorDir.'/a');
  1084. $expectedNamespace = <<<'EOF'
  1085. <?php
  1086. // autoload_namespaces.php @generated by Composer
  1087. $vendorDir = dirname(dirname(__FILE__));
  1088. $baseDir = dirname($vendorDir);
  1089. return array(
  1090. 'Foo' => array($baseDir . '/composer-test-autoload-src/src'),
  1091. );
  1092. EOF;
  1093. $expectedPsr4 = <<<'EOF'
  1094. <?php
  1095. // autoload_psr4.php @generated by Composer
  1096. $vendorDir = dirname(dirname(__FILE__));
  1097. $baseDir = dirname($vendorDir);
  1098. return array(
  1099. 'Acme\\Foo\\' => array($baseDir . '/composer-test-autoload-src/src-psr4'),
  1100. );
  1101. EOF;
  1102. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'VendorSubstring');
  1103. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace);
  1104. $this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_psr4.php', $expectedPsr4);
  1105. }
  1106. public function testExcludeFromClassmap()
  1107. {
  1108. $package = new Package('a', '1.0', '1.0');
  1109. $package->setAutoload(array(
  1110. 'psr-0' => array(
  1111. 'Main' => 'src/',
  1112. 'Lala' => array('src/', 'lib/'),
  1113. ),
  1114. 'psr-4' => array(
  1115. 'Acme\Fruit\\' => 'src-fruit/',
  1116. 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
  1117. ),
  1118. 'classmap' => array('composersrc/'),
  1119. 'exclude-from-classmap' => array(
  1120. '/composersrc/foo/bar/',
  1121. '/composersrc/excludedTests/',
  1122. '/composersrc/ClassToExclude.php',
  1123. '/composersrc/*/excluded/excsubpath',
  1124. '**/excsubpath',
  1125. ),
  1126. ));
  1127. $this->repository->expects($this->once())
  1128. ->method('getCanonicalPackages')
  1129. ->will($this->returnValue(array()));
  1130. $this->fs->ensureDirectoryExists($this->workingDir.'/composer');
  1131. $this->fs->ensureDirectoryExists($this->workingDir.'/src/Lala/Test');
  1132. $this->fs->ensureDirectoryExists($this->workingDir.'/lib');
  1133. file_put_contents($this->workingDir.'/src/Lala/ClassMapMain.php', '<?php namespace Lala; class ClassMapMain {}');
  1134. file_put_contents($this->workingDir.'/src/Lala/Test/ClassMapMainTest.php', '<?php namespace Lala\Test; class ClassMapMainTest {}');
  1135. $this->fs->ensureDirectoryExists($this->workingDir.'/src-fruit');
  1136. $this->fs->ensureDirectoryExists($this->workingDir.'/src-cake');
  1137. $this->fs->ensureDirectoryExists($this->workingDir.'/lib-cake');
  1138. file_put_contents($this->workingDir.'/src-cake/ClassMapBar.php', '<?php namespace Acme\Cake; class ClassMapBar {}');
  1139. $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc');
  1140. $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc/tests');
  1141. file_put_contents($this->workingDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
  1142. // this classes should not be found in the classmap
  1143. $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc/excludedTests');
  1144. file_put_contents($this->workingDir.'/composersrc/excludedTests/bar.php', '<?php class ClassExcludeMapFoo {}');
  1145. file_put_contents($this->workingDir.'/composersrc/ClassToExclude.php', '<?php class ClassClassToExclude {}');
  1146. $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc/long/excluded/excsubpath');
  1147. file_put_contents($this->workingDir.'/composersrc/long/excluded/excsubpath/foo.php', '<?php class ClassExcludeMapFoo2 {}');
  1148. file_put_contents($this->workingDir.'/composersrc/long/excluded/excsubpath/bar.php', '<?php class ClassExcludeMapBar {}');
  1149. // symlink directory in project directory in classmap
  1150. $this->fs->ensureDirectoryExists($this->workingDir.'/forks/bar/src/exclude');
  1151. $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc/foo');
  1152. file_put_contents($this->workingDir.'/forks/bar/src/exclude/FooExclClass.php', '<?php class FooExclClass {};');
  1153. $target = $this->workingDir.'/forks/bar/';
  1154. $link = $this->workingDir.'/composersrc/foo/bar';
  1155. $command = Platform::isWindows()
  1156. ? 'mklink /j "' . str_replace('/', '\\', $link) . '" "' . str_replace('/', '\\', $target) . '"'
  1157. : 'ln -s "' . $target . '" "' . $link . '"';
  1158. exec($command);
  1159. $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
  1160. // Assert that autoload_classmap.php was correctly generated.
  1161. $this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
  1162. }
  1163. private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
  1164. {
  1165. $a = __DIR__.'/Fixtures/autoload_'.$name.'.php';
  1166. $b = $dir.'/autoload_'.$type.'.php';
  1167. $this->assertFileEquals($a, $b);
  1168. }
  1169. public static function assertFileEquals($expected, $actual, $message = '', $canonicalize = false, $ignoreCase = false)
  1170. {
  1171. return self::assertEquals(
  1172. file_get_contents($expected),
  1173. file_get_contents($actual),
  1174. $message ?: $expected.' equals '.$actual,
  1175. 0,
  1176. 10,
  1177. $canonicalize,
  1178. $ignoreCase
  1179. );
  1180. }
  1181. public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
  1182. {
  1183. return parent::assertEquals(str_replace("\r", '', $expected), str_replace("\r", '', $actual), $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
  1184. }
  1185. }